|
|
@@ -1,6 +1,7 @@
|
|
|
import * as KMap from "@/utils/ol-map/KMap";
|
|
|
import * as util from "@/common/ol_common.js";
|
|
|
import config from "@/api/config.js";
|
|
|
+import StaticImgLayer from "@/utils/ol-map/StaticImgLayer";
|
|
|
import { Vector as VectorSource } from "ol/source.js";
|
|
|
import Style from "ol/style/Style";
|
|
|
import Text from "ol/style/Text";
|
|
|
@@ -16,6 +17,29 @@ import {
|
|
|
getHeight,
|
|
|
} from "ol/extent";
|
|
|
|
|
|
+/** PNG 农场影像底图:extent 为 [minLon, minLat, maxLon, maxLat],仅以下农场有数据 */
|
|
|
+const FARM_BASE_IMAGE_LAYERS = [
|
|
|
+ {
|
|
|
+ name: "东莞市潢涌村水稻基地",
|
|
|
+ farmId: 320,
|
|
|
+ url: "https://birdseye-img.sysuimars.com/platform-rs/farm_320_20260314.png",
|
|
|
+ extent: [113.48318638854593, 22.90042586164938, 113.98019565717107, 23.36008435819883],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "莞荔园",
|
|
|
+ farmId: 319,
|
|
|
+ url: "https://birdseye-img.sysuimars.com/platform-rs/farm_319_20260314.png",
|
|
|
+ extent: [113.49887532172826, 22.74031995946140, 113.99520269126261, 23.19988233865987],
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+const FARM_BASE_IMAGE_FARM_IDS = new Set(FARM_BASE_IMAGE_LAYERS.map((item) => item.farmId));
|
|
|
+
|
|
|
+export function hasFarmBaseImage(farmId) {
|
|
|
+ if (farmId == null || farmId === "") return false;
|
|
|
+ return FARM_BASE_IMAGE_FARM_IDS.has(Number(farmId));
|
|
|
+}
|
|
|
+
|
|
|
const WKT_FORMAT = new WKT();
|
|
|
|
|
|
const RECORD_TYPE_STYLE = {
|
|
|
@@ -105,6 +129,9 @@ class FileMap {
|
|
|
this._pending = null;
|
|
|
this._fitTimer = null;
|
|
|
this._renderToken = 0;
|
|
|
+ this.baseImageLayers = [];
|
|
|
+ this.baseImageVisible = false;
|
|
|
+ this.currentFarmId = null;
|
|
|
const vectorStyle = new KMap.VectorStyle();
|
|
|
|
|
|
this.recordPolygonLayer = new KMap.VectorLayer("fileRecordPolygonLayer", 1000, {
|
|
|
@@ -131,6 +158,49 @@ class FileMap {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ initBaseImageLayers() {
|
|
|
+ FARM_BASE_IMAGE_LAYERS.forEach((item) => {
|
|
|
+ const imgLayer = new StaticImgLayer(
|
|
|
+ item.url,
|
|
|
+ {
|
|
|
+ extent: item.extent,
|
|
|
+ minZoom: 8,
|
|
|
+ maxZoom: 22,
|
|
|
+ opacity: 0.4,
|
|
|
+ },
|
|
|
+ 4,
|
|
|
+ this.kmap,
|
|
|
+ );
|
|
|
+ this.baseImageLayers.push({ farmId: item.farmId, layer: imgLayer });
|
|
|
+ });
|
|
|
+ this.applyBaseImageVisibility();
|
|
|
+ }
|
|
|
+
|
|
|
+ applyBaseImageVisibility() {
|
|
|
+ const canShow = this.baseImageVisible && hasFarmBaseImage(this.currentFarmId);
|
|
|
+ this.baseImageLayers.forEach(({ farmId, layer }) => {
|
|
|
+ const shouldShow = canShow && farmId === this.currentFarmId;
|
|
|
+ if (shouldShow) {
|
|
|
+ layer.show();
|
|
|
+ } else {
|
|
|
+ layer.hide();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ showBaseImageByFarmId(farmId) {
|
|
|
+ this.currentFarmId = farmId != null && farmId !== "" ? Number(farmId) : null;
|
|
|
+ if (!hasFarmBaseImage(this.currentFarmId)) {
|
|
|
+ this.baseImageVisible = false;
|
|
|
+ }
|
|
|
+ this.applyBaseImageVisibility();
|
|
|
+ }
|
|
|
+
|
|
|
+ toggleBaseImageLayers(visible = !this.baseImageVisible) {
|
|
|
+ this.baseImageVisible = visible && hasFarmBaseImage(this.currentFarmId);
|
|
|
+ this.applyBaseImageVisibility();
|
|
|
+ }
|
|
|
+
|
|
|
initMap(centerWkt, target) {
|
|
|
if (!target) return;
|
|
|
|
|
|
@@ -149,6 +219,7 @@ class FileMap {
|
|
|
|
|
|
this.kmap = new KMap.Map(target, 16, center[0], center[1], null, 8, 22);
|
|
|
this.kmap.addXYZLayer(config.base_img_url3 + "map/lby/{z}/{x}/{y}.png", { minZoom: 8, maxZoom: 22 }, 2);
|
|
|
+ this.initBaseImageLayers();
|
|
|
this.kmap.addLayer(this.recordPolygonLayer.layer);
|
|
|
|
|
|
if (this._pending) {
|