| | |
| | | * 创建图层相关的类 |
| | | */ |
| | | import AjaxUtils from '@/utils/AjaxUtils' |
| | | import store from '@/store' |
| | | |
| | | class ServiceLayerHelper { |
| | | constructor (options) { |
| | |
| | | this.tileLayersWMTSArray = [] // 初始的WMTS集 |
| | | this.tileLayersTileArray = [] // 初始的Tile集 |
| | | this.tileLayersWMSArray = [] // 初始的WMS集 |
| | | this.geojsonArray = [] // 初始的geojson集 |
| | | this.geojsonArray = {} // 初始的geojson集 |
| | | this.layerConfig = {} |
| | | this.regex = /\{(.+?)\}/g // 匹配{} |
| | | } |
| | |
| | | */ |
| | | initServiceLayers (layerConfig) { |
| | | this.layerConfig = layerConfig |
| | | this._loadLayers(layerConfig.mapConfig.Layers.LayerSewersLine) |
| | | this.loadLayers(layerConfig.mapConfig.Layers.LayerSewersLine) |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param {*} mapConfig |
| | | * @param {*} isAddToMap |
| | | */ |
| | | _loadLayers (layerConfig, isAddToMap = true) { |
| | | loadLayers (layerConfig, isAddToMap = true) { |
| | | console.debug('ServiceLayerHelper加载参数:', layerConfig) |
| | | for (let i = 0, len = layerConfig.length; i < len; ++i) { |
| | | const opt = layerConfig[i] |
| | |
| | | this.loadTileLayer(opt, isAddToMap) |
| | | this.tileLayersTileArray.push(opt) |
| | | } else if (opt.type === 'geojson') { |
| | | this.loadGeojson(opt) |
| | | this.loadGeojsonLayers(opt) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | loadGeojson (options) { |
| | | loadGeojsonLayers (options) { |
| | | var url = options.url |
| | | var layers = options.layers |
| | | var matches = this.regex.exec(url) |
| | | for (var i = 0; i < layers.length; i++) { |
| | | var layer = layers[i] |
| | | var matchValue = layer[matches[1]] |
| | | var checked = layer.checked |
| | | if (!checked) { |
| | | continue |
| | | if (checked) { |
| | | this.loadGeojsonLayer(url, layer) |
| | | } |
| | | var newUrl = url.replace(this.regex, matchValue) |
| | | var that = this |
| | | } |
| | | } |
| | | |
| | | loadGeojsonLayer (url, layer) { |
| | | var matches = this.regex.exec(url) |
| | | var matchValue = layer[matches[1]] |
| | | var code = layer.code |
| | | var newUrl = url.replace(this.regex, matchValue) |
| | | var that = this |
| | | if (!that.geojsonArray[code]) { |
| | | AjaxUtils.GetDataAsynByUrl(newUrl, {}, function (res) { |
| | | // let geojsondata = L.geoJSON(test.features,{ |
| | | that.L.geoJSON(res.features, { |
| | | style: function (feature) { |
| | | return { |
| | | fill: true, |
| | | weight: 2, |
| | | fillColor: '#06cccc', |
| | | color: '#06cccc', |
| | | fillOpacity: 0.2, |
| | | opacity: 0.8, |
| | | dashArray: '10,4', |
| | | dashSpeed: -10 |
| | | } |
| | | }, |
| | | minZoom: 10 |
| | | }).bindPopup(function (layer) { |
| | | // return layer.feature.properties.linenumber |
| | | }).addTo(that.map) |
| | | store.commit('setSewersDatas', res) |
| | | var layer = that.loadGeojson(res) |
| | | that.geojsonArray[code] = layer |
| | | }) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 加载点数据 |
| | | * @param res |
| | | */ |
| | | loadGeojson (res) { |
| | | var that = this |
| | | const featureGroup = that.L.featureGroup([], { |
| | | attribution: { id: '123' } |
| | | }).addTo(that.map) |
| | | that.L.geoJSON(res.features, { |
| | | style: function (feature) { |
| | | return { |
| | | fill: true, |
| | | weight: 2, |
| | | fillColor: '#06cccc', |
| | | color: '#06cccc', |
| | | fillOpacity: 0.2, |
| | | opacity: 0.8, |
| | | dashArray: '10,4', |
| | | dashSpeed: -10 |
| | | } |
| | | }, |
| | | pointToLayer: function (geoJsonPoint, latlng) { |
| | | return that.L.canvasMarker(latlng, |
| | | { |
| | | radius: 20, |
| | | img: { |
| | | url: 'assets/images/map/marker-icon.png', |
| | | size: [20, 20] |
| | | } |
| | | }) |
| | | } |
| | | }).bindPopup(function (layer) { |
| | | // return layer.feature.properties.linenumber |
| | | }).addTo(featureGroup) |
| | | featureGroup.bringToBack() |
| | | return featureGroup |
| | | } |
| | | |
| | | removeLayer (item) { |
| | | var code = item.code |
| | | var layer = this.geojsonArray[code] |
| | | if (layer) { |
| | | this.map.removeLayer(layer) |
| | | delete this.geojsonArray[code] |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 往地图中加入一个WMTS服务 |
| | | * @param {}} options |
| | | * @param {*} isAddToMap |