|
@@ -5,7 +5,7 @@ import Style from "ol/style/Style";
|
|
|
import Icon from "ol/style/Icon";
|
|
import Icon from "ol/style/Icon";
|
|
|
import Fill from "ol/style/Fill";
|
|
import Fill from "ol/style/Fill";
|
|
|
import Stroke from "ol/style/Stroke";
|
|
import Stroke from "ol/style/Stroke";
|
|
|
-import { Point, Polygon } from "ol/geom";
|
|
|
|
|
|
|
+import { Point, Polygon, MultiPolygon } from "ol/geom";
|
|
|
import Feature from "ol/Feature";
|
|
import Feature from "ol/Feature";
|
|
|
import DragPan from "ol/interaction/DragPan";
|
|
import DragPan from "ol/interaction/DragPan";
|
|
|
import MouseWheelZoom from "ol/interaction/MouseWheelZoom";
|
|
import MouseWheelZoom from "ol/interaction/MouseWheelZoom";
|
|
@@ -15,6 +15,8 @@ import DoubleClickZoom from "ol/interaction/DoubleClickZoom";
|
|
|
import KeyboardPan from "ol/interaction/KeyboardPan";
|
|
import KeyboardPan from "ol/interaction/KeyboardPan";
|
|
|
import KeyboardZoom from "ol/interaction/KeyboardZoom";
|
|
import KeyboardZoom from "ol/interaction/KeyboardZoom";
|
|
|
import DragRotateAndZoom from "ol/interaction/DragRotateAndZoom";
|
|
import DragRotateAndZoom from "ol/interaction/DragRotateAndZoom";
|
|
|
|
|
+import Select from "ol/interaction/Select";
|
|
|
|
|
+import { singleClick } from "ol/events/condition";
|
|
|
import { reactive } from "vue";
|
|
import { reactive } from "vue";
|
|
|
import WKT from "ol/format/WKT.js";
|
|
import WKT from "ol/format/WKT.js";
|
|
|
import * as proj from "ol/proj";
|
|
import * as proj from "ol/proj";
|
|
@@ -62,35 +64,55 @@ class MapManage {
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
- this.gridLayer = new KMap.VectorLayer("terrainGridLayer", 900, {
|
|
|
|
|
- style: () => {
|
|
|
|
|
|
|
+ this.gridLayer = new KMap.VectorLayer("terrainGridLayer", 1100, {
|
|
|
|
|
+ style: (feature) => {
|
|
|
|
|
+ const selected = !!feature.get("selected");
|
|
|
return new Style({
|
|
return new Style({
|
|
|
- // fill: new Fill({
|
|
|
|
|
- // color: "rgba(0, 0, 0, 0.25)",
|
|
|
|
|
- // }),
|
|
|
|
|
|
|
+ fill: new Fill({
|
|
|
|
|
+ color: selected ? "rgba(100, 0, 0, 0.5)" : "rgba(255, 255, 255, 0.01)",
|
|
|
|
|
+ }),
|
|
|
stroke: new Stroke({
|
|
stroke: new Stroke({
|
|
|
- color: "rgba(0, 0, 0, 0.57)",
|
|
|
|
|
- width: 1.2,
|
|
|
|
|
|
|
+ color: selected ? "#E03131" : "#fff",
|
|
|
|
|
+ width: selected ? 1.8 : 1.2,
|
|
|
}),
|
|
}),
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
+ this.gridToggleSelect = null;
|
|
|
|
|
+ this.selectedGridIds = new Set();
|
|
|
|
|
+ this.terrainGridItems = [];
|
|
|
this.wktFormat = new WKT();
|
|
this.wktFormat = new WKT();
|
|
|
|
|
+ this.editable = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- initMap(location, target) {
|
|
|
|
|
|
|
+ createReadonlyPolygonStyle() {
|
|
|
|
|
+ return new Style({
|
|
|
|
|
+ fill: new Fill({
|
|
|
|
|
+ color: "rgba(124, 124, 124, 0.5)",
|
|
|
|
|
+ }),
|
|
|
|
|
+ stroke: new Stroke({
|
|
|
|
|
+ color: "rgba(255, 255, 255, 0.55)",
|
|
|
|
|
+ width: 2,
|
|
|
|
|
+ }),
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ initMap(location, target, options = {}) {
|
|
|
|
|
+ const { editable = true } = options;
|
|
|
|
|
+ this.editable = editable;
|
|
|
let level = 16;
|
|
let level = 16;
|
|
|
let coordinate = util.wktCastGeom(location).getFirstCoordinate();
|
|
let coordinate = util.wktCastGeom(location).getFirstCoordinate();
|
|
|
this.kmap = new KMap.Map(target, level, coordinate[0], coordinate[1], null, 8, 22);
|
|
this.kmap = new KMap.Map(target, level, coordinate[0], coordinate[1], null, 8, 22);
|
|
|
let xyz2 = config.base_img_url3 + "map/lby/{z}/{x}/{y}.png";
|
|
let xyz2 = config.base_img_url3 + "map/lby/{z}/{x}/{y}.png";
|
|
|
this.kmap.addXYZLayer(xyz2, { minZoom: 8, maxZoom: 22 }, 2);
|
|
this.kmap.addXYZLayer(xyz2, { minZoom: 8, maxZoom: 22 }, 2);
|
|
|
- this.kmap.addLayer(this.clickPointLayer.layer);
|
|
|
|
|
|
|
+ // this.kmap.addLayer(this.clickPointLayer.layer);
|
|
|
this.kmap.addLayer(this.gridLayer.layer);
|
|
this.kmap.addLayer(this.gridLayer.layer);
|
|
|
|
|
|
|
|
- this.kmap.initDraw(() => {});
|
|
|
|
|
- this.kmap.modifyDraw();
|
|
|
|
|
-
|
|
|
|
|
- this.setRegionDrawingActive(false);
|
|
|
|
|
|
|
+ if (this.editable) {
|
|
|
|
|
+ this.kmap.initDraw(() => {});
|
|
|
|
|
+ this.kmap.modifyDraw();
|
|
|
|
|
+ this.setRegionDrawingActive(false);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -110,7 +132,7 @@ class MapManage {
|
|
|
const c = this.kmap.getView().getCenter();
|
|
const c = this.kmap.getView().getCenter();
|
|
|
this.setMapPoint(c);
|
|
this.setMapPoint(c);
|
|
|
} else {
|
|
} else {
|
|
|
- this.clickPointLayer.source.clear();
|
|
|
|
|
|
|
+ // this.clickPointLayer.source.clear();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -118,10 +140,64 @@ class MapManage {
|
|
|
this.setRegionDrawingActive(true);
|
|
this.setRegionDrawingActive(true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ enableMapInteraction() {
|
|
|
|
|
+ if (!this.kmap) return;
|
|
|
|
|
+ setViewportInteractionsActive(this.kmap.map, true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据中心点和亩数生成正方形 WKT
|
|
|
|
|
+ * @param {number[]} center [lng, lat]
|
|
|
|
|
+ * @param {number} mu 面积(亩)
|
|
|
|
|
+ */
|
|
|
|
|
+ generateSquareWktByMu(center, mu = 60) {
|
|
|
|
|
+ const lng = parseFloat(center[0]);
|
|
|
|
|
+ const lat = parseFloat(center[1]);
|
|
|
|
|
+ const halfSide = Math.sqrt(mu * 666.67) / 2;
|
|
|
|
|
+ const latDelta = halfSide / 111000;
|
|
|
|
|
+ const lngDelta = halfSide / (111000 * Math.cos((lat * Math.PI) / 180));
|
|
|
|
|
+ const ring = [
|
|
|
|
|
+ [lng - lngDelta, lat + latDelta],
|
|
|
|
|
+ [lng + lngDelta, lat + latDelta],
|
|
|
|
|
+ [lng + lngDelta, lat - latDelta],
|
|
|
|
|
+ [lng - lngDelta, lat - latDelta],
|
|
|
|
|
+ [lng - lngDelta, lat + latDelta],
|
|
|
|
|
+ ];
|
|
|
|
|
+ const coordinates = ring.map((point) => `${point[0]} ${point[1]}`).join(", ");
|
|
|
|
|
+ return `MULTIPOLYGON (((${coordinates})))`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 以当前地图中心生成指定亩数的正方形区域
|
|
|
|
|
+ * @param {number} mu 面积(亩)
|
|
|
|
|
+ * @returns {string|null} WKT
|
|
|
|
|
+ */
|
|
|
|
|
+ setDefaultSquareAtCenter(mu = 60) {
|
|
|
|
|
+ if (!this.kmap) return null;
|
|
|
|
|
+ const center = this.kmap.getView().getCenter();
|
|
|
|
|
+ const wkt = this.generateSquareWktByMu(center, mu);
|
|
|
|
|
+ this.setAreaGeometry([wkt]);
|
|
|
|
|
+ this.setMapPoint(center);
|
|
|
|
|
+ return wkt;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ setCenterAndSquare(center, mu = 60) {
|
|
|
|
|
+ if (!this.kmap) return null;
|
|
|
|
|
+ this.kmap.getView().animate({
|
|
|
|
|
+ center,
|
|
|
|
|
+ zoom: 16,
|
|
|
|
|
+ duration: 0,
|
|
|
|
|
+ });
|
|
|
|
|
+ this.setMapPoint(center);
|
|
|
|
|
+ const wkt = this.generateSquareWktByMu(center, mu);
|
|
|
|
|
+ this.setAreaGeometry([wkt]);
|
|
|
|
|
+ return wkt;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
setMapPoint(coordinate) {
|
|
setMapPoint(coordinate) {
|
|
|
- this.clickPointLayer.source.clear();
|
|
|
|
|
|
|
+ // this.clickPointLayer.source.clear();
|
|
|
let point = new Feature(new Point(coordinate));
|
|
let point = new Feature(new Point(coordinate));
|
|
|
- this.clickPointLayer.addFeature(point);
|
|
|
|
|
|
|
+ // this.clickPointLayer.addFeature(point);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setMapPosition(center) {
|
|
setMapPosition(center) {
|
|
@@ -145,25 +221,175 @@ class MapManage {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
clearGridLayer() {
|
|
clearGridLayer() {
|
|
|
|
|
+ this.unbindGridClick();
|
|
|
this.gridLayer?.source?.clear();
|
|
this.gridLayer?.source?.clear();
|
|
|
|
|
+ this.selectedGridIds?.clear();
|
|
|
|
|
+ this.terrainGridItems = [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ unbindGridClick() {
|
|
|
|
|
+ if (this.gridToggleSelect && this.kmap?.map) {
|
|
|
|
|
+ this.kmap.map.removeInteraction(this.gridToggleSelect);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.gridToggleSelect = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bindGridClick() {
|
|
|
|
|
+ if (!this.kmap?.map || !this.gridLayer?.layer) return;
|
|
|
|
|
+ this.unbindGridClick();
|
|
|
|
|
+
|
|
|
|
|
+ const selectedStyle = new Style({
|
|
|
|
|
+ fill: new Fill({
|
|
|
|
|
+ color: "rgba(100, 0, 0, 0.5)",
|
|
|
|
|
+ }),
|
|
|
|
|
+ stroke: new Stroke({
|
|
|
|
|
+ color: "#E03131",
|
|
|
|
|
+ width: 1.8,
|
|
|
|
|
+ }),
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ this.gridToggleSelect = new Select({
|
|
|
|
|
+ condition: singleClick,
|
|
|
|
|
+ toggleCondition: singleClick,
|
|
|
|
|
+ layers: [this.gridLayer.layer],
|
|
|
|
|
+ multi: true,
|
|
|
|
|
+ hitTolerance: 8,
|
|
|
|
|
+ style: selectedStyle,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ this.gridToggleSelect.on("select", (e) => {
|
|
|
|
|
+ e.selected.forEach((feature) => {
|
|
|
|
|
+ feature.set("selected", true);
|
|
|
|
|
+ this.selectedGridIds.add(feature.get("gridId"));
|
|
|
|
|
+ feature.changed();
|
|
|
|
|
+ });
|
|
|
|
|
+ e.deselected.forEach((feature) => {
|
|
|
|
|
+ feature.set("selected", false);
|
|
|
|
|
+ this.selectedGridIds.delete(feature.get("gridId"));
|
|
|
|
|
+ feature.changed();
|
|
|
|
|
+ });
|
|
|
|
|
+ this.gridLayer.layer.changed();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ this.kmap.map.addInteraction(this.gridToggleSelect);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getSelectedGrids() {
|
|
|
|
|
+ const empty = {
|
|
|
|
|
+ gridIds: [],
|
|
|
|
|
+ geometryArr: [],
|
|
|
|
|
+ parcels: [],
|
|
|
|
|
+ mianji: "0.00",
|
|
|
|
|
+ mergedGeometry: "",
|
|
|
|
|
+ };
|
|
|
|
|
+ if (!this.kmap || !this.gridLayer?.source) return empty;
|
|
|
|
|
+
|
|
|
|
|
+ const projection = this.kmap.map.getView().getProjection();
|
|
|
|
|
+ const gridIds = [];
|
|
|
|
|
+ const geometryArr = [];
|
|
|
|
|
+ const parcels = [];
|
|
|
|
|
+ let totalMu = 0;
|
|
|
|
|
+
|
|
|
|
|
+ this.gridLayer.source.getFeatures().forEach((feature) => {
|
|
|
|
|
+ if (!feature.get("selected")) return;
|
|
|
|
|
+ const geometry = feature.getGeometry();
|
|
|
|
|
+ if (!geometry) return;
|
|
|
|
|
+
|
|
|
|
|
+ const gridId = feature.get("gridId");
|
|
|
|
|
+ gridIds.push(gridId);
|
|
|
|
|
+ const wkt = this.wktFormat.writeGeometry(geometry, {
|
|
|
|
|
+ dataProjection: "EPSG:4326",
|
|
|
|
|
+ featureProjection: projection,
|
|
|
|
|
+ });
|
|
|
|
|
+ geometryArr.push(wkt);
|
|
|
|
|
+
|
|
|
|
|
+ let geom = geometry.clone();
|
|
|
|
|
+ geom.transform(proj.get("EPSG:4326"), proj.get("EPSG:38572"));
|
|
|
|
|
+ let mu = getArea(geom);
|
|
|
|
|
+ mu = (mu + mu / 2) / 1000;
|
|
|
|
|
+ totalMu += mu;
|
|
|
|
|
+ parcels.push({ gridId, wkt, mianji: Number(mu.toFixed(2)) });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ gridIds,
|
|
|
|
|
+ geometryArr,
|
|
|
|
|
+ parcels,
|
|
|
|
|
+ mianji: totalMu.toFixed(2),
|
|
|
|
|
+ mergedGeometry: this.mergeGeometryWkts(geometryArr),
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ polygonCoordSetsFromGeometry(geometry) {
|
|
|
|
|
+ if (!geometry || typeof geometry.getType !== "function") return [];
|
|
|
|
|
+ const type = geometry.getType();
|
|
|
|
|
+ if (type === "Polygon") return [geometry.getCoordinates()];
|
|
|
|
|
+ if (type === "MultiPolygon") return geometry.getCoordinates();
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将多个 WKT 面合并为一个(单块返回 POLYGON,多块返回 MULTIPOLYGON)
|
|
|
|
|
+ * @param {string[]} wktArr
|
|
|
|
|
+ * @returns {string}
|
|
|
|
|
+ */
|
|
|
|
|
+ mergeGeometryWkts(wktArr) {
|
|
|
|
|
+ if (!Array.isArray(wktArr) || wktArr.length === 0) return "";
|
|
|
|
|
+ const trimmed = wktArr
|
|
|
|
|
+ .map((item) => String(item).trim())
|
|
|
|
|
+ .filter((item) => item.length > 10);
|
|
|
|
|
+ if (trimmed.length === 0) return "";
|
|
|
|
|
+ if (trimmed.length === 1) return trimmed[0];
|
|
|
|
|
+
|
|
|
|
|
+ const wktOpts = {
|
|
|
|
|
+ dataProjection: "EPSG:4326",
|
|
|
|
|
+ featureProjection: "EPSG:4326",
|
|
|
|
|
+ };
|
|
|
|
|
+ const coordSets = [];
|
|
|
|
|
+ trimmed.forEach((wkt) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const geometry = this.wktFormat.readGeometry(wkt, wktOpts);
|
|
|
|
|
+ coordSets.push(...this.polygonCoordSetsFromGeometry(geometry));
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ /* 单条解析失败则跳过 */
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (coordSets.length === 0) return trimmed[0];
|
|
|
|
|
+ if (coordSets.length === 1) {
|
|
|
|
|
+ return this.wktFormat.writeGeometry(new Polygon(coordSets[0]), wktOpts);
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.wktFormat.writeGeometry(new MultiPolygon(coordSets), wktOpts);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getSelectedGridIds() {
|
|
|
|
|
+ return this.getSelectedGrids().gridIds;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * MULTIPOINT WKT 顶点转 Polygon(接口网格为多点围成的面)
|
|
|
|
|
|
|
+ * 接口网格 geometry 转 Polygon(支持 MULTIPOINT / POLYGON)
|
|
|
*/
|
|
*/
|
|
|
- multipointWktToPolygon(multipointWkt) {
|
|
|
|
|
- if (!this.kmap || !multipointWkt) return null;
|
|
|
|
|
|
|
+ gridGeometryToPolygon(geometryWkt) {
|
|
|
|
|
+ if (!this.kmap || !geometryWkt) return null;
|
|
|
const projection = this.kmap.map.getView().getProjection();
|
|
const projection = this.kmap.map.getView().getProjection();
|
|
|
let geom;
|
|
let geom;
|
|
|
try {
|
|
try {
|
|
|
- geom = this.wktFormat.readGeometry(String(multipointWkt).trim(), {
|
|
|
|
|
|
|
+ geom = this.wktFormat.readGeometry(String(geometryWkt).trim(), {
|
|
|
dataProjection: "EPSG:4326",
|
|
dataProjection: "EPSG:4326",
|
|
|
featureProjection: projection,
|
|
featureProjection: projection,
|
|
|
});
|
|
});
|
|
|
} catch {
|
|
} catch {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- if (geom.getType() !== "MultiPoint") return null;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const type = geom.getType();
|
|
|
|
|
+ if (type === "Polygon") return geom;
|
|
|
|
|
+ if (type === "MultiPolygon") {
|
|
|
|
|
+ const polygons = geom.getPolygons();
|
|
|
|
|
+ return polygons.length ? polygons[0] : null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (type !== "MultiPoint") return null;
|
|
|
|
|
+
|
|
|
const coords = geom.getCoordinates();
|
|
const coords = geom.getCoordinates();
|
|
|
if (!coords || coords.length < 3) return null;
|
|
if (!coords || coords.length < 3) return null;
|
|
|
const ring = coords.map((c) => [...c]);
|
|
const ring = coords.map((c) => [...c]);
|
|
@@ -184,30 +410,95 @@ class MapManage {
|
|
|
this.clearGridLayer();
|
|
this.clearGridLayer();
|
|
|
if (!Array.isArray(gridItems) || !gridItems.length) return;
|
|
if (!Array.isArray(gridItems) || !gridItems.length) return;
|
|
|
|
|
|
|
|
|
|
+ this.terrainGridItems = gridItems.map((item) => ({
|
|
|
|
|
+ id: item.id,
|
|
|
|
|
+ geometry: item.geometry,
|
|
|
|
|
+ area_m2: item.area_m2,
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
gridItems.forEach((item) => {
|
|
gridItems.forEach((item) => {
|
|
|
- const polygon = this.multipointWktToPolygon(item?.geometry);
|
|
|
|
|
|
|
+ const polygon = this.gridGeometryToPolygon(item?.geometry);
|
|
|
if (!polygon) return;
|
|
if (!polygon) return;
|
|
|
const feature = new Feature({ geometry: polygon });
|
|
const feature = new Feature({ geometry: polygon });
|
|
|
feature.set("gridId", item.id);
|
|
feature.set("gridId", item.id);
|
|
|
feature.set("area_m2", item.area_m2);
|
|
feature.set("area_m2", item.area_m2);
|
|
|
|
|
+ feature.set("selected", false);
|
|
|
this.gridLayer.addFeature(feature);
|
|
this.gridLayer.addFeature(feature);
|
|
|
});
|
|
});
|
|
|
|
|
+ this.bindGridClick();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fitGridView() {
|
|
fitGridView() {
|
|
|
if (!this.kmap || !this.gridLayer?.source) return;
|
|
if (!this.kmap || !this.gridLayer?.source) return;
|
|
|
const extent = this.gridLayer.source.getExtent();
|
|
const extent = this.gridLayer.source.getExtent();
|
|
|
if (!extent || extent.some((v) => !Number.isFinite(v))) return;
|
|
if (!extent || extent.some((v) => !Number.isFinite(v))) return;
|
|
|
- this.kmap.getView().fit(extent, { duration: 500, padding: [80, 80, 80, 80] });
|
|
|
|
|
|
|
+ this.kmap.getView().fit(extent, { duration: 500, padding: [40, 40, 40, 40] });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getDisplayAreaWkt() {
|
|
|
|
|
+ if (!this.kmap?.polygonLayer?.source) return "";
|
|
|
|
|
+ const projection = this.kmap.map.getView().getProjection();
|
|
|
|
|
+ const geometryArr = [];
|
|
|
|
|
+ this.kmap.polygonLayer.source.getFeatures().forEach((feature) => {
|
|
|
|
|
+ const geometry = feature.getGeometry();
|
|
|
|
|
+ if (!geometry) return;
|
|
|
|
|
+ geometryArr.push(
|
|
|
|
|
+ this.wktFormat.writeGeometry(geometry, {
|
|
|
|
|
+ dataProjection: "EPSG:4326",
|
|
|
|
|
+ featureProjection: projection,
|
|
|
|
|
+ })
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+ return this.mergeGeometryWkts(geometryArr);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getTerrainGridItems() {
|
|
|
|
|
+ if (this.terrainGridItems.length) {
|
|
|
|
|
+ return this.terrainGridItems.map((item) => ({ ...item }));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!this.kmap || !this.gridLayer?.source) return [];
|
|
|
|
|
+
|
|
|
|
|
+ const projection = this.kmap.map.getView().getProjection();
|
|
|
|
|
+ return this.gridLayer.source.getFeatures().map((feature) => {
|
|
|
|
|
+ const geometry = feature.getGeometry();
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: feature.get("gridId"),
|
|
|
|
|
+ geometry: geometry
|
|
|
|
|
+ ? this.wktFormat.writeGeometry(geometry, {
|
|
|
|
|
+ dataProjection: "EPSG:4326",
|
|
|
|
|
+ featureProjection: projection,
|
|
|
|
|
+ })
|
|
|
|
|
+ : "",
|
|
|
|
|
+ area_m2: feature.get("area_m2"),
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ restoreSelectedGrids(gridIds) {
|
|
|
|
|
+ if (!this.gridLayer?.source || !Array.isArray(gridIds)) return;
|
|
|
|
|
+ const idSet = new Set(gridIds.map((id) => String(id)));
|
|
|
|
|
+ this.selectedGridIds.clear();
|
|
|
|
|
+ this.gridLayer.source.getFeatures().forEach((feature) => {
|
|
|
|
|
+ const gridId = feature.get("gridId");
|
|
|
|
|
+ const selected = idSet.has(String(gridId));
|
|
|
|
|
+ feature.set("selected", selected);
|
|
|
|
|
+ if (selected) {
|
|
|
|
|
+ this.selectedGridIds.add(gridId);
|
|
|
|
|
+ }
|
|
|
|
|
+ feature.changed();
|
|
|
|
|
+ });
|
|
|
|
|
+ this.gridLayer.layer.changed();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
destroyMap() {
|
|
destroyMap() {
|
|
|
|
|
+ this.unbindGridClick();
|
|
|
this.clearLayer();
|
|
this.clearLayer();
|
|
|
if (this.kmap && typeof this.kmap.destroy === "function") {
|
|
if (this.kmap && typeof this.kmap.destroy === "function") {
|
|
|
this.kmap.destroy();
|
|
this.kmap.destroy();
|
|
|
}
|
|
}
|
|
|
this.kmap = null;
|
|
this.kmap = null;
|
|
|
this.regionDrawingActive = false;
|
|
this.regionDrawingActive = false;
|
|
|
|
|
+ this.selectedGridIds?.clear();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -243,18 +534,29 @@ class MapManage {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setAreaGeometry(geometryArr) {
|
|
setAreaGeometry(geometryArr) {
|
|
|
- this.clearLayer()
|
|
|
|
|
- let that = this
|
|
|
|
|
- geometryArr.map(item => {
|
|
|
|
|
- that.kmap.setLayerWkt(item)
|
|
|
|
|
- })
|
|
|
|
|
- this.fitView()
|
|
|
|
|
|
|
+ this.clearLayer();
|
|
|
|
|
+ if (!this.kmap) return;
|
|
|
|
|
+
|
|
|
|
|
+ const format = new WKT();
|
|
|
|
|
+ const mapProjection = this.kmap.map.getView().getProjection();
|
|
|
|
|
+ geometryArr.forEach((item) => {
|
|
|
|
|
+ const geometry = format.readGeometry(item, {
|
|
|
|
|
+ dataProjection: "EPSG:4326",
|
|
|
|
|
+ featureProjection: mapProjection,
|
|
|
|
|
+ });
|
|
|
|
|
+ const feature = new Feature({ geometry });
|
|
|
|
|
+ if (!this.editable) {
|
|
|
|
|
+ feature.setStyle(this.createReadonlyPolygonStyle());
|
|
|
|
|
+ }
|
|
|
|
|
+ this.kmap.polygonLayer.source.addFeature(feature);
|
|
|
|
|
+ });
|
|
|
|
|
+ this.fitView();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fitView(){
|
|
fitView(){
|
|
|
let extent = this.kmap.polygonLayer.source.getExtent()
|
|
let extent = this.kmap.polygonLayer.source.getExtent()
|
|
|
// 地图自适应到区域可视范围
|
|
// 地图自适应到区域可视范围
|
|
|
- this.kmap.getView().fit(extent, { duration: 500, padding: [100, 100, 100, 100] });
|
|
|
|
|
|
|
+ this.kmap.getView().fit(extent, { duration: 500, padding: [40, 40, 40, 40] });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|