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