diff --git a/src/views/screen/components/gisMapOfCounty.vue b/src/views/screen/components/gisMapOfCounty.vue index 205f60f..f8c6d0f 100644 --- a/src/views/screen/components/gisMapOfCounty.vue +++ b/src/views/screen/components/gisMapOfCounty.vue @@ -279,92 +279,86 @@ export default { // 使用 require 加载 GeoJSON 文件 const geojsonData = require('@/assets/geojson/town_boundaries.geojson'); - const colors = ['#33FFD450']; + const colors = ['#33FFD450']; // 定义多边形边界颜色 - // 提取所有边界坐标 - const boundaries = geojsonData.features.map((feature) => { - const coordinates = feature.geometry.coordinates[0]; // 假设是 Polygon 类型 - return coordinates[0].map((coord) => new AMap.LngLat(coord[0], coord[1])); // 转换为 AMap 坐标 - }); - - // this.map.setMask(boundaries); - - // 添加标签 + // 遍历 GeoJSON 数据 geojsonData.features.forEach((feature, index) => { const { properties, geometry } = feature; const name = properties.name; // 获取乡镇名称 const coordinates = geometry.coordinates[0]; // 获取多边形的坐标 - const center = this.getPolygonCenter(coordinates); // 获取多边形的中心点 + const center = this.getPolygonCenter(coordinates); // 计算多边形的中心点 console.log('多边形中心点:', center); - const path = coordinates[0].map((coord) => new AMap.LngLat(coord[0], coord[1])); - path.push(path[0]); // 闭合路径 - // 创建多边形并设置样式 const polygon = new AMap.Polygon({ zIndex: 100, - // path: coordinates[0].map((coord) => new AMap.LngLat(coord[0], coord[1])), // 转换为 AMap 坐标 - path, + path: coordinates[0].map((coord) => new AMap.LngLat(coord[0], coord[1])), // 转换为 AMap 坐标 strokeColor: colors[index % colors.length], // 边界线颜色 - strokeWeight: 3, // 边界线宽度 + strokeWeight: 2, // 边界线宽度 fillColor: '#0A7EA8', // 填充颜色 fillOpacity: 0.5, // 填充透明度 bubble: true, // 允许事件冒泡 }); - // 将多边形添加到地图 + // 添加多边形到地图 polygon.setMap(this.map); + // 如果多边形有名称和中心点,则添加对应的 Marker if (name && center) { const labelMarker = new AMap.Marker({ position: center, zIndex: 2000, clickable: true, content: ` -