下面是删除标绘图层的示例代码。
|
| 1. | < !--引入地图框架--> |
| 2. | < script src="http://服务器IP/地图API名称/" type="text/javascript" />< /script> |
创建地图容器元素
创建地图浏览应用程序需要在页面中创建一块区域用于显示地图内容,这个区域我们叫做地图容器,即在body中加入的一个div容器,其页面代码为:
| 1. | <div id="map_div" class="content"> </div> |
参数初始化设置
地图实例通过下列代码创建,其中,DCIMapConfig.mapInitParams是地图初始化参数。
| 1. | var map = new DCIMap("map_div", DCIMapConfig.mapInitParams); |
加载图层到地图
根据底图类型,创建底图,添加到地图中。
| 1. | switch (DCIMapConfig.vecMap.type) { |
| 2. | case 0://WMTS |
| 3. | var layers = new DCIWMTSLayer(DCIMapConfig.vecMap.Url); |
| 4. | map.addLayer(layers, 0); |
| 5. | map.showSlider(map.initExtent, DCIMapConfig.sliderConfig); |
| 6. | break; |
| 7. | case 1://1为mapserver切片 |
| 8. | var layers = new esri.layers.ArcGISTiledMapServiceLayer(DCIMapConfig.vecMap.Url); |
| 9. | map.addLayer(layers, 0); |
| 10. | dojo.connect(layers, "onLoad", function () { |
| 11. | map.showSlider(map.initExtent, DCIMapConfig.sliderConfig); |
| 12. | }) |
| 13. | break; |
| 14. | } |
| 15. | } |
添加标绘图层
新建标绘图层GraphicsLayer,添加到地图上
| 1. | var plotLayer = new esri.layers.GraphicsLayer(); |
| 2. | map.addLayer(plotLayer, 1); |
创建一个标绘
创建一个标绘,并将标绘加到地图中
| 1. | var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 255, 0.8])); |
| 2. | var geometry = new esri.geometry.Point([426699.98869475815, 2583118.604640635], new esri.SpatialReference({ wkid: 4547 })); |
| 3. | var graphic = new esri.Graphic(geometry, symbol); |
| 4. | plotLayer.add(graphic); |
删除标绘图层
删除标绘图层示例,通过以下定义removePlotLayer()事件实现
| 1. | function removePlotLayer() { |
| 2. | if (!!poltLayer) { |
| 3. | map.removeLayer(poltLayer); |
| 4. | alert("标绘图层已经移除!"); |
| 5. | } |
| 6. | } |
创建删除按钮
| 1. | < type="button" class="button" value="删除标绘图层" onclick="removePlotLayer()" /> |
