|
|
@@ -178,7 +178,7 @@ onMounted(async () => {
|
|
|
}
|
|
|
});
|
|
|
// 初始化区域选择器的默认值
|
|
|
- initAreaDefaultValue();
|
|
|
+ // initAreaDefaultValue();
|
|
|
|
|
|
// 窗口大小改变时更新地图尺寸
|
|
|
const handleResize = () => {
|
|
|
@@ -194,12 +194,68 @@ onMounted(async () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+// 加载东莞市行政区边界(使用远程 GeoJSON 数据)
|
|
|
const getVillageBoundary = async () => {
|
|
|
- const res = await VE_API.warning.fetchVillageBoundary();
|
|
|
- if (res.code === 0 && res.data) {
|
|
|
- const villageBoundary = res.data;
|
|
|
- console.log(villageBoundary);
|
|
|
- boundaryLayer.initData(villageBoundary);
|
|
|
+ const url =
|
|
|
+ "https://birdseye-img.sysuimars.com/geojson/mlxy/%E4%B8%9C%E8%8E%9E%E8%A1%8C%E6%94%BF%E5%8C%BA.geojson";
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch(url);
|
|
|
+ if (!response.ok) {
|
|
|
+ console.error("获取行政区 GeoJSON 失败:", response.statusText);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const geojson = await response.json();
|
|
|
+ if (!geojson || !Array.isArray(geojson.features)) {
|
|
|
+ console.error("行政区 GeoJSON 格式不正确:", geojson);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将 GeoJSON MultiPolygon 转成 boundaryLayer 需要的 WKT 格式数据
|
|
|
+ const geoJsonMultiPolygonToWkt = (geometry) => {
|
|
|
+ if (!geometry || geometry.type !== "MultiPolygon" || !Array.isArray(geometry.coordinates)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ const polygons = geometry.coordinates
|
|
|
+ .map((polygon) => {
|
|
|
+ // polygon: [ [ [x, y], ... ] ] => 每个 polygon 可能包含多个 ring
|
|
|
+ const rings = polygon
|
|
|
+ .map((ring) => {
|
|
|
+ const coords = ring.map((coord) => `${coord[0]} ${coord[1]}`).join(", ");
|
|
|
+ return `(${coords})`;
|
|
|
+ })
|
|
|
+ .join(", ");
|
|
|
+ return `(${rings})`;
|
|
|
+ })
|
|
|
+ .join(", ");
|
|
|
+
|
|
|
+ return `MULTIPOLYGON (${polygons})`;
|
|
|
+ };
|
|
|
+
|
|
|
+ const villageBoundary = geojson.features
|
|
|
+ .map((f, index) => {
|
|
|
+ const wkt = geoJsonMultiPolygonToWkt(f.geometry);
|
|
|
+ if (!wkt) return null;
|
|
|
+ const props = f.properties || {};
|
|
|
+
|
|
|
+ return {
|
|
|
+ id: props.code || props["区划码"] || index,
|
|
|
+ name: props["地名"] || props.ENG_NAME || "行政区边界",
|
|
|
+ geom: wkt,
|
|
|
+ };
|
|
|
+ })
|
|
|
+ .filter((item) => item);
|
|
|
+
|
|
|
+ if (!villageBoundary.length) {
|
|
|
+ console.warn("未能从 GeoJSON 中解析出有效的行政区边界");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ boundaryLayer && boundaryLayer.initData(villageBoundary);
|
|
|
+ } catch (error) {
|
|
|
+ console.error("加载行政区 GeoJSON 出错:", error);
|
|
|
}
|
|
|
};
|
|
|
|