From cb85033879c74f34925a303402c1ad3e4a8646f2 Mon Sep 17 00:00:00 2001 From: 徐旺旺 <11530253@qq.com> Date: 星期一, 10 五月 2021 17:03:54 +0800 Subject: [PATCH] 搜索更换为geoserver wfs,图层顺序,弹窗定位等 --- src/components/LayerController/service/LayerFactory.js | 97 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 77 insertions(+), 20 deletions(-) diff --git a/src/components/LayerController/service/LayerFactory.js b/src/components/LayerController/service/LayerFactory.js index 9387933..f781247 100644 --- a/src/components/LayerController/service/LayerFactory.js +++ b/src/components/LayerController/service/LayerFactory.js @@ -1,7 +1,14 @@ import WfsLayerService from './WfsLayerService' -import WmsLayerService from './WmsLayerService' import { clone } from '../../../utils/utils' -import { logicMapper } from '../../../conf/Constants' +import { logicMapper, SERVICE_TYPE } from '../../../conf/Constants' +import WmsLayerService from './WmsLayerService' + +/** + * init 鍙垵濮嬪寲涓�娆� + * start 姣忔璋冪敤鍥惧眰鏄剧ずshow()鏃讹紝閮戒細璋冪敤 + * destory 姣忔璋冪敤鍥惧眰闅愯棌hide()鏃讹紝閮戒細璋冪敤 + * + */ class LayerFactory { constructor (options) { this.L = options.L @@ -9,9 +16,18 @@ this.layers = {} this.layersLogic = {} this.minZoomLayers = {} + this.wmsLayers = [] + this.clickSwitch = true // 鍥惧眰鐐瑰嚮寮圭獥寮�鍏� } init (layerConfig) { + this.initConfig(layerConfig) + // wms鏈嶅姟鍙渶瑕佸垵濮嬪寲涓�娆� + this.wmsLayerService = new WmsLayerService(this.wmsLayers) + this.wmsLayerService.init() + } + + initConfig (layerConfig) { // 1. 閬嶅巻layer config if (layerConfig) { for (var i = 0; i < layerConfig.length; i++) { @@ -19,6 +35,11 @@ var layers = config.layers var childLayer = config.childLayer var checked = config.checked + /* if (config.groupName) { + const wmsGroupLayerService = new WmsGroupLayerService(config) + wmsGroupLayerService.init() + continue + } */ layers && this.init(config.layers) childLayer && this.init(config.childLayer) @@ -32,14 +53,19 @@ initMinZoom (config) { const minZoom = parseInt(config.minZoom) if (minZoom) { - this.minZoomLayers[minZoom] = config + var configs = this.minZoomLayers[minZoom] + if (configs) { + configs[configs.length] = config + } else { + configs = [config] + } + this.minZoomLayers[minZoom] = configs } } loadLogic (config) { var code = config.code - var wfs = config.wfs - var wms = config.wms + var type = config.type const file = logicMapper[code] var logic = this.layersLogic[code] @@ -47,16 +73,26 @@ 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 (wms) { - logic = new WmsLayerService(config) + } else if (type === SERVICE_TYPE.WMS) { + var layer = {} + layer[config.code] = config + this.wmsLayers.push(layer) } } this.layersLogic[code] = logic return logic } + /** + * 1. 鍏堣皟鐢ㄥ鐞嗛�昏緫鐨� initLayer 锛屽鏋滄病鏈� 灏卞垱寤轰竴涓� featureGroup + * 2. 濡傛灉瀛樺湪浜嬩欢閫昏緫鐨勮瘽锛岀粦瀹歵ooltip,click浜嬩欢 + * 3. 灏唋ayer娣诲姞鍒癿ap + * 4. 杩斿洖layer + * @param config + * @returns layer + */ addLayer (config) { var code = config.code var logic = this.loadLogic(config) @@ -75,17 +111,26 @@ return layer } + /** + * 濡傛灉 瀛樺湪宸茬粡鍔犺浇浜嗙殑瀵硅薄锛屽氨鐩存帴鍔犲埌map + * 濡傛灉 涓嶅瓨鍦ㄥ垯 璋冪敤 addLayer 鍙� 閫昏緫绫荤殑init 杩涜鍒濆鍖栨搷浣� + * 濡傛灉 瀛樺湪start鍑芥暟锛屽垯璋冪敤 + * @param config + */ show (config) { + var index = config.index var layer = this.layers[config.code] var logic = this.loadLogic(config) if (layer) { if (!this.map.hasLayer(layer)) { + index && layer.setZIndex(index) layer.addTo(this.map) } } else { logic && logic.init(this.addLayer(config), this.L) } - logic && logic.create && logic.create() + logic && logic.start && logic.start() + this.wmsLayerService && this.wmsLayerService.add(config) } hide (config) { @@ -94,6 +139,7 @@ layer && this.map.removeLayer(layer) const logic = this.loadLogic(config) logic && logic.destory && logic.destory() + this.wmsLayerService && this.wmsLayerService.remove(config) } /** @@ -107,14 +153,17 @@ toggleByZoom () { const zoom = this.map.getZoom() for (var k in this.minZoomLayers) { - const config = this.minZoomLayers[k] - const checked = config.checked - console.log(zoom) - console.log(k) - if (checked && zoom > k) { - this.show(config) - } else if (checked && zoom < k) { - this.hide(config) + const configs = this.minZoomLayers[k] + for (var j in configs) { + const config = configs[j] + const checked = config.checked + // console.log(zoom) + // console.log(k) + if (checked && zoom > k) { + this.show(config) + } else if (checked && zoom < k) { + this.hide(config) + } } } } @@ -134,10 +183,18 @@ 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(), 15) + console.log(point) + window.map.flyTo(point.reverse(), 17) code && this.openPopup(code, feature.id) } @@ -187,7 +244,7 @@ this.findLayerById(layer.getLayers(), id) } else { layer.eachLayer(function (layer) { - console.log(layer) + // console.log(layer) }) } } -- Gitblit v1.8.0