arcgis js 的地图加载类

本文介绍了一个地图加载类,能够根据地图类型加载不同种类的地图层,包括WebTiledLayer、ArcGISTiledMapServiceLayer和ArcGISDynamicMapServiceLayer。同时,文章详细说明了如何初始化地图的全局参数,如地图DIV的id、地图属性、中心点、初始级别等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**
 *地图加载类,可根据地图类型加载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;
    },
   
  });
})

类似于生成模块

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值