派生自 wuyushui/SewerAndRainNetwork

陈泽平
2021-05-19 b4fa7ad9c8e0051e9851c3bfbe398d5ff4cbfafe
src/components/helpers/LocateHelper.js
@@ -1,4 +1,4 @@
import { pulseEffect, reversePolyLine } from '../../utils/utils'
import { pulseEffect } from '../../utils/utils'
import Popup from '@views/popup/Popup'
import { LAYERPROPS, LAYERS } from '../../conf/Constants'
@@ -9,8 +9,7 @@
 */
export const locate = function (feature, config, filter) {
  fitBounds(feature)
  highlight(feature, config)
  setTimeout(() => {
  highlight(feature, config.icon)
    const centerPoint = getCenterPoint(feature)
    const params = { LAYERS: config.layerGroup || config.typeName, QUERY_LAYERS: config.layerGroup || config.typeName }
    const filters = []
@@ -23,8 +22,18 @@
    if (filters.length > 0) {
      params.CQL_FILTER = filters.join(' AND ')
    }
    window.mapManager.loadWfsDatas(centerPoint, params).then((res) => {
      openPropsPopup(centerPoint, res.features)
  loadPointWfs(centerPoint, params)
}
/**
 * 加载点范围的wfs数据并弹窗
 * @param latlng  点的经纬度坐标
 * @param params
 */
export const loadPointWfs = function (latlng, params) {
  setTimeout(() => {
    window.mapManager.loadWfsDatas(latlng, params).then((res) => {
      openPropsPopup(latlng, res.features)
    })
  }, 1000)
}
@@ -35,58 +44,58 @@
 */
export const fitBounds = function (feature) {
  const type = feature.geometry.type
  switch (type) {
    case 'Point':
  if (type === 'Point') {
      var point = feature.geometry.coordinates
      point = [point[1], point[0]]
      window.map.setView(point, 17)
      break
    case 'MultiLineString':
  } else {
      window.map.fitBounds(window.L.geoJSON(feature).getBounds())
      break
    case 'LineString':
      window.map.fitBounds(window.L.polyline(reversePolyLine(feature)).getBounds())
      break
  }
}
export const highlight = function (feature, icon) {
  if (Array.isArray(feature)) {
  /* if (Array.isArray(feature)) {
    for (let i = 0; i < feature.length; i++) {
      highlight(feature[i], icon)
    }
  } else {
  } else { */
  window.mapManager.clearHighlight()
    const L = window.L
    const type = feature.geometry.type
    window.mapManager.clearHighlight()
    const highlightLayer = window.mapManager.hightlightLayer
    if (type === 'MultiLineString') {
  if (type === 'Point') {
    // 叠加一个大尺寸的图标
    let point = feature.geometry.coordinates
    point = [point[1], point[0]]
    pointZoom(point, icon)
    pulseEffect(point)
  } else {
      L.geoJSON(feature, {
        style: function () {
          return {
            fillColor: 'red',
            color: 'red'
          }
        }
      }).addTo(highlightLayer)
    } else if (type === 'Point') {
    // 叠加一个大尺寸的图标
      let point = feature.geometry.coordinates
      point = [point[1], point[0]]
  }
}
/**
 * 高亮点位图标
 * @param latlng  经纬度
 * @param icon    图标
 */
export const pointZoom = function (latlng, icon) {
  const L = window.L
  const highlightLayer = window.mapManager.hightlightLayer
      if (icon) {
        L.marker(point, {
    L.marker(latlng, {
          icon: L.icon({
            iconUrl: '/assets/images/map/' + icon,
            iconSize: [30, 30],
            iconAnchor: [15, 15]
          })
        }).addTo(highlightLayer)
      }
      pulseEffect(point)
    } else if (type === 'LineString') {
      L.polyline(reversePolyLine(feature), { color: 'red' }).addTo(highlightLayer)
    }
  }
}
@@ -98,7 +107,6 @@
export const openPropsPopup = function (xy, features) {
  const lt = window.map.latLngToContainerPoint(xy)
  const datas = popupDatas(features)
  console.log(datas)
  if (datas.length > 0) {
    window.$layer.open({
      content: {
@@ -115,32 +123,21 @@
}
export const getCenterPoint = function (feature) {
  const L = window.L
  const type = feature.geometry.type
  var point = []
  switch (type) {
    case 'Point':
      point = feature.geometry.coordinates
      break
    case 'MultiLineString':
      var coordinates = feature.geometry.coordinates
      var coordinate = coordinates[parseInt(coordinates.length / 2)][0]
      if (coordinate.length > 2) {
        point = [coordinate[0], coordinate[1]]
  if (type === 'Point') {
    return [coordinates[1], coordinates[0]]
  } else {
    const center = L.geoJSON(feature, {}).getBounds().getCenter()
    return [center.lat, center.lng]
      }
      break
    case 'LineString':
      var lineString = feature.geometry.coordinates
      point = lineString[parseInt(lineString.length / 2)][0]
      break
  }
  if (point.length > 2) {
    point.splice(2, 1)
  }
  return point.reverse()
}
const popupDatas = function (features) {
  const datas = []
  console.log(features)
  if (features) {
    for (var i = 0; i < features.length; i++) {
      const feature = features[i]
@@ -153,22 +150,49 @@
      if (!propValues) {
        continue
      }
      if (id.indexOf('pipesegment') >= 0) {
        continue
      }
      for (const k in properties) {
        if (propValues[k]) {
          contents[propValues[k]] = properties[k]
        }
      }
      datas.push({
      const data = {
        title: LAYERS[ids[0]],
        name: feature.id,
        content: contents
      })
        content: contents,
        feature: feature
      }
      if (id.indexOf('pipeline') >= 0) {
        data.tableList = listPipeSection(features, properties.subchacode || properties.pipecode)
      }
      datas.push(data)
      console.log(properties)
    }
  }
  return datas
}
// 管线信息绑定所属管段
export const listPipeSection = function (features, code) {
  const list = []
  if (features) {
    for (var i = 0; i < features.length; i++) {
      const feature = features[i]
      const id = feature.id
      if (id.indexOf('pipesegment') < 0) {
        continue
      }
      const properties = feature.properties
      if (properties.pipecode === code) {
        list[list.length] = properties
      }
    }
  }
  return list
}
export const getLayer = function (layerId, id) {
  const layer = this.layers[layerId]