Quellcode durchsuchen

将首页的地图换为高德地图

jishenghua vor 7 Monaten
Ursprung
Commit
46b98a97d0
3 geänderte Dateien mit 119 neuen und 123 gelöschten Zeilen
  1. 1 0
      gyj-iot-web/index.html
  2. 27 0
      gyj-iot-web/src/utils/mapGaode.js
  3. 91 123
      gyj-iot-web/src/views/index.vue

+ 1 - 0
gyj-iot-web/index.html

@@ -10,6 +10,7 @@
   <script src="/js/jessibuca-pro/jessibuca-pro.js"></script>
   <script type="text/javascript" src="/js/ZLMRTCClient.js"></script>
   <script type="text/javascript" src="/js/EasyWasmPlayer.js"></script>
+  <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=2cd74056ead5ced85589e398b621c955"></script>
   <script>var _hmt = _hmt || [];(function() {var hm = document.createElement("script");hm.src = "https://hm.baidu.com/hm.js?2742bc99fd6c8a9569359b4d583cf507";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(hm, s);   })();</script>
   <title>管伊佳物联</title>
   <meta name="description" content="管伊佳物联-让连接更稳定,简单易用,更适合中小企业和个人学习使用。 适用于智能家居、智慧办公、智慧社区、工业控制、农业监测、水利监测等。" />

+ 27 - 0
gyj-iot-web/src/utils/mapGaode.js

@@ -0,0 +1,27 @@
+export function loadBMap() {
+    return new Promise(function(resolve, reject) {
+        // if (typeof BMap !== 'undefined') {
+        //     resolve(BMap)
+        //     return true
+        // }
+        // window.onBMapCallback = function() {
+        //     resolve(BMap)
+        // }
+        // // 使用https协议需要添加一下meta标签
+        // var protocolStr = document.location.protocol;
+        // if(protocolStr == "https:")
+        // {
+        //     let meta = document.createElement('meta')
+        //     meta.httpEquiv = 'Content-Security-Policy'
+        //     meta.content ='upgrade-insecure-requests'
+        //     meta.onerror = reject
+        //     document.head.appendChild(meta)
+        // }
+        // 引入高德地图
+        let script = document.createElement('script')
+        script.type = 'text/javascript'
+        script.src = 'https://webapi.amap.com/maps?v=2.0&key=2cd74056ead5ced85589e398b621c955'
+        script.onerror = reject
+        document.head.appendChild(script)
+    })
+}

+ 91 - 123
gyj-iot-web/src/views/index.vue

@@ -97,7 +97,7 @@
 
       <el-col :xs="24" :sm="24" :md="24" :lg="14" :xl="14">
         <div style="overflow: hidden; border: 1px solid #ccc">
-          <div ref="map" style="height: 650px"></div>
+          <div id="mapGaode" style="height: 650px"></div>
         </div>
       </el-col>
     </el-row>
@@ -157,10 +157,6 @@
 import { getDeviceStatistic } from '@/api/iot/device';
 import { listNotice, getNotice } from '@/api/system/notice';
 import CountTo from '@/components/CountTo/CountTo';
-import { loadBMap } from '@/utils/map.js';
-//安装的是echarts完整包,里面包含百度地图扩展,路径为 echarts/extension/bmap/bmap.js,将其引入
-//ECharts的百度地图扩展,可以在百度地图上展现点图,线图,热力图等可视化
-import 'echarts/extension/bmap/bmap';
 import { getServer } from '@/api/monitor/server';
 import { listAllDeviceShort } from '@/api/iot/device';
 import * as echarts from 'echarts';
@@ -235,7 +231,6 @@ function flushIframe() {
 /** 查询设备统计信息 */
 function searchDeviceStatistic() {
   getDeviceStatistic().then((response) => {
-    console.log(response.data)
     deviceStatistic.value = response.data;
   });
 }
@@ -279,9 +274,7 @@ function getAllDevice() {
 /**加载地图*/
 function loadMap() {
   proxy.$nextTick(() => {
-    loadBMap().then(() => {
-      getmap();
-    });
+    getmap1();
   });
 }
 /** 查询服务器信息 */
@@ -432,120 +425,6 @@ function getmap() {
       zoom: 5,
       roam: true,
       mapStyle: {
-        // styleJson: [
-        //   {
-        //     featureType: 'water',
-        //     elementType: 'all',
-        //     stylers: {
-        //       color: '#a0cfff',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'land',
-        //     elementType: 'all',
-        //     stylers: {
-        //       color: '#fafafa', // #fffff8 淡黄色
-        //     },
-        //   },
-        //   {
-        //     featureType: 'railway',
-        //     elementType: 'all',
-        //     stylers: {
-        //       visibility: 'off',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'highway',
-        //     elementType: 'all',
-        //     stylers: {
-        //       color: '#fdfdfd',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'highway',
-        //     elementType: 'labels',
-        //     stylers: {
-        //       visibility: 'off',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'arterial',
-        //     elementType: 'geometry',
-        //     stylers: {
-        //       color: '#fefefe',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'arterial',
-        //     elementType: 'geometry.fill',
-        //     stylers: {
-        //       color: '#fefefe',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'poi',
-        //     elementType: 'all',
-        //     stylers: {
-        //       visibility: 'off',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'green',
-        //     elementType: 'all',
-        //     stylers: {
-        //       visibility: 'off',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'subway',
-        //     elementType: 'all',
-        //     stylers: {
-        //       visibility: 'off',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'manmade',
-        //     elementType: 'all',
-        //     stylers: {
-        //       color: '#d1d1d1',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'local',
-        //     elementType: 'all',
-        //     stylers: {
-        //       color: '#d1d1d1',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'arterial',
-        //     elementType: 'labels',
-        //     stylers: {
-        //       visibility: 'off',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'boundary',
-        //     elementType: 'all',
-        //     stylers: {
-        //       color: '#999999',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'building',
-        //     elementType: 'all',
-        //     stylers: {
-        //       color: '#d1d1d1',
-        //     },
-        //   },
-        //   {
-        //     featureType: 'label',
-        //     elementType: 'labels.text.fill',
-        //     stylers: {
-        //       color: '#999999',
-        //     },
-        //   },
-        // ],
       },
     },
     series: [
@@ -602,6 +481,95 @@ function getmap() {
   };
   option && myChart.setOption(option);
 }
+
+/** 高德地图 */
+function getmap1() {
+  // 创建地图实例
+  let map = new AMap.Map('mapGaode', {
+    zoom: 4,
+    center: [ 108, 34]
+  })
+  for(var i=0;i<deviceList.value.length;i+=1) {
+    let currentInfo = deviceList.value[i]
+    if (currentInfo.longitude && currentInfo.latitude) {
+      let fillStr = ''
+      let htmlStr = '<div style="padding:5px;line-height:28px;">';
+      htmlStr += "设备名称: <span style='color:#409EFF'>" + currentInfo.deviceName + '</span><br />';
+      htmlStr += '设备编号: ' + currentInfo.serialNumber + '<br />';
+      htmlStr += '设备状态: ';
+      if (currentInfo.status == 1) {
+        fillStr = '%23E6A23C'
+        htmlStr += "<span style='color:#E6A23C'>未激活</span>" + '<br />';
+      } else if (currentInfo.status == 2) {
+        fillStr = '%23F56C6C'
+        htmlStr += "<span style='color:#F56C6C'>禁用</span>" + '<br />';
+      } else if (currentInfo.status == 3) {
+        fillStr = '%2367C23A'
+        htmlStr += "<span style='color:#67C23A'>在线</span>" + '<br />';
+      } else if (currentInfo.status == 4) {
+        fillStr = '%23909399'
+        htmlStr += "<span style='color:#909399'>离线</span>" + '<br />';
+      }
+      if (currentInfo.isShadow == 1) {
+        htmlStr += '设备影子: ' + "<span style='color:#67C23A'>启用</span>" + '<br />';
+      } else {
+        htmlStr += '设备影子: ' + "<span style='color:#909399'>未启用</span>" + '<br />';
+      }
+      htmlStr += '产品名称: ' + currentInfo.productName + '<br />';
+      htmlStr += '固件版本: Version ' + currentInfo.firmwareVersion + '<br />';
+      htmlStr += '激活时间: ' + currentInfo.activeTime + '<br />';
+      htmlStr += '定位方式: ';
+      if (currentInfo.locationWay == 1) {
+        htmlStr += '自动定位' + '<br />';
+      } else if (currentInfo.locationWay == 2) {
+        htmlStr += '设备定位' + '<br />';
+      } else if (currentInfo.locationWay == 3) {
+        htmlStr += '自定义位置' + '<br />';
+      } else {
+        htmlStr += '未知' + '<br />';
+      }
+      let networkAddress = currentInfo.networkAddress || '未知';
+      htmlStr += '所在地址: ' + networkAddress + '<br />';
+      htmlStr += '</div>';
+
+      // 创建标记点
+      let marker = new AMap.Marker({
+        position: new AMap.LngLat(currentInfo.longitude, currentInfo.latitude),
+        // 自定义图标
+        icon: new AMap.Icon({
+          image: 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><circle cx="10" cy="10" r="8" fill="' + fillStr + '" fill-opacity="0.5" /></svg>',
+          size: new AMap.Size(15, 15), // 图标大小
+          imageSize: new AMap.Size(15, 15) // 实际显示大小
+        }),
+        map: map
+      })
+
+      // 创建信息窗口(Tooltip)
+      let infoWindow = new AMap.InfoWindow({
+        content: htmlStr,
+        offset: new AMap.Pixel(8, 0)
+      })
+
+      // 添加事件监听
+      marker.on('mouseover', () => infoWindow.open(map, marker.getPosition()))
+      marker.on('mouseout', () => infoWindow.close())
+
+      // 点击事件
+      let deviceId = deviceList.value[i].deviceId
+      marker.on('click', () => {
+        if (deviceId) {
+          proxy.$router.push({
+            path: '/iot/device-edit',
+            query: {
+              t: Date.now(),
+              deviceId: deviceId,
+            },
+          });
+        }
+      })
+    }
+  }
+}
 function drawPieCpu() {
   // 基于准备好的dom,初始化echarts实例
   const myChart = echarts.init(pieCpu.value);