gardenPointLayer.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import eventBus from "@/api/eventBus";
  2. import * as KMap from "@/utils/ol-map/KMap";
  3. import { Vector as VectorSource } from "ol/source.js";
  4. import Style from "ol/style/Style";
  5. import { WKT } from 'ol/format'
  6. import { Fill, Text } from "ol/style";
  7. import Icon from 'ol/style/Icon.js';
  8. import { Feature } from "ol";
  9. import store from '@/store'
  10. import Photo from "ol-ext/style/Photo";
  11. import Stroke from 'ol/style/Stroke.js';
  12. import { newPoint } from "@/utils/map.js";
  13. /**
  14. *
  15. */
  16. class gardenPointLayer {
  17. constructor(kmap) {
  18. let that = this;
  19. this.kmap = kmap
  20. let vectorStyle = new KMap.VectorStyle()
  21. // this.regionLayer = new KMap.VectorLayer("regionLayer", 3, {
  22. // source: new VectorSource({}),
  23. // style: function (f) {
  24. // let style2 = vectorStyle.getPolygonStyle("#032833" + "30", "#c7cb20", 2)
  25. // return [style2]
  26. // }
  27. // });
  28. // this.kmap.addLayer(this.regionLayer.layer)
  29. this.gardenPointLayer = new KMap.VectorLayer("gardenUserLayer", 9999, {
  30. minZoom: 0,
  31. maxZoom: 22,
  32. source: new VectorSource({}),
  33. style: (feature) => {
  34. const organId = feature.get('organId') === this.organId
  35. let style1 = new Style({
  36. image: new Icon({
  37. src: require("@/assets/images/map/garden.png"),
  38. scale: 1,
  39. shadow: 0,
  40. // crop: true,
  41. onload: function () {
  42. that.gardenPointLayer.layer.changed();
  43. },
  44. displacement: [-1, -1],
  45. }),
  46. });
  47. return [style1];
  48. },
  49. });
  50. this.gardenPointLayer2 = new KMap.VectorLayer("gardenUserLayer2", 9999, {
  51. minZoom: 0,
  52. maxZoom: 22,
  53. source: new VectorSource({}),
  54. style: (feature) => {
  55. const organId = feature.get('organId') === this.organId
  56. let style1 = new Style({
  57. image: new Icon({
  58. src: require("@/assets/images/map/garden2.png"),
  59. scale: 1,
  60. shadow: 0,
  61. // crop: true,
  62. onload: function () {
  63. that.gardenPointLayer2.layer.changed();
  64. },
  65. displacement: [-1, -1],
  66. }),
  67. });
  68. return [style1];
  69. },
  70. });
  71. this.kmap.addLayer(this.gardenPointLayer.layer);
  72. this.kmap.addLayer(this.gardenPointLayer2.layer);
  73. this.initLayer()
  74. }
  75. initLayer(){
  76. const gardenList = [
  77. {wkt: "POINT(113.61702297075017 23.584863449735067)"}
  78. ]
  79. const gardenList2 = [
  80. {wkt: "POINT(113.5081595 23.5320866)"}
  81. ]
  82. this.gardenPointLayer.refresh()
  83. this.gardenPointLayer2.refresh()
  84. if (this.gardenPointLayer.source) {
  85. this.gardenPointLayer.source.clear()
  86. this.gardenPointLayer2.source.clear()
  87. // this.gardenReportPointLayer.source.clear()
  88. }
  89. for(let garden of gardenList){
  90. // this.clearOverLay(garden.organId)
  91. garden.wktVal = garden.wkt
  92. this.gardenPointLayer.source.addFeature(newPoint(garden, "wktVal", "myGarden"))
  93. // this.gardenReportPointLayer.source.addFeature(newPoint(garden, "wkt", "myGardenReport"))
  94. // this.initGardenWaring(extractCoordinates(garden.wkt), garden)
  95. }
  96. for(let garden of gardenList2){
  97. // this.clearOverLay(garden.organId)
  98. garden.wktVal = garden.wkt
  99. this.gardenPointLayer2.source.addFeature(newPoint(garden, "wktVal", "myGarden"))
  100. // this.gardenReportPointLayer.source.addFeature(newPoint(garden, "wkt", "myGardenReport"))
  101. // this.initGardenWaring(extractCoordinates(garden.wkt), garden)
  102. }
  103. }
  104. }
  105. export default gardenPointLayer;