1. 程式人生 > >arcgis js 實現地圖聯動對比功能

arcgis js 實現地圖聯動對比功能

var MapCompareCom = function(firstIndex,secondIndex){
var firstlayersinfo = [["basemap","標準向量","[email protected]","ArcGISTiledMapServiceLayer","http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer"],
["warmmap","暖色向量","[email protected]","ArcGISTiledMapServiceLayer","http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer"],
["coldmap","冷色向量","
[email protected]
","ArcGISTiledMapServiceLayer","http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineStreetCold/MapServer"],
["imagemap","影像地圖","[email protected]","ArcGISTiledMapServiceLayer","http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"],
["automap","高德向量","[email protected]
","MapABCTiledLayer","http://webrd0${subDomain}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x=${col}&y=${row}&z=${level}"],
["bdvectormap","百度向量","[email protected]","BaiduTiledLayer",""]];

var secondlayersinfo = [["basemap2","標準向量2","[email protected]","ArcGISTiledMapServiceLayer","http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer"],
["warmmap2","暖色向量2","
[email protected]
","ArcGISTiledMapServiceLayer","http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer"],
["coldmap2","冷色向量2","[email protected]","ArcGISTiledMapServiceLayer","http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineStreetCold/MapServer"],
["imagemap2","影像地圖2","[email protected]","ArcGISTiledMapServiceLayer","http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"],
["automap2","高德向量2","[email protected]","MapABCTiledLayer","http://webrd0${subDomain}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x=${col}&y=${row}&z=${level}"],
["bdvectormap2","百度向量2","[email protected]","BaiduTiledLayer",""]];

var mlt = $('#map-list',$("#compare-panel"));

var map0,map1;
var initMapInstance = function(type){
var maptmp; 
require(["esri/map"],function(Map, bundle) {
if(type==0){ 
maptmp = new Map("mapc0", {
     slider: true, 
     sliderPosition: "top-right",
     logo:false,
     center: [114.263,30.55],//[116.383,39.95]
     zoom: 14
   }); 
   map0 = maptmp;
}else{
maptmp = new Map("mapc1", {
     slider: true, 
     sliderPosition: "top-right",
     logo:false,
     center: [114.263,30.55],//[116.383,39.95]
     zoom: 14
   }); 
   map1 = maptmp;
}
});
return maptmp;
}

var mapaction0,mapaction1;
var initMapAction = function(){
$("#mapc0").mouseover(function(n){
if(map0==undefined||map1==undefined){
return;
}
if(mapaction0!=undefined){
mapaction0.remove();
}
mapaction0 = map0.on("extent-change",function(){  
                map1.setExtent(map0.extent);  
            }); 
});
$("#mapc0").mouseout(function(n){
if(mapaction0!=undefined){
mapaction0.remove();

});

$("#mapc1").mouseover(function(n){
if(map0==undefined||map1==undefined){
return;
}
if(mapaction1!=undefined){
mapaction1.remove();

mapaction1 = map1.on("extent-change",function(){  
                map0.setExtent(map1.extent);  
            }); 
});
$("#mapc1").mouseout(function(n){
if(mapaction1!=undefined){
mapaction1.remove();
}  
}); 
}

var closePanelListener = function(){ 
var panel = $('#compare-panel');
panel.find(".panel-header").find('i').on("click",
function(n){  
//$("#map").show();
$("#mapc0").css("left",(68)+"px");
$("#mapc0").css("width","calc(50% - 34px)");
$("#mapc1").css("width","calc(50% - 34px)");
});

}

var initLayerMenu = function(layerinfo,type){ 
var maptmp = initMapInstance(type);
for(var i=0;i<layerinfo.length;i++){
var item = '<li class="map-item"><div id="'+layerinfo[i][0]+'" class="thumb" style="background-image:url(mapicon/'+layerinfo[i][2]+')">'; 
item += '<i class="fa fa-check-circle"></i></div>';
item +='<p>'+layerinfo[i][1]+'</p></li>';  
mlt.append(item); 
$('#'+layerinfo[i][0],mlt).off("click");
$('#'+layerinfo[i][0],mlt).on("click",{
layerinfo:layerinfo,
layerType:layerinfo[i][3],
layerUrl:layerinfo[i][4],
layerID:layerinfo[i][0],
map:maptmp},
function(n){
n.preventDefault(); 
var t =$(this); 
if(!t.hasClass("active")){
clearBaseSelected(n.data.layerinfo,n.data.map);
t.addClass("active");
changeLayer(n.data.layerType,n.data.layerUrl,n.data.layerID,n.data.map);

});
}
}

var clearBaseSelected = function(layerInfo,mapInstance){ 
for(var i=0;i<layerInfo.length;i++){
var t = $('#'+layerInfo[i][0],mlt);
if(t.hasClass("active")){ 
t.removeClass("active");
break;
}
}
mapInstance.removeAllLayers();
}

var changeLayer = function(layerType,layerUrl,layerID,mapInstance){
mapInstance.removeAllLayers();
var ly = initLayer(layerType,layerUrl,layerID);
mapInstance.addLayer(ly);
}

var initLayer= function(layerType,layerUrl,layerID){
var mylayer = null;
switch(layerType){
case "ArcGISTiledMapServiceLayer":
mylayer = new esri.layers.ArcGISTiledMapServiceLayer(layerUrl,{}); 
break;
case "BaiduTiledLayer"://var imgMap = new bdimgLayer(),anoMap = new bdanoLayer(),vectMap = new bdvectorLayer();
mylayer = new bdvectorLayer(); 
break;
case "MapABCTiledLayer":
mylayer = new esri.layers.WebTiledLayer(layerUrl, {           
     "subDomains": ["1", "2", "3","4"]
   }); 
break;
case "MapABCTrafficTiledLayer":
mylayer = new autotrafficLayer();
break;
case "ArcGISDynamicMapServiceLayer":
var imageParameters = new esri.layers.ImageParameters();
   imageParameters.format = "png";
  mylayer = new esri.layers.ArcGISDynamicMapServiceLayer(layerUrl,{
  "opacity" : 0.5,
     "imageParameters":imageParameters
  });
break;
case "CustomClusterLayer":
mylayer= new setClusterData();
break; 
case "GeoEventClusterLayer":
mylayer = new setGeoEventClusterData();
break;
}
   
  if(mylayer!=null){
  mylayer.id=layerID; 
  } 
  return mylayer;
}  

var initUI = function(){
mlt.append('<div class="panel-header2">左邊圖層</div>');
initLayerMenu(firstlayersinfo,0);

mlt.append('<div class="panel-header3">右邊圖層</div>');
initLayerMenu(secondlayersinfo,1); 

mlt.parent().perfectScrollbar();

$('#'+firstlayersinfo[firstIndex][0],mlt).click();
$('#'+secondlayersinfo[secondIndex][0],mlt).click(); 
closePanelListener(); 
initMapAction();

this.setCompareMapShow = function(){
$("#mapc0").show();
$("#mapc0").css("left",(68+280)+"px");
$("#mapc1").show(); 
$("#map").hide();
}

initUI();

有問題聯絡qq:541247221

相關推薦

arcgis js 實現地圖聯動對比功能

var MapCompareCom = function(firstIndex,secondIndex){var firstlayersinfo = [["basemap","標準向量","[email protected]","ArcGISTiledMapSer

arcgis js 實現透鏡或放大鏡功能

function MagnifyMap(){ var _map_drag; var divID ="MagnifyMap";var mmap;var radius=80;var levelMax = 0;function searchLayerInfo(layerID){v

arcgis js 實現捲簾功能

function SwipeMap(){this.maptoplayer;this._map_drag;this.InitSwipe = function(){  var rt = true;require(["dojo/on"],function(on){var divI

js實現搖一搖功能

ice 彈出 update 運動 including scrip read log 頁面 function init(){   if (window.DeviceMotionEvent) {     // 移動瀏覽器支持運動傳感事件     window.addEvent

原生js實現三級聯動

三級聯動 chan 學習 initial ble ont view document chang 學習 自 於 http://blog.csdn.net/Elenal/article/details/51493510 <!DOCTYPE html> <ht

js 實現簡易留言板功能

con wid NPU children 標準 element 出錯 hdel focus <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xh

vue中使用raphael.js實現地圖繪制

proc -c ima order ont .text mov += svg 一、效果圖 二、在vue中引入raphael.js npm i raphael -S 三、封裝一個名為StreetMap的組件,代碼如下 1 <template> 2

原生js實現toggle classname的功能

function hasClass(obj, cls) { return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')); } function addClass(obj, cls) {

【javaweb】JS實現省市聯動

需求:比如在註冊頁面中,需要選擇籍貫,當我們選擇省的時候,市可以隨著省的選擇不同而變動。 字首知識:https://blog.csdn.net/qq_42370146/article/details/84326604 過程分析: 1. 確定事件:  onchange 2. 函式

C#+ AE實現地圖註記功能

基於Arcgis Engine的二次開發,需要地圖註記功能。簡單講註記是以文字的形式將要素圖層的屬性標註出來。 首先,窗體設計如下: 其次,實現的主要程式碼如下: public partial class FormMapAnnotation : Form

JS實現二級聯動 (createTextNode,createElement )

 JS中只有陣列,沒有集合 陣列長度=角標+1    長度可變 cities[0],cities[1],cities[2],cities[3] cities[100]   長度是101   而不是5 <!DO

js實現三級聯動-年月日

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html

實用小專案——Vue.js 實現增刪查改功能

最近學習了vue.js框架,嘗試著做了一個增刪查改功能的小專案。 今天發博來跟大家交流交流經驗。整體效果如下動態圖: 首先,我使用的是Bootstrap搭建整體框架: <!DOCTYPE html> <html> <head&g

利用jQuery.print.js實現canvas的列印功能

需求 把在瀏覽器中的利用canvas做的圖實現列印功能 思路 先把canvas轉換成img 把生成的img利用jQuery外掛jquery.print.js實現圖片列印功能 資料連

js實現點選複製功能

一、實現點選按鈕,複製文字框中的的內容<script type="text/javascript">function copyUrl2(){var Url2=document.getElementById("biao1");Url2.select(); // 選擇

JS實現new關鍵字的功能

一.前言 眾所周知:沒有物件怎麼辦?那就new一個! 那麼在JS中,當我們new一個物件的時候,這個new關鍵字內部都幹了什麼呢? 現在我們就來剖析一下原生JS中new關鍵字內部的工作原理。 二.原始的new 首先,我們先new一個物件看看: //建立Person建構函式,引數為name,age

JS 實現 Tab標籤切換功能

Tab標籤切換    效果圖:       HTML部分: <div class="wrap"> <ul id="tag"> <li class="current" >標籤一</li> <li>標

JS實現三級聯動

通過陣列簡單實現三級聯動。程式碼如下圖所示:  <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> &

vue.js實現簡單的購物車功能

咳咳,第一次寫部落格,有點小緊張,這次我將給大家帶來一個vue.js實現購物車的小專案,如有不足請嚴厲指出。 購物車功能有:全選和選擇部分商品,選中商品總價計算,商品移除,以及調整購買數量等功能。 js主要有以下方法 加函式,減函式,手動修改數量判斷庫存函式,總價格

JS】用js實現地圖窗體自適應不同的瀏覽器高度

//呼叫方法 autodivheight(); function autodivheight(){ //函式:獲取尺寸 //獲取瀏覽器視窗高度 var winH