餐饮油烟智能监测与监管一体化平台
riku
2026-03-03 015f3aa4e2818f8e0c16acd0515d9c8eb4026de8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { map, AMap, onMapMounted } from './index';
 
// 行政区划缓存
var districtPolygonMap = new Map();
// 当前显示的区县
var activeDistrict = undefined;
export default {
  // 绘制区县边界
  drawDistrict(districtName, isNew) {
    if(!districtName) return;
    onMapMounted(() => {
      if (!isNew && districtPolygonMap.has(districtName)) {
        const districtPolygon = districtPolygonMap.get(districtName);
        map.add(districtPolygon);
        map.setFitView(districtPolygon);
        activeDistrict = districtPolygon;
      } else {
        var district = new AMap.DistrictSearch({
          extensions: 'all', //返回行政区边界坐标等具体信息
          level: 'district' //设置查询行政区级别为区
        });
        district.search(districtName, function (status, result) {
          var bounds = result.districtList[0].boundaries; //获取边界信息
          if (bounds) {
            for (var i = 0; i < bounds.length; i++) {
              //生成行政区划 polygon
              const districtPolygon = new AMap.Polygon({
                map: map, //显示该覆盖物的地图对象
                strokeWeight: 1, //轮廓线宽度
                path: bounds[i], //多边形轮廓线的节点坐标数组
                fillOpacity: 0.4, //多边形填充透明度
                fillColor: '#0077ff',
                strokeColor: '#CC66CC' //线条颜色
              });
 
              districtPolygonMap.set(districtName, districtPolygon);
              activeDistrict = districtPolygon;
              map.setFitView(districtPolygon, true);
            }
          }
        });
      }
    });
  },
  removeDistrict() {
    onMapMounted(() => {
      if (activeDistrict) {
        map.remove(activeDistrict);
        activeDistrict = undefined;
      }
    })
  }
};