index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import * as KMap from "@/utils/ol-map/KMap";
  2. import * as util from "@/common/ol_common.js";
  3. import config from "@/api/config.js";
  4. import { Point } from 'ol/geom';
  5. import Feature from "ol/Feature";
  6. import Style from "ol/style/Style";
  7. import Icon from "ol/style/Icon";
  8. /**
  9. * @description 地图层对象
  10. */
  11. class IndexMap {
  12. constructor() {
  13. let that = this;
  14. let vectorStyle = new KMap.VectorStyle();
  15. this.vectorStyle = vectorStyle;
  16. // 位置图标
  17. this.clickPointLayer = new KMap.VectorLayer("clickPointLayer", 9999, {
  18. style: (f) => {
  19. return new Style({
  20. image: new Icon({
  21. src: require("@/assets/img/home/garden-point.png"),
  22. scale: 0.5,
  23. anchor: [0.5, 1],
  24. }),
  25. });
  26. },
  27. });
  28. }
  29. initMap(location, target) {
  30. let level = 16;
  31. let coordinate = util.wktCastGeom(location).getFirstCoordinate();
  32. this.kmap = new KMap.Map( target, level, coordinate[0], coordinate[1], null, 8, 22 );
  33. let xyz2 = config.base_img_url3 + "map/lby/{z}/{x}/{y}.png";
  34. this.kmap.addXYZLayer(xyz2, { minZoom: 8, maxZoom: 22 }, 2);
  35. this.kmap.addLayer(this.clickPointLayer.layer);
  36. let point = new Feature(new Point(coordinate))
  37. this.clickPointLayer.addFeature(point)
  38. this.kmap.on("singleclick", (evt) => {
  39. // that.kmap.map.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
  40. // if ( layer instanceof VectorLayer && layer.get("name") === "reportPolygonLayer" ) {
  41. // areaId.data = feature.get("id")
  42. // }
  43. // });
  44. console.log('evt.coordinate', evt.coordinate);
  45. });
  46. }
  47. }
  48. export default IndexMap;