企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
更新弹层标记的popup内容 ![](https://box.kancloud.cn/822160090d36119cb49f1c6e719d47cb_456x276.gif) ``` // 随机生成坐标 function generateRandomCoord(type) { switch (type) { case 'w': // 世界 return [Math.random() * 180 - Math.random() * 180, Math.random() * 90 - Math.random() * 90]; break; case 's': // 特定范围 return [103 + Math.random() * (108 - 103), 22 + Math.random() * (25 - 22)]; default: // 中国 return [74 + Math.random() * (135 - 74), 1 + Math.random() * (53 - 1)]; break; } } require([ 'esri/Map', 'esri/views/MapView', 'esri/Graphic', 'esri/geometry/Point' ], function(Map, MapView, Graphic, Point) { var map = new Map({ basemap: 'streets' }); var mapView = new MapView({ map: map, center: [102.9331224074, 25.1049040686], zoom: 6, container: 'js_map' }); // 点 var pointGraphicArr = []; for (var i = 0; i < 3; i++) { var coord = generateRandomCoord('s'); var pointGraphic = new Graphic({ attributes: { id: 'point_'+i // 主要就是匹配标记id }, geometry: { type: "point", longitude: coord[0], latitude: coord[1] }, symbol: { type: "simple-marker", color: [226, 119, 40], outline: { color: [255, 255, 255], width: 2 } }, popupTemplate: { overwriteActions: true, // 覆盖action,关闭弹层缩放 title: "自定义弹层标题"+i, content: '<div style="padding: 20px;border: 1px solid #333;font-size: 14px;color: #f00;">Hello ArcGis地图.</div>' } }); pointGraphicArr.push(pointGraphic); } mapView.graphics.addMany(pointGraphicArr); setTimeout(function() { if(mapView.popup.visible) { var pointMarker = mapView.popup.features[0], // 弹层标记 pointId = pointMarker.attributes.id, coord = [pointMarker.geometry.longitude, pointMarker.geometry.latitude]; mapView.graphics.items.forEach(function(v) { var id = v.attributes.id; if(id === pointId) { mapView.popup.open({ overwriteActions: true, title: "自定义弹层标题", content: '<div style="padding: 20px;border: 1px solid #333;font-size: 14px;color: #177D0B;">Hello ArcGis地图.</div>', location: coord }); } }); } }, 5000); }); ```