派生自 wuyushui/SewerAndRainNetwork

wangqi
2021-03-15 f2c8563d7f3bcc3131524214456464a512e2624a
src/components/helpers/ServiceLayerHelper.js
@@ -140,11 +140,10 @@
     * @param res
     */
  loadGeojson (res, opt) {
    var that = this
    var icon = opt.icon
    const featureGroup = that.L.featureGroup()
    const featureGroup = this.L.featureGroup()
    const featureList = []
    const geojson = that.L.geoJSON(res.features, {
    const geojson = this.L.geoJSON(res.features, {
      style: function (feature) {
        return {
          fill: styles.defaultLineStyle.fill,
@@ -157,8 +156,8 @@
          dashSpeed: styles.defaultLineStyle.dashSpeed
        }
      },
      pointToLayer: function (geoJsonPoint, latlng) {
        return that.L.canvasMarker(latlng,
      pointToLayer: (geoJsonPoint, latlng) => {
        return this.L.canvasMarker(latlng,
          {
            img: {
              // url: 'assets/images/map/marker-icon.png',
@@ -167,70 +166,64 @@
            }
          })
      },
      onEachFeature: function (feature, layer) {
        console.log(feature)
        console.log(layer)
      onEachFeature: (feature, layer) => {
        featureList.push(layer)
        layer.addTo(featureGroup)
      }
    }).bindPopup(function (layer) {
      that.popupComp.setDatas(layer)
      that.popupComp.setShow()
      return that.popupComp.$el
    }, {
      className: 's-map-popup',
      minWidth: 300,
      closeButton: false,
      autoClose: false
    })
      .bindTooltip(function (layer) {
        const nameId = layer.feature.id
        let name = ''
        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 })
      .on('mouseover', function (e) {
        const layer = e.layer
        const type = e.layer.feature.geometry.type
        if (type === 'LineString' || type === 'MultiLineString') {
          layer.setStyle({ weight: 8, color: '#00ffff' })
        } else if (type === 'Point' || type === 'MultiPoint') {
          layer.setStyle({
            img: {
              url: '/assets/images/map/' + icon,
              size: [25, 25]
        layer.bindPopup((layer) => {
          this.popupComp.setDatas(layer)
          this.popupComp.setShow()
          return this.popupComp.$el
        }, {
          className: 's-map-popup',
          minWidth: 300,
          closeButton: false,
          autoClose: false
        })
          .bindTooltip((layer) => {
            const nameId = layer.feature.id
            let name = ''
            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 })
          .on('mouseover', (e) => {
            const type = e.target.feature.geometry.type
            if (type === 'LineString' || type === 'MultiLineString') {
              layer.setStyle({ weight: 8, color: '#00ffff' })
            } else if (type === 'Point' || type === 'MultiPoint') {
              layer.setStyle({
                img: {
                  url: '/assets/images/map/' + icon,
                  size: [25, 25]
                }
              })
          layer.bringToFront()
        }
      }).on('mouseout', function (e) {
        const layer = e.layer
        const type = e.layer.feature.geometry.type
        if (type === 'LineString' || type === 'MultiLineString') {
          layer.setStyle({ weight: styles.defaultLineStyle.weight, color: styles.defaultLineStyle.color })
        }
        if (type === 'Point' || type === 'MultiPoint') {
          layer.setStyle({
            img: {
              url: '/assets/images/map/' + icon,
              size: styles.defaultLineStyle.size
              layer.bringToFront()
            }
          })
        }
      // }).addTo(that.map)
      // }).addTo(featureGroup)
      })
          }).on('mouseout', (e) => {
            const type = e.target.feature.geometry.type
            if (type === 'LineString' || type === 'MultiLineString') {
              layer.setStyle({ weight: styles.defaultLineStyle.weight, color: styles.defaultLineStyle.color })
            }
            if (type === 'Point' || type === 'MultiPoint') {
              layer.setStyle({
                img: {
                  url: '/assets/images/map/' + icon,
                  size: styles.defaultLineStyle.size
                }
              })
            }
          }).addTo(featureGroup)
      }
    })
    store.commit('addSewersDatas', geojson)
    featureGroup.addTo(that.map)
    that.setZIndex(featureGroup)
    featureGroup.addTo(this.map)
    this.setZIndex(featureGroup)
    return featureGroup
  }