派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-03-10 74af7e38b277395b635c6b45f9607e2f0b89aa8f
src/components/helpers/ServiceLayerHelper.js
@@ -126,13 +126,12 @@
      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
        }
        var layer = that.loadGeojson(res.data, item)
        that.layerArray[code] = layer
      }
    } else {
      that.layerArray[code].addTo(that.map)
      var _layer = that.layerArray[code].addTo(that.map)
      that.setZIndex(_layer)
    }
  }
@@ -143,7 +142,7 @@
  loadGeojson (res, opt) {
    var that = this
    var icon = opt.icon
    const featureGroup = that.L.featureGroup().addTo(that.map)
    const featureGroup = that.L.featureGroup()
    const featureList = []
    const geojson = that.L.geoJSON(res.features, {
      style: function (feature) {
@@ -169,6 +168,8 @@
          })
      },
      onEachFeature: function (feature, layer) {
        console.log(feature)
        console.log(layer)
        featureList.push(layer)
        layer.addTo(featureGroup)
      }
@@ -228,12 +229,26 @@
      // }).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()
    featureGroup.addTo(that.map)
    that.setZIndex(featureGroup)
    return featureGroup
  }
  /**
   * 设置index,线在最下面,点在上面
   * @param layerGroup 图层组
   */
  setZIndex (layerGroup) {
    console.log(layerGroup)
    var layers = layerGroup.getLayers()
    if (layers.length > 0) {
      var layer = layers[0]
      if (layer.feature && (layer.feature.geometry.type === 'LineString' || layer.feature.geometry.type === 'MultiLineString')) {
        layerGroup.bringToBack()
      } else {
        layerGroup.bringToFront()
      }
    }
    return geojson
  }
  removeLayer (item) {