import { WMS_URL } from '../../../conf/Constants'
|
import WmsLayerList from '../dataset/WmsLayerList'
|
|
/**
|
* todo 得考虑一个图层配置了多个 wmsLayers的情况
|
*/
|
class WmsLayerService {
|
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 () {
|
}
|
|
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)
|
}
|
}
|
|
export default WmsLayerService
|