12345678910111213141516171819202122232425262728293031323334353637 |
- import proj4 from 'proj4'
- import { register } from 'ol/proj/proj4'
- import { ImageWMS } from 'ol/source'
- import { Image as ImageLayer } from 'ol/layer'
- // China Geodetic Coordinate System 2000
- proj4.defs('EPSG:4490', '+proj=longlat +ellps=GRS80 +no_defs')
- // 注册进 openlayer
- register(proj4)
- export default function wmsLayer(url, option) {
- const { zIndex, radio = 1.0, params, opacity } = option
- const source = new ImageWMS({
- ratio: radio,
- url: url,
- crossOrigin: 'anonymous',
- params: {},
- opacity
- })
- // 处理 layerDefs 为字符串
- source._updateParams = source.updateParams
- source.updateParams = function(params) {
- const newVar = Object.assign({}, params, {
- cql_filter: params.cql_filter
- })
- source._updateParams(newVar)
- }
- params && source.updateParams(params)
- return new ImageLayer({
- source: source,
- zIndex
- })
- }
|