From cf5ab6da9ff676fab8a10d4299bd5a04a07bf50f Mon Sep 17 00:00:00 2001 From: 徐旺旺 <11530253@qq.com> Date: 星期一, 17 五月 2021 10:05:53 +0800 Subject: [PATCH] 修复默认选中图层时出现的BUG --- src/components/LayerController/service/LayerFactory.js | 84 +++++++++++++++++++++++++++++++++++------ 1 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/components/LayerController/service/LayerFactory.js b/src/components/LayerController/service/LayerFactory.js index 0a661d6..d88b9a6 100644 --- a/src/components/LayerController/service/LayerFactory.js +++ b/src/components/LayerController/service/LayerFactory.js @@ -1,5 +1,5 @@ import WfsLayerService from './WfsLayerService' -import { clone } from '../../../utils/utils' +import { clone, pulseEffect } from '../../../utils/utils' import { logicMapper, SERVICE_TYPE } from '../../../conf/Constants' import WmsLayerService from './WmsLayerService' @@ -17,14 +17,17 @@ this.layersLogic = {} this.minZoomLayers = {} this.wmsLayers = [] + this.wmsLayerService = null + // todo 寰呬紭鍖栵紝wmslayerservice璋冪敤锛屾斁杩欓噷涓嶅悎閫� this.clickSwitch = true // 鍥惧眰鐐瑰嚮寮圭獥寮�鍏� + this.hightlightLayer = options.L.featureGroup({}).addTo(window.map) } init (layerConfig) { - this.initConfig(layerConfig) // wms鏈嶅姟鍙渶瑕佸垵濮嬪寲涓�娆� - this.wmsLayerService = new WmsLayerService(this.wmsLayers) + this.wmsLayerService = new WmsLayerService() this.wmsLayerService.init() + this.initConfig(layerConfig) } initConfig (layerConfig) { @@ -40,8 +43,8 @@ wmsGroupLayerService.init() continue } */ - layers && this.init(config.layers) - childLayer && this.init(config.childLayer) + layers && this.initConfig(config.layers) + childLayer && this.initConfig(config.childLayer) this.initMinZoom(config) this.loadLogic(config) @@ -75,10 +78,6 @@ logic = new BusiLayer() } else if (type === SERVICE_TYPE.WFS) { logic = new WfsLayerService(config) - } else if (type === SERVICE_TYPE.WMS) { - var layer = {} - layer[config.code] = config - this.wmsLayers.push(layer) } } this.layersLogic[code] = logic @@ -175,11 +174,12 @@ * @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 @@ -193,15 +193,73 @@ point = lineString[parseInt(lineString.length / 2)][0] break } - console.log(point) - 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]] + } + 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