wmsLayer.js 887 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import proj4 from 'proj4'
  2. import { register } from 'ol/proj/proj4'
  3. import { ImageWMS } from 'ol/source'
  4. import { Image as ImageLayer } from 'ol/layer'
  5. // China Geodetic Coordinate System 2000
  6. proj4.defs('EPSG:4490', '+proj=longlat +ellps=GRS80 +no_defs')
  7. // 注册进 openlayer
  8. register(proj4)
  9. export default function wmsLayer(url, option) {
  10. const { zIndex, radio = 1.0, params, opacity } = option
  11. const source = new ImageWMS({
  12. ratio: radio,
  13. url: url,
  14. crossOrigin: 'anonymous',
  15. params: {},
  16. opacity
  17. })
  18. // 处理 layerDefs 为字符串
  19. source._updateParams = source.updateParams
  20. source.updateParams = function(params) {
  21. const newVar = Object.assign({}, params, {
  22. cql_filter: params.cql_filter
  23. })
  24. source._updateParams(newVar)
  25. }
  26. params && source.updateParams(params)
  27. return new ImageLayer({
  28. source: source,
  29. zIndex
  30. })
  31. }