From 4423935d0249d35161efa7f2a095fbfc4b2fd017 Mon Sep 17 00:00:00 2001 From: 徐旺旺 <11530253@qq.com> Date: 星期一, 17 五月 2021 17:15:31 +0800 Subject: [PATCH] 定位、弹窗 --- src/components/LayerController/service/WmsLayerService.js | 74 +++++++++++++++++++++++++++++++++++- 1 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/components/LayerController/service/WmsLayerService.js b/src/components/LayerController/service/WmsLayerService.js index 859334d..4706862 100644 --- a/src/components/LayerController/service/WmsLayerService.js +++ b/src/components/LayerController/service/WmsLayerService.js @@ -1,10 +1,78 @@ +import { WMS_URL } from '../../../conf/Constants' +import WmsLayerList from '../dataset/WmsLayerList' + +/** + * todo 寰楄�冭檻涓�涓浘灞傞厤缃簡澶氫釜 wmsLayers鐨勬儏鍐� + */ class WmsLayerService { - constructor (config) { - this.config = config + constructor (layersConfig) { + this.L = window.L + this.map = window.map + this.popupComp = window.popupComp + // wms getfeatureinfo 榛樿鍙傛暟 + this.params = { + VERSION: '1.1.1', + SERVICE: 'WMS', + REQUEST: 'GetFeatureInfo', + // bbox: bbox, + FORMAT: 'image/png', + INFO_FORMAT: 'application/json', + TRANSPARENT: true, + FEATURE_COUNT: 50, + SRS: 'EPSG:4326', + EXCEPTIONS: 'application/vnd.ogc.se_inimage' + } + this.layersConfig = layersConfig + // 瀛樻斁getfeatureinfo鐨勫浘灞傜粍 + this.featureGroup = this.L.featureGroup({}).addTo(this.map) + + this.wmsLayerList = new WmsLayerList() + if (layersConfig) { + for (var i = 0; i < layersConfig.length; i++) { + const config = layersConfig[i] + this.wmsLayerList.addConfig(config) + } + } + this.load() } - init (layer) { + init () { + } + add (config) { + this.wmsLayerList.addConfig(config) + const layers = this.wmsLayerList.getLayers() || '' + const filter = this.wmsLayerList.getFilters() || '' + const params = {} + params.cql_filter = filter + params.layers = layers + this.wmsLayer.setParams(params) + } + + remove (config) { + this.wmsLayerList.remove(config.typeName, config.filter) + const layers = this.wmsLayerList.getLayers() || '' + const filter = this.wmsLayerList.getFilters() || '' + const params = { layers: layers } + params.cql_filter = filter + this.wmsLayer.setParams(params) + } + + load () { + const layers = this.wmsLayerList.getLayers() + const filter = this.wmsLayerList.getFilters() + const params = { + format: 'image/png', // 杩斿洖鐨勬暟鎹牸寮� + transparent: true, + BBOX: this.map.getBounds().toBBoxString() + } + if (layers) { + params.layers = layers + } + if (filter.length > 0) { + params.cql_filter = filter + } + this.wmsLayer = this.L.tileLayer.wms(WMS_URL, params).addTo(this.map) } } -- Gitblit v1.8.0