This commit is contained in:
姚宇浩 2024-07-23 16:29:03 +08:00
parent f8b75b05b1
commit 75b8a11238
1 changed files with 52 additions and 2 deletions

View File

@ -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, {