派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-03-10 7af28eaca09c2aa1f9a678df081abb378e22ee16
src/components/helpers/ServiceLayerHelper.js
@@ -116,18 +116,19 @@
     * @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)
      const res = await AjaxUtils.GetDataAsynByUrl(newUrl, {})
      if (res.data instanceof Object && Object.prototype.hasOwnProperty.call(res.data, 'features')) {
        store.commit('addSewersDatas', res.data)
        var layer = that.loadGeojson(res.data, item)
        that.layerArray[code] = layer
      })
      }
    } else {
      that.layerArray[code].addTo(that.map)
    }
@@ -140,6 +141,8 @@
  loadGeojson (res, opt) {
    var that = this
    var icon = opt.icon
    const featureGroup = that.L.featureGroup()
    const featureList = []
    const geojson = that.L.geoJSON(res.features, {
      style: function (feature) {
        return {
@@ -148,9 +151,9 @@
          fillColor: styles.defaultLineStyle.fillColor,
          color: styles.defaultLineStyle.color,
          fillOpacity: styles.defaultLineStyle.fillOpacity,
          opacity: styles.defaultLineStyle.opacity
          // dashArray: styles.defaultLineStyle.dashArray,
          // dashSpeed: styles.defaultLineStyle.dashSpeed
          opacity: styles.defaultLineStyle.opacity,
          dashArray: styles.defaultLineStyle.dashArray,
          dashSpeed: styles.defaultLineStyle.dashSpeed
        }
      },
      pointToLayer: function (geoJsonPoint, latlng) {
@@ -162,6 +165,12 @@
              size: styles.defaultLineStyle.size
            }
          })
      },
      onEachFeature: function (feature, layer) {
        console.log(feature)
        console.log(layer)
        featureList.push(layer)
        layer.addTo(featureGroup)
      }
    }).bindPopup(function (layer) {
      that.popupComp.setDatas(layer)
@@ -215,14 +224,17 @@
            }
          })
        }
      }).addTo(that.map)
      // }).addTo(that.map)
      // }).addTo(featureGroup)
      })
    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 geojson
    featureGroup.addTo(that.map)
    return featureGroup
  }
  removeLayer (item) {