Browse Source

feat(dashboard): map boundary

Casper Dai 2 years ago
parent
commit
27030b1cca
4 changed files with 96 additions and 84 deletions
  1. 1 0
      .env
  2. 2 0
      .env.fujian
  3. 92 84
      src/views/dashboard/v1/Map.vue
  4. 1 0
      src/views/dashboard/v1/config.js

+ 1 - 0
.env

@@ -57,6 +57,7 @@ VUE_APP_SALT = '42857cfddb33f3fddb27fff9773683f3'
 # VUE_APP_GAODE_MAP_JSCODE = 'e7b3c29a5112657edcc688a3c589bd15'
 VUE_APP_GAODE_MAP_KEY = 'd450b58ff3a620e5eaf477e29c7ea94c'
 VUE_APP_GAODE_MAP_JSCODE = '92a333ddc89042aee3e3459162f0abe6'
+VUE_APP_GAODE_MAP_RANGE = '中国'
 
 VUE_APP_AD_ORDER_QR = 'https://msr.inspur.com'
 

+ 2 - 0
.env.fujian

@@ -10,3 +10,5 @@ VUE_APP_NAME = '万福千屏户外安播云平台'
 __TAKEOVER__ = 'disabled'
 # 小程序
 __WECHAT__ = 'disabled'
+
+VUE_APP_GAODE_MAP_RANGE = '福建省'

+ 92 - 84
src/views/dashboard/v1/Map.vue

@@ -32,7 +32,6 @@
 
 <script>
 import Box from './Box'
-import { Bounds } from './config'
 import DeviceStatus from './DeviceStatus'
 import AlarmInfo from './AlarmInfo'
 import AMapLoader from '@amap/amap-jsapi-loader'
@@ -54,10 +53,6 @@ export default {
     statusData: {
       type: Array,
       required: true
-    },
-    city: {
-      type: String,
-      default: '深圳市'
     }
   },
   data () {
@@ -133,104 +128,117 @@ export default {
         辅助转化函数 str.split(';').map(i=>i.split(',').map(i=>Number))
         后续 可以  new AMap.Polyline画轮廓  setFiew 定位轮廓
         */
+        const options = {
+          subdistrict: 1,
+          extensions: 'all',
+          level: 'province'
+        }
+        const district = new AMap.DistrictSearch(options)
         const outer = [
           new AMap.LngLat(-360, 90, true),
           new AMap.LngLat(-360, -90, true),
           new AMap.LngLat(360, -90, true),
           new AMap.LngLat(360, 90, true)
         ]
-        const bounds = [Bounds.inspur]
-        const pathArray = [outer, Bounds.inspur] // bounds外部
-
-        // 实例化地图
-        const map = new AMap.Map(this.$refs.map, {
+        district.search(process.env.VUE_APP_GAODE_MAP_RANGE, (status, result) => {
+          let bounds
+          if (status === 'complete') {
+            bounds = result.districtList[0]['boundaries']
+          } else {
+            bounds = []
+            this.$message.error('获取边界信息失败')
+          }
+          const pathArray = [outer, ...bounds] // bounds外部
+          // 实例化地图
+          const map = new AMap.Map(this.$refs.map, {
           // expandZoomRange: true, // 开启显示范围设置
           // zooms: [7, 20], // 最小显示级别为7,最大显示级别为20
           // viewMode: '3D', // 这里特别注意,设置为3D则其它地区不显示
-          zoomEnable: true, // 是否可以缩放地图
-          // resizeEnable: true
-          mapStyle: 'amap://styles/darkblue'
-        })
-        this.map = map
+            zoomEnable: true, // 是否可以缩放地图
+            // resizeEnable: true
+            mapStyle: 'amap://styles/darkblue'
+          })
+          this.map = map
 
-        this.marks = []
-        this.$deviceMap = {} // 当前地图 有标记点的设备  (可能切换部门变少)
-        this.$alldeviceMap = {} // 警告是全部设备的  可能因为切换部门 地图上没有警告对应设备的标记点无法定位 所以需要一个全部的坐标map
+          this.marks = []
+          this.$deviceMap = {} // 当前地图 有标记点的设备  (可能切换部门变少)
+          this.$alldeviceMap = {} // 警告是全部设备的  可能因为切换部门 地图上没有警告对应设备的标记点无法定位 所以需要一个全部的坐标map
 
-        this.$onlineIcon = new AMap.Icon({
-          image: onlineIcon
-        })
-        this.$offlineIcon = new AMap.Icon({
-          image: offlineIcon
-        })
+          this.$onlineIcon = new AMap.Icon({
+            image: onlineIcon
+          })
+          this.$offlineIcon = new AMap.Icon({
+            image: offlineIcon
+          })
 
-        this.deviceList.forEach(
-          ({ id, longitude, latitude, name, onlineStatus, address, mac }) => {
-            if (longitude && latitude) {
-              const markObj = new AMap.Marker({
-                position: [Number(longitude), Number(latitude)],
-                title: name,
-                content: this.getMarkerContent(
+          this.deviceList.forEach(
+            ({ id, longitude, latitude, name, onlineStatus, address, mac }) => {
+              if (longitude && latitude) {
+                const markObj = new AMap.Marker({
+                  position: [Number(longitude), Number(latitude)],
+                  title: name,
+                  content: this.getMarkerContent(
+                    onlineStatus,
+                    this.getMarkActive(id)
+                  )
+                })
+                this.marks.push(markObj)
+                this.$deviceMap[id] = {
                   onlineStatus,
-                  this.getMarkActive(id)
-                )
-              })
-              this.marks.push(markObj)
-              this.$deviceMap[id] = {
-                onlineStatus,
-                markObj,
-                address,
-                mac
-              }
-              this.$alldeviceMap[id] = {
-                onlineStatus,
-                markObj,
-                address,
-                mac
-              }
-            } else {
+                  markObj,
+                  address,
+                  mac
+                }
+                this.$alldeviceMap[id] = {
+                  onlineStatus,
+                  markObj,
+                  address,
+                  mac
+                }
+              } else {
               /* 没有坐标,但是全局提醒警告信息只有设备id,
               需要全部设备MAP查询 添加一些设备信息展示*/
-              this.$alldeviceMap[id] = {
-                onlineStatus,
-                address,
-                mac
+                this.$alldeviceMap[id] = {
+                  onlineStatus,
+                  address,
+                  mac
+                }
               }
             }
-          }
-        )
-        map.add(this.marks)
+          )
+          map.add(this.marks)
 
-        const polygon = new AMap.Polygon({
-          pathL: pathArray,
-          strokeColor: 'transparent', // 边框线颜色
-          strokeWeight: 0,
-          fillColor: '#1D274B', // 遮罩图层颜色
-          fillOpacity: 0.6
-        })
+          const polygon = new AMap.Polygon({
+            pathL: pathArray,
+            strokeColor: 'transparent', // 边框线颜色
+            strokeWeight: 0,
+            fillColor: '#1D274B', // 遮罩图层颜色
+            fillOpacity: 0.6
+          })
 
-        polygon.setPath(pathArray)
-        map.add(polygon)
-        // /////////////
-        const polylines = []
-        // 添加描边
-        for (let i = 0; i < bounds.length; i += 1) {
-          polylines.push(
-            new AMap.Polyline({
-              path: bounds[i],
-              strokeColor: 'red',
-              strokeWeight: 4,
-              map
-            })
-          )
-        }
-        this.polylines = polylines
-        this.resetView()
-        map.on('click', () => {
-          map.zoomIn()
-        })
-        polygon.on('click', () => {
-          map.zoomIn()
+          polygon.setPath(pathArray)
+          map.add(polygon)
+          // /////////////
+          const polylines = []
+          // 添加描边
+          for (let i = 0; i < bounds.length; i += 1) {
+            polylines.push(
+              new AMap.Polyline({
+                path: bounds[i],
+                strokeColor: 'red',
+                strokeWeight: 4,
+                map
+              })
+            )
+          }
+          this.polylines = polylines
+          this.resetView()
+          map.on('click', () => {
+            map.zoomIn()
+          })
+          polygon.on('click', () => {
+            map.zoomIn()
+          })
         })
       })
     },

+ 1 - 0
src/views/dashboard/v1/config.js

@@ -51,6 +51,7 @@ export const ProgramTop = {
   timer: 30 * 1000
 }
 
+// 济南园区
 export const Bounds = {
   inspur: [
     [117.126789, 36.660564],