From 0df1b9e7efbf4204c0d87d3018c41b6214f53489 Mon Sep 17 00:00:00 2001
From: chenyabin <Chenab123!>
Date: 星期五, 14 五月 2021 11:16:43 +0800
Subject: [PATCH] 图例部分图标替换
---
src/components/LayerController/service/LayerFactory.js | 91 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 80 insertions(+), 11 deletions(-)
diff --git a/src/components/LayerController/service/LayerFactory.js b/src/components/LayerController/service/LayerFactory.js
index f7ee38d..51fe254 100644
--- a/src/components/LayerController/service/LayerFactory.js
+++ b/src/components/LayerController/service/LayerFactory.js
@@ -1,7 +1,8 @@
import WfsLayerService from './WfsLayerService'
import { clone } from '../../../utils/utils'
-import { logicMapper } from '../../../conf/Constants'
+import { logicMapper, SERVICE_TYPE } from '../../../conf/Constants'
import WmsLayerService from './WmsLayerService'
+import AnimalService from './AnimalService'
/**
* init 鍙垵濮嬪寲涓�娆�
@@ -17,7 +18,9 @@
this.layersLogic = {}
this.minZoomLayers = {}
this.wmsLayers = []
- this.clickSwitch = false
+ this.clickSwitch = true // 鍥惧眰鐐瑰嚮寮圭獥寮�鍏�
+ this.animalService = new AnimalService({ L: this.L })
+ this.hightlightLayer = options.L.featureGroup({}).addTo(window.map)
}
init (layerConfig) {
@@ -36,7 +39,7 @@
var childLayer = config.childLayer
var checked = config.checked
/* if (config.groupName) {
- const wmsGroupLayerService = new WmsGroupLayerService(config)
+ const wmsGroupLayerService = new WmsLayerGroupService(config)
wmsGroupLayerService.init()
continue
} */
@@ -65,8 +68,7 @@
loadLogic (config) {
var code = config.code
- var wfs = config.wfs
- var wmsLayers = config.wmsLayers
+ var type = config.type
const file = logicMapper[code]
var logic = this.layersLogic[code]
@@ -74,9 +76,9 @@
if (file) {
var BusiLayer = require('../logic/' + file)
logic = new BusiLayer()
- } else if (wfs) {
+ } else if (type === SERVICE_TYPE.WFS) {
logic = new WfsLayerService(config)
- } else if (wmsLayers) {
+ } else if (type === SERVICE_TYPE.WMS) {
var layer = {}
layer[config.code] = config
this.wmsLayers.push(layer)
@@ -176,25 +178,92 @@
* @param feature
*/
flyByFeature (feature, code) {
+ this.clearHighlight()
const type = feature.geometry.type
var point = []
switch (type) {
case 'Point':
- point = clone(feature.geometry.coordinates)
+ point = feature.geometry.coordinates
break
case 'MultiLineString':
var coordinates = feature.geometry.coordinates
- point = coordinates[parseInt(coordinates.length / 2)][0]
+ var coordinate = coordinates[parseInt(coordinates.length / 2)][0]
+ if (coordinate.length > 2) {
+ point = [coordinate[0], coordinate[1]]
+ }
+ break
+ case 'LineString':
+ var lineString = feature.geometry.coordinates
+ point = lineString[parseInt(lineString.length / 2)][0]
break
}
- window.map.flyTo(point.reverse(), 17)
+ if (point.length > 2) {
+ point.splice(2, 1)
+ }
+ this.highlight(feature)
+ window.map.setView(clone(point).reverse(), 17)
code && this.openPopup(code, feature.id)
+ }
+
+ clearHighlight () {
+ this.hightlightLayer.clearLayers()
+ }
+
+ highlight (feature) {
+ const type = feature.geometry.type
+ if (type === 'MultiLineString') {
+ this.L.geoJSON(feature, {
+ style: function () {
+ return {
+ fillColor: 'red',
+ color: 'red'
+ }
+ }
+ }).addTo(this.hightlightLayer)
+ } else if (type === 'Point') {
+ let point = clone(feature.geometry.coordinates)
+ if (point.length > 2) {
+ point = [point[0], point[1]]
+ }
+ this.animalService.pulseEffect(point.reverse())
+ /* var myIcon = this.L.divIcon({ className: 'my-div-icon' })
+ this.L.marker(feature.geometry.coordinates.reverse(), {
+ icon: myIcon
+ }).addTo(this.hightlightLayer) */
+ } else if (type === 'LineString') {
+ this.L.polyline(this.reversePolyLine(feature), { color: 'red' }).addTo(this.hightlightLayer)
+ }
+ }
+
+ reverseMultiLine (feature) {
+ const coordinates = feature.geometry.coordinates
+ var latlng = []
+ for (var j = 0; j < coordinates.length; j++) {
+ const coordinate = coordinates[j]
+ var xy = []
+ for (var k = 0; k < coordinate.length; k++) {
+ const coor = coordinate[k]
+ xy.push(coor.reverse())
+ }
+ latlng.push(xy)
+ }
+ return latlng
+ }
+
+ reversePolyLine (feature) {
+ const coordinates = feature.geometry.coordinates
+ var latlng = []
+ for (var j = 0; j < coordinates.length; j++) {
+ const coordinate = coordinates[j]
+ latlng.push(coordinate.reverse())
+ }
+ return latlng
}
openPopup (layerId, id) {
const layer = this.layers[layerId]
- if (layer.eachLayer) {
+ if (layer) {
layer.eachLayer(function (layer) {
const layers = layer.getLayers()
for (var i = 0; i < layers.length; i++) {
--
Gitblit v1.8.0