當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
ArcGIS JS先添加动态图层,再添加切片图层后不显示
生活随笔
收集整理的這篇文章主要介紹了
ArcGIS JS先添加动态图层,再添加切片图层后不显示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景:
? ? ? ? ?現在要在一個地圖上添加動態服務圖層和切片服務圖層,當創建好圖層之后,使用map.addLayer()方法,先把動態圖層加到地圖上,再把切片圖層加到地圖上,出現一個現象:只能看到加載的動態圖層,切片圖層沒了。
現象:
先加載動態圖層,再加載切片圖層
所對應代碼:
<script>var map;require(["esri/map","esri/layers/ArcGISDynamicMapServiceLayer","esri/layers/ArcGISTiledMapServiceLayer"], function (Map, ArcGISDynamicMapServiceLayer,ArcGISTiledMapServiceLayer) {map = new Map("mapDiv");//動態地圖服務圖層var dynamic = new ArcGISDynamicMapServiceLayer("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer");//切片地圖服務圖層var tiled = new ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");//先添加動態地圖服務//If the first layer added to the map is an ArcGISDynamicMapServiceLayer,// the map will take on the projection of this layer.map.addLayer(dynamic);//再添加切片地圖服務map.addLayer(tiled);}); </script>解決方法:
試了試,先添加切片圖層,再添加動態圖層,就沒有什么問題了,兩個圖層都可以疊加到地圖上面。主要代碼如下:
<script>var map;require(["esri/map","esri/layers/ArcGISDynamicMapServiceLayer","esri/layers/ArcGISTiledMapServiceLayer"], function (Map, ArcGISDynamicMapServiceLayer,ArcGISTiledMapServiceLayer) {map = new Map("mapDiv");//動態地圖服務圖層var dynamic = new ArcGISDynamicMapServiceLayer("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer");//切片地圖服務圖層var tiled = new ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");// //先添加動態地圖服務// //If the first layer added to the map is an ArcGISDynamicMapServiceLayer,// // the map will take on the projection of this layer.// map.addLayer(dynamic);// //再添加切片地圖服務// map.addLayer(tiled);//改變順序,先添加切片圖層,再添加動態圖層map.addLayer(tiled);console.log(map.spatialReference);map.addLayer(dynamic);}); </script>改變添加順序后的效果:
?
? ? ? ? 現在可以看到兩個圖層已經疊起來了。到底是什么原因呢?
原因分析:
? ? ? ??偶然找到一個官方的文檔(https://pan.baidu.com/s/1o8UhCxG),里面有這么一段:
? ? ? ? 緩存圖層指的就是切片圖層,如果先添加動態圖層,再添加切片圖層,由于切片圖層不會動態轉換空間參考,導致地圖上只有動態圖層;反之,如果先加載切片圖層,再加載動態圖層,由于動態圖層可以自動轉換空間參考,因此可以看到兩個圖層疊在了一起。
總結
以上是生活随笔為你收集整理的ArcGIS JS先添加动态图层,再添加切片图层后不显示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Angular项目中,基于esriLoa
- 下一篇: Java实现栅格数据格式文件读取及加法操