StaticImgLayer.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import LTBaseObject from './KBaseObject'
  2. import XYZ from 'ol/source/XYZ'
  3. import Tile from 'ol/layer/Tile'
  4. import Common from './Common'
  5. import {GeoJSON} from "ol/format";
  6. import VectorSource from "ol/source/Vector.js";
  7. import VectorLayer from "ol/layer/Vector.js";
  8. import Static from "ol/source/ImageStatic";
  9. import ImageLayer from "ol/layer/Image";
  10. /**
  11. * @description LTMap.GeoJsonLayer GeoJsonLayer图层类
  12. */
  13. class StaticImgLayer extends LTBaseObject{
  14. /**
  15. * @description 构造函数
  16. * @param {String} url XYZ图层服务地址
  17. * @param {LTMap.Map} [mapInstance=null] map对象,单地图的时候可不传,多地图时候需要传
  18. * @memberof XYZLayer
  19. */
  20. constructor(url,options,zIndex,mapInstance = null){
  21. super(mapInstance)
  22. const vm = this
  23. vm.initStaticImgLayer(url,options,zIndex)
  24. }
  25. /**
  26. * @description 初始化静态图片图层
  27. */
  28. initStaticImgLayer(url,options,zIndex){
  29. var minZoom = Common.BaseLayerZoom[0];
  30. var maxZoom = Common.BaseLayerZoom[1];
  31. let opacity = 1;
  32. if(options && options.opacity != undefined){
  33. opacity = options.opacity
  34. }
  35. if(options && options.minZoom != undefined){
  36. minZoom = options.minZoom
  37. }
  38. if(options && options.maxZoom != undefined){
  39. maxZoom = options.maxZoom
  40. }
  41. const vm = this
  42. vm.source = new Static({
  43. url, // 替换为你的GeoJSON文件URL
  44. projection: 'EPSG:4326',
  45. imageExtent: options.extent,
  46. });
  47. vm.layer = new ImageLayer({
  48. source:vm.source,
  49. maxZoom:maxZoom,
  50. minZoom:minZoom,
  51. opacity:opacity,
  52. zIndex:zIndex,
  53. extent:options.extent || [Infinity, -Infinity, -Infinity, Infinity]
  54. })
  55. vm.map.addLayer(vm.layer)
  56. }
  57. setProperty(properties){
  58. const vm = this;
  59. vm.properties = properties;
  60. }
  61. getProperty(){
  62. const vm = this;
  63. return vm.properties?vm.properties:null;
  64. }
  65. /**
  66. * @description 添加XYZ图层到地图
  67. * @memberof XYZLayer
  68. */
  69. add(){
  70. const vm = this
  71. if(!vm.state) {
  72. vm.map.addLayer(vm.layer)
  73. vm.state = true
  74. }
  75. }
  76. /**
  77. * @description 从当前地图中移除XYZ图层
  78. * @memberof XYZLayer
  79. */
  80. remove() {
  81. const vm = this
  82. if(vm.state) {
  83. vm.map.removeLayer(vm.layer)
  84. vm.state = false
  85. }
  86. }
  87. /**
  88. * @description 显示XYZ图层数据
  89. * @memberof XYZLayer
  90. */
  91. show(){
  92. const vm = this
  93. vm.layer.setVisible(true)
  94. }
  95. /**
  96. * @description 隐藏XYZ图层数据
  97. * @memberof XYZLayer
  98. */
  99. hide(){
  100. const vm = this
  101. vm.layer.setVisible(false)
  102. }
  103. /**
  104. * @description 缩放到过滤后的地图要素对应范围
  105. * @memberof XYZLayer
  106. */
  107. zoomTo() {
  108. const vm = this
  109. }
  110. }
  111. export default StaticImgLayer