From 5759640f419b0088eeb98b0dfd394d9b25febe0d Mon Sep 17 00:00:00 2001 From: 陈泽平 <chenzeping> Date: 星期五, 28 五月 2021 20:21:43 +0800 Subject: [PATCH] Merge branch 'develop' of http://xearth.cn:6600/r/wuyushui/SewerAndRainNetwork into develop --- src/components/LayerController/service/LayerFactory.js | 165 ++++++------------------------------------------------ 1 files changed, 20 insertions(+), 145 deletions(-) diff --git a/src/components/LayerController/service/LayerFactory.js b/src/components/LayerController/service/LayerFactory.js index d88b9a6..f7230ba 100644 --- a/src/components/LayerController/service/LayerFactory.js +++ b/src/components/LayerController/service/LayerFactory.js @@ -1,5 +1,4 @@ import WfsLayerService from './WfsLayerService' -import { clone, pulseEffect } from '../../../utils/utils' import { logicMapper, SERVICE_TYPE } from '../../../conf/Constants' import WmsLayerService from './WmsLayerService' @@ -18,9 +17,6 @@ this.minZoomLayers = {} this.wmsLayers = [] this.wmsLayerService = null - // todo 寰呬紭鍖栵紝wmslayerservice璋冪敤锛屾斁杩欓噷涓嶅悎閫� - this.clickSwitch = true // 鍥惧眰鐐瑰嚮寮圭獥寮�鍏� - this.hightlightLayer = options.L.featureGroup({}).addTo(window.map) } init (layerConfig) { @@ -110,6 +106,16 @@ return layer } + showAll (configs) { + if (Array.isArray(configs)) { + for (let i = 0; i < configs.length; i++) { + const config = configs[i] + this.show(config) + } + this.wmsLayerService && this.wmsLayerService.addAll(configs) + } + } + /** * 濡傛灉 瀛樺湪宸茬粡鍔犺浇浜嗙殑瀵硅薄锛屽氨鐩存帴鍔犲埌map * 濡傛灉 涓嶅瓨鍦ㄥ垯 璋冪敤 addLayer 鍙� 閫昏緫绫荤殑init 杩涜鍒濆鍖栨搷浣� @@ -126,10 +132,19 @@ layer.addTo(this.map) } } else { - logic && logic.init(this.addLayer(config), this.L) + logic && logic.init(this.addLayer(config), this.L, config) } logic && logic.start && logic.start() this.wmsLayerService && this.wmsLayerService.add(config) + } + + hideAll (configs) { + if (Array.isArray(configs)) { + for (let i = 0; i < configs.length; i++) { + this.hide(configs[i]) + } + this.wmsLayerService && this.wmsLayerService.removeAll(configs) + } } hide (config) { @@ -164,146 +179,6 @@ this.hide(config) } } - } - } - - /** - * - * 鏍规嵁浼犵殑 feature瀵硅薄瀹氫綅锛� - * @param code - * @param feature - */ - flyByFeature (feature, code) { - this.clearHighlight() - 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]] - } - break - case 'LineString': - var lineString = feature.geometry.coordinates - point = lineString[parseInt(lineString.length / 2)][0] - break - } - 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) { - layer.eachLayer(function (layer) { - const layers = layer.getLayers() - for (var i = 0; i < layers.length; i++) { - const lay = layers[i] - const feature = lay.feature - lay.closePopup() - if (feature.id === id) { - lay.openPopup() - break - } - } - }) - } - /* for (var k in this.layers) { - var layerGroup = this.layers[k] - layerGroup.eachLayer(function (layer) { - console.log(layer) - console.log(layer.getAttribution()) - }) - var layers = layerGroup.getLayers() - if (layers) { - for (var m = 0; m < layers.length; m++) { - var layer = layers[m] - console.log(layer) - console.log(layer.getLayerId(val.id)) - /!* var feature = layer.feature - if (feature.id === layerId) { - this.map.flyToBounds(bound) - return layer - } *!/ - } - } - } */ - return null - } - - findLayerById (layer, id) { - const layers = layer.getLayers - if (layers) { - this.findLayerById(layer.getLayers(), id) - } else { - layer.eachLayer(function (layer) { - // console.log(layer) - }) } } } -- Gitblit v1.8.0