多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 一、点位置变动 ![](https://box.kancloud.cn/7a764f6b394395d028df12859fef90e7_284x224.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/layers/GraphicsLayer', 'dojo/domReady!' ], function(Map, MapView, Graphic, GraphicsLayer) { var map = new Map({ basemap: 'streets' // dark-gray }); var mapView = new MapView({ map: map, container: 'js_map', center: [102.9331224074, 25.1049040686], zoom: 6, // rotation: -127.7 }); // graphicLayer var graphicLayer = new GraphicsLayer(); map.layers.add(graphicLayer); // 点 var pointGraphic = new Graphic({ geometry: { type: "point", longitude: 102.91835013921454, latitude: 25.07329419928656 }, symbol: { type: "simple-marker", color: [226, 119, 40], outline: { color: [255, 255, 255], width: 2 } } }); graphicLayer.add(pointGraphic); mapView.when(function() { var startTime = Date.now(), coord; var timer = setInterval(function() { // 定时器 if(Date.now()-startTime < 10000) { coord = generateRandomCoord('s'); pointGraphic.geometry = { type: "point", longitude: coord[0], latitude: coord[1] } } else { clearInterval(timer); } }, 1000); }); }); ~~~ ## 二、弹层位置跟着变动 ![](https://box.kancloud.cn/a5c05a9cc0d1011dbcda0166881bb579_540x348.gif) ~~~ var pointGraphic = new Graphic({ geometry: { type: "point", longitude: 102.91835013921454, latitude: 25.07329419928656 }, symbol: { type: "simple-marker", color: [226, 119, 40], outline: { color: [255, 255, 255], width: 2 } }, popupTemplate: { title: "自定义弹层标题", content: '<div style="padding: 20px;border: 1px solid #333;font-size: 14px;color: #f00;">Hello ArcGis地图.</div>' } }); graphicLayer.add(pointGraphic); mapView.when(function() { var startTime = Date.now(), coord; var timer = setInterval(function() { // 定时器 if(Date.now()-startTime < 100000) { coord = generateRandomCoord('s'); pointGraphic.geometry = { type: "point", longitude: coord[0], latitude: coord[1] } if(mapView.popup.visible) { // 如果弹层显示,则更新位置 mapView.popup.open({ title: "自定义弹层标题", content: '<div style="padding: 20px;border: 1px solid #333;font-size: 14px;color: #f00;">Hello ArcGis地图.</div>', location: coord }); } } else { clearInterval(timer); } }, 2000); }); ~~~