| | |
| | | /* eslint-disable no-debugger */ |
| | | import AjaxUtils from '@/utils/AjaxUtils' |
| | | |
| | | import * as utils from '../../utils/utils' |
| | | /** |
| | | * 底图管理助手,负责底图创建及开关 |
| | | */ |
| | | class BasemapHelper { |
| | | constructor (options) { |
| | | this.map = options.map |
| | | this.L = options.L |
| | | this.L = window.L |
| | | this.basemapList = [] |
| | | this.basemapMap = new Map() |
| | | this.basemapLayerGroup = options.L.layerGroup().addTo(options.map) |
| | | this.basemapLayerGroup = this.L.layerGroup().addTo(options.map) |
| | | this.currentBaseMapCode = null |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param map |
| | | * @param defBasemapName 初始化完成后,默认显示的图层 |
| | | */ |
| | | initBasemap = (mapConfig, isIntranet) => { |
| | | initBasemap =async (config, isIntranet) => { |
| | | if (isIntranet) { // 内网 |
| | | this._getToken(mapConfig) // 获取token后,并按配置加载地图 |
| | | this._getToken(config) // 获取token后,并按配置加载地图 |
| | | } else { // 外网 |
| | | this._createBasemapByConfig(mapConfig) |
| | | this._createBasemapByConfig(config) |
| | | } |
| | | |
| | | return this.basemapMap |
| | |
| | | this.basemapLayerGroup.addLayer(basemap.layer) |
| | | if (showAnnotation) { |
| | | this.basemapLayerGroup.addLayer(basemap.annotation) |
| | | } else { |
| | | this.basemapLayerGroup.removeLayer(basemap.annotation) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // 公网创建地图部分 |
| | | _createBasemapByConfig (mapConfig) { |
| | | const internetBasemaps = mapConfig.mapConfig.InternetBaseMaps |
| | | _createBasemapByConfig (config) { |
| | | const internetBasemaps = config.mapConfig.InternetBaseMaps |
| | | for (let i = 0, len = internetBasemaps.length; i < len; ++i) { |
| | | const basemapConfig = internetBasemaps[i] |
| | | const basemapLayer = this.L.tileLayer(basemapConfig.map.url, basemapConfig.map.option) |
| | | const basemapAnnotationLayer = this.L.tileLayer(basemapConfig.annotation.url, basemapConfig.annotation.option) |
| | | const mapToken = utils.getRandomTDTToken() |
| | | const mapUrl = utils.changeURLArg(basemapConfig.map.url, 'tk', mapToken) |
| | | const basemapLayer = this.L.tileLayer(mapUrl, basemapConfig.map.option) |
| | | const basemapAnnotationLayer = this.L.tileLayer(mapUrl, basemapConfig.annotation.option) |
| | | |
| | | const basemap = { |
| | | code: basemapConfig.code, |
| | |
| | | |
| | | // 内网地图创建部分 |
| | | // 获取内网地图token,并加载到地图中 |
| | | _getToken = (mapConfig) => { |
| | | const params = mapConfig.TokenConfig |
| | | AjaxUtils.GetDataAsynByUrl(params.url, params.option, (token) => { |
| | | this._showTDT(token, mapConfig) |
| | | }) |
| | | _getToken = async (config) => { |
| | | const params = config.TokenConfig |
| | | const token = await AjaxUtils.GetDataAsynByUrl(params.url, params.option) |
| | | this._showTDT(token, config) |
| | | } |
| | | |
| | | // 内网地图加载,并加载到地图 |
| | | _showTDT = (token, mapConfig) => { |
| | | const intranetBasemaps = mapConfig.mapConfig.IntranetBaseMaps |
| | | _showTDT = (token, config) => { |
| | | const intranetBasemaps = config.mapConfig.IntranetBaseMaps |
| | | for (let i = 0, len = intranetBasemaps.length; i < len; ++i) { |
| | | const basemapConfig = intranetBasemaps[i] |
| | | const basemapLayer = this.L.tileLayer(basemapConfig.map.url, basemapConfig.map.option) |
| | | const basemapAnnotationLayer = this.L.tileLayer(basemapConfig.annotation.url, basemapConfig.annotation.option) |
| | | const basemapLayer = this.L.tileLayer(basemapConfig.map.url + '&token=' + token, basemapConfig.map.option) |
| | | const basemapAnnotationLayer = this.L.tileLayer(basemapConfig.annotation.url + '&token=' + token, basemapConfig.annotation.option) |
| | | |
| | | const basemap = { |
| | | code: basemapConfig.code, |