/**
*地图加载类,可根据地图类型加载WebTiledLayer、
*ArcGISTiledMapServiceLayer、
*ArcGISDynamicMapServiceLayer地图
* 同时加载、初始化一些基本的全局参数
* mapDivId html中的地图DIV的id
* mapConfig 地图的属性等信息
*/
define([
'dojo/_base/declare',
'esri/map',
'esri/SpatialReference',
'esri/geometry/Extent',
'esri/layers/ArcGISTiledMapServiceLayer',
'esri/layers/WebTiledLayer',
'esri/layers/ArcGISDynamicMapServiceLayer',
'esri/layers/TileInfo',
'dojo/NodeList-dom',
'dojo/NodeList-manipulate'
],function(declare,Map,SpatialReference,Extent,ArcGISTiledMapServiceLayer,WebTiledLayer,ArcGISDynamicMapServiceLayer,TileInfo) {
return declare('mapmanager',null,{
constructor: function(mapDivId,mapConfig){
this.mapDivId = mapDivId;
this.mapConfig = mapConfig;
this.init();
},
init:function(){
//var mapUrl = "http://localhost:6080/arcgis/rest/services/test1/Default/MapServer";
this.baselayers = this.mapConfig.baseLayers;
this.mapOption = this.mapConfig.mapOptions;
this.center = this.mapConfig.center;
this.initLevel = this.mapConfig.initLevel;
//添加是否显示放大缩小控件配置
this.map = new Map(this.mapDivId,this.mapConfig.mapOptions);
this.map.spatialReference = new SpatialReference(this.mapConfig.spatialReference);
this.map.initExtent = this.mapConfig.initExtent;
//this.map.lods = this.mapOptions.lods ? this.mapOptions.lods : null;
this.map.URL = this.mapConfig.URL;
this.map.mapConfig = this.mapConfig;
this.map.layertree=[];
this.map.mapExtent = new Extent(this.mapConfig.initExtent[0], this.mapConfig.initExtent[1],
this.mapConfig.initExtent[2], this.mapConfig.initExtent[3], this.map.spatialReference);
this._getHtmlIDs();
var that = this;
/*地图初始范围, 没有初始范围使用中心点和初始级别*/
this.map.on('load', function() {
if (that.mapConfig.initExtent && that.mapConfig.initExtent.length === 4) {
that.map.setExtent(that.map.mapExtent);
}
});
/*地图加载*/
for (var i = 0, baselayer; baselayer = this.baselayers[i++];){
var layer;
if(baselayer.type == 'ArcGISTiledMapServiceLayer'){
layer = new ArcGISTiledMapServiceLayer(baselayer.url, {
'displayLevels': baselayer.displayLevels
});
layer._displayLevels = baselayer.displayLevels;
}
else if(baselayer.type == 'ArcGISDynamicMapServiceLayer'){
layer = new ArcGISDynamicMapServiceLayer(baselayer.url);
}
layer.isBaseLayer = true;
layer.layerName = baselayer.layerName;
layer.layerGroup = baselayer.layerGroup ? baselayer.layerGroup : '';
if (baselayer.layerName) {
layer.id = baselayer.layerName;
}
if (baselayer.layerVisable === 'true') {
layer.show();
} else {
layer.hide();
}
this.map.addLayer(layer);
this.map.layertree.push(layer);
}
/*
if (this.showSlide) {
if (this.showSlide === 'false') {
this.map.hideZoomSlider();
}
}
*/
},
getMap:function(){
return this.map;
},
});
})
类似于生成模块