From 80078586462a5d66221d716adca79b6173c2bc08 Mon Sep 17 00:00:00 2001
From: chenzeping <ChenZeping02609@163.com>
Date: 星期二, 09 三月 2021 17:04:33 +0800
Subject: [PATCH] 修改已知问题
---
src/components/helpers/ServiceLayerHelper.js | 50 +++++++++++++++++++++++++++++++++++++-------------
1 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/src/components/helpers/ServiceLayerHelper.js b/src/components/helpers/ServiceLayerHelper.js
index 444421f..96da67f 100644
--- a/src/components/helpers/ServiceLayerHelper.js
+++ b/src/components/helpers/ServiceLayerHelper.js
@@ -16,13 +16,27 @@
this.tileLayersTileArray = [] // 鍒濆鐨凾ile闆�
this.tileLayersWMSArray = [] // 鍒濆鐨刉MS闆�
this.layerArray = {} // key涓洪厤缃殑code锛屽姞杞界殑鍥惧眰瀵硅薄锛�
- this.layerConfig = {}
this.regex = /\{(.+?)\}/g // 鍖归厤{}
this.popupComp = null
}
getTileLayer (code) {
return this.loadedLayersMap.get(code)
+ }
+
+ getByLayerId (layerId) {
+ for (var k in this.layerArray) {
+ var layer = this.layerArray[k]
+ var geojson = layer.toGeoJSON()
+ var features = geojson.features
+ for (var j = 0; j < features.length; j++) {
+ var feature = features[j]
+ if (feature.id === layerId) {
+ return layer
+ }
+ }
+ }
+ return null
}
initDisplayZoom (layerConfig) {
@@ -37,7 +51,7 @@
if (layer.minZoom) {
if (zoom > layer.minZoom) {
var layerObj = that.layerArray[layer.code]
- layerObj.addTo(that.map)
+ layerObj && layerObj.addTo(that.map)
} else {
that.removeLayer(layer)
}
@@ -102,18 +116,23 @@
* @param url
* @param item
*/
- loadGeojsonLayer (url, item) {
+ async loadGeojsonLayer (url, item) {
var matches = this.regex.exec(url)
var matchValue = item[matches[1]]
var code = item.code
var newUrl = url.replace(this.regex, matchValue)
var that = this
if (!that.layerArray[code]) {
- AjaxUtils.GetDataAsynByUrl(newUrl, {}, function (res) {
- store.commit('addSewersDatas', res)
- var layer = that.loadGeojson(res, item)
- that.layerArray[code] = layer
- })
+ const res = await AjaxUtils.GetDataAsynByUrl(newUrl, {})
+ if (res.data instanceof Object && Object.prototype.hasOwnProperty.call(res.data, 'features')) {
+ store.commit('addSewersDatas', res.data)
+ if (newUrl.indexOf('绠$綉') !== -1 || newUrl.indexOf('鍥涢��') !== -1) {
+ var layer = that.loadGeojson(res.data, item)
+ that.layerArray[code] = layer
+ }
+ }
+ } else {
+ that.layerArray[code].addTo(that.map)
}
}
@@ -124,7 +143,7 @@
loadGeojson (res, opt) {
var that = this
var icon = opt.icon
- const featureGroup = that.L.featureGroup().addTo(that.map)
+ const layergroup = that.L.featureGroup().addTo(that.map)
const geojson = that.L.geoJSON(res.features, {
style: function (feature) {
return {
@@ -161,10 +180,13 @@
.bindTooltip(function (layer) {
const nameId = layer.feature.id
let name = ''
- if (nameId.indexOf('涓夐��') !== -1 || nameId.indexOf('鍥涢��') !== -1) {
+ if (nameId.indexOf('涓夐��') !== -1 || nameId.indexOf('鍥涢��') !== -1 || nameId.indexOf('绐ㄤ簳') !== -1) {
name = layer.feature.properties.pointnumber
} else {
name = layer.feature.properties.name
+ }
+ if (name === undefined) {
+ name = ''
}
return name
}, { direction: 'bottom', offset: [0, 15], sticky: true })
@@ -197,18 +219,20 @@
}
})
}
- }).addTo(featureGroup)
+ // }).addTo(that.map)
+ }).addTo(layergroup)
store.commit('addSewersDatas', geojson)
if (Object.prototype.hasOwnProperty.call(res, 'features') && res.features.length > 0 && (res.features[0].geometry.type === 'LineString' || res.features[0].geometry.type === 'MultiLineString')) {
geojson.bringToBack()
} else {
geojson.bringToFront()
}
- return featureGroup
+ return geojson
}
removeLayer (item) {
- this.map.removeLayer(this.layerArray[item.code])
+ var layer = this.layerArray[item.code]
+ layer && this.map.removeLayer(layer)
}
/**
--
Gitblit v1.8.0