|
|
@@ -7,8 +7,11 @@ import VectorLayer from "ol/layer/Vector.js";
|
|
|
import WKT from "ol/format/WKT.js";
|
|
|
import ScaleLine from "ol/control/ScaleLine";
|
|
|
import { useRouter } from "vue-router";
|
|
|
-import Overlay from 'ol/Overlay'
|
|
|
+import Overlay from "ol/Overlay";
|
|
|
import eventBus from "@/api/eventBus";
|
|
|
+import Style from "ol/style/Style";
|
|
|
+import Icon from "ol/style/Icon";
|
|
|
+import { newPoint } from "@/utils/map.js";
|
|
|
/**
|
|
|
* @description 地图层对象
|
|
|
*/
|
|
|
@@ -17,14 +20,15 @@ class HomeMap {
|
|
|
let that = this;
|
|
|
let vectorStyle = new KMap.VectorStyle();
|
|
|
this.vectorStyle = vectorStyle;
|
|
|
- that.address = ""
|
|
|
+ that.address = "";
|
|
|
+ this.testPointLayer = null;
|
|
|
}
|
|
|
|
|
|
initMap(location, target) {
|
|
|
let level = 9;
|
|
|
let coordinate = util.wktCastGeom(location).getFirstCoordinate();
|
|
|
this.kmap = new KMap.Map(target, level, coordinate[0], coordinate[1], null, 9, 22);
|
|
|
- this.addMapListen()
|
|
|
+ this.addMapListen();
|
|
|
// 添加比例尺控件
|
|
|
const scaleLine = new ScaleLine({
|
|
|
units: 'metric' // 可以选择 'imperial' 或 'metric'
|
|
|
@@ -32,6 +36,48 @@ class HomeMap {
|
|
|
this.kmap.addControl(scaleLine);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 在当前地图中心生成并展示 10 个测试点位
|
|
|
+ */
|
|
|
+ addTestPointsAroundCenter() {
|
|
|
+ if (!this.kmap || !this.kmap.map) return;
|
|
|
+ const center = this.kmap.map.getView().getCenter();
|
|
|
+ if (!center || center.length < 2) return;
|
|
|
+ const [lon, lat] = center;
|
|
|
+
|
|
|
+ // 首次创建测试点图层
|
|
|
+ if (!this.testPointLayer) {
|
|
|
+ const vecLayer = new KMap.VectorLayer("testPointLayer", 1200, {
|
|
|
+ visible: true,
|
|
|
+ style: () =>
|
|
|
+ new Style({
|
|
|
+ image: new Icon({
|
|
|
+ src: "/src/assets/images/warningHome/chat/fly-point.png",
|
|
|
+ scale: 0.6,
|
|
|
+ }),
|
|
|
+ }),
|
|
|
+ });
|
|
|
+ this.kmap.addLayer(vecLayer.layer);
|
|
|
+ this.testPointLayer = vecLayer;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 以当前中心为基准生成 10 个随机偏移点位(小范围散点)
|
|
|
+ const points = [];
|
|
|
+ for (let i = 0; i < 10; i++) {
|
|
|
+ const dx = (Math.random() - 0.5) * 0.2;
|
|
|
+ const dy = (Math.random() - 0.5) * 0.2;
|
|
|
+ points.push({
|
|
|
+ id: `test-${i + 1}`,
|
|
|
+ wkt: `POINT(${lon + dx} ${lat + dy})`,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ points.forEach((item) => {
|
|
|
+ const feature = newPoint(item);
|
|
|
+ this.testPointLayer.addFeature(feature);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
addMapListen() {
|
|
|
let that = this
|
|
|
// 监听地图点击事件
|