From 75b8a112386600944f19275d6def2b5d5f2ae51d Mon Sep 17 00:00:00 2001 From: yaoyuhao Date: Tue, 23 Jul 2024 16:29:03 +0800 Subject: [PATCH] gx --- src/view/sy_map.vue | 54 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/view/sy_map.vue b/src/view/sy_map.vue index c281e82..48f300b 100644 --- a/src/view/sy_map.vue +++ b/src/view/sy_map.vue @@ -179,6 +179,8 @@ const mapTownCount = reactive([ //默认龙游县灰色地块 const mapTownDataDK = reactive([]); +//社区地块 +const xkzDk = reactive([]); var map = null; const initMap = () => { map = new BMapGL.Map("map", { minZoom: 11, maxZoom: 20 }); @@ -238,6 +240,47 @@ const addPolygonCounty = () => { createCustomOverlayJd(item); }); }; +//加载村社信息 +const loadCs = () => { + for (let v of xkz.features) { + if (v.geometry.coordinates.length > 1) { + for (let w in v.geometry.coordinates) { + if (v.geometry.coordinates[w][0].length < 60) continue; + xkzDk.push({ + name: v.properties.name, + point: v.geometry.coordinates[w][0], + }); + } + } else { + xkzDk.push({ + name: v.properties.name, + point: v.geometry.coordinates[0], + }); + } + } +}; +//添加村社区块 +const addPolygonCountyCs = () => { + console.log(888888,xkzDk); + let fillColor = "#red"; + xkzDk.map((item) => { + //地区的坐标范围 + let points = []; + item.point.map((p) => points.push(new BMapGL.Point(...p))); + if (points.length) { + //创建面 + let polygonCs = new BMapGL.Polygon(points, { + strokeColor: "blue", + strokeWeight: 2, + strokeOpacity: 0.8, + fillColor: fillColor, + fillOpacity: 0.7, + name: item.name, + }); + map.addOverlay(polygonCs); + } + }); +}; // 添加地图上的街道名 const createCustomOverlayJd = (polygon) => { function createLabelDOM() { @@ -264,7 +307,14 @@ const createCustomOverlayJd = (polygon) => { div.appendChild(title); title.appendChild(document.createTextNode(this.properties.title)); content.appendChild(div); - + div.onclick = function () { + console.log(11111111, polygon); + if (polygon.name == "溪口镇") { + loadCs(); + addPolygonCountyCs(); + console.log(2222); + } + }; return content; } var customOverlay = new BMapGL.CustomOverlay(createLabelDOM, { @@ -346,7 +396,7 @@ const removeAllPolygon = () => { let allOverlay = map.getOverlays(); console.log("allOverlay", allOverlay); for (let i = 0; i < allOverlay.length; i++) { - map.removeOverlay(allOverlay[i]); + map.removeOverlay(allOverlay[i]); } addPolygonCounty(); };