Browse Source

修改地图

wangningfei 2 years ago
parent
commit
90610db67d

+ 12 - 6
vue-admin-template-master/public/index.html

@@ -1,18 +1,24 @@
 <!DOCTYPE html>
 <html>
   <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
-    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
+    <meta charset="utf-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+    <meta
+      name="viewport"
+      content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
+    />
+    <link rel="icon" href="<%= BASE_URL %>favicon.ico" />
     <title><%= webpackConfig.name %></title>
   </head>
   <body>
     <noscript>
-      <strong>We're sorry but <%= webpackConfig.name %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
+      <strong
+        >We're sorry but <%= webpackConfig.name %> doesn't work properly without
+        JavaScript enabled. Please enable it to continue.</strong
+      >
     </noscript>
     <div id="app"></div>
     <!-- built files will be auto injected -->
-    <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=36IBZ-VI53O-FJHW2-SV2NP-USSAE-GFBUS"></script>
+    <script src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&callback=init"></script>
   </body>
 </html>

+ 48 - 48
vue-admin-template-master/src/permission.js

@@ -15,61 +15,61 @@ router.beforeEach(async (to, from, next) => {
 
   // set page title
   document.title = getPageTitle(to.meta.title);
-
+  next();
   // determine whether the user has logged in
   const hasToken = getToken();
   console.log(hasToken);
 
-  if (!!hasToken && typeof hasToken == "string") {
-    if (to.path === "/login") {
-      // if is logged in, redirect to the home page
-      next({ path: "/" });
-      NProgress.done();
-    } else {
-      const hasRoles = store.getters.roles && store.getters.roles.length > 0;
-      if (hasRoles) {
-        next();
-      } else {
-        const roles = await store.dispatch("user/setroles");
-        store.dispatch("GenerateRoutes", { roles }).then(() => {
-          // 生成可访问的路由表
-          router.options.routes = store.getters.addRouters;
-          router.addRoutes(store.getters.addRouters); // 动态添加可访问路由表
-          next({ ...to, replace: true }); // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
-        });
-      }
+  // if (!!hasToken && typeof hasToken == "string") {
+  //   if (to.path === "/login") {
+  //     // if is logged in, redirect to the home page
+  //     next({ path: "/" });
+  //     NProgress.done();
+  //   } else {
+  //     const hasRoles = store.getters.roles && store.getters.roles.length > 0;
+  //     if (hasRoles) {
+  //       next();
+  //     } else {
+  //       const roles = await store.dispatch("user/setroles");
+  //       store.dispatch("GenerateRoutes", { roles }).then(() => {
+  //         // 生成可访问的路由表
+  //         router.options.routes = store.getters.addRouters;
+  //         router.addRoutes(store.getters.addRouters); // 动态添加可访问路由表
+  //         next({ ...to, replace: true }); // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
+  //       });
+  //     }
 
-      // next()
-      // const hasGetUserInfo = store.getters.name
-      // if (hasGetUserInfo) {
-      //   next()
-      // } else {
-      //   try {
-      //     // get user info
-      //     await store.dispatch('user/getInfo')
+  //     // next()
+  //     // const hasGetUserInfo = store.getters.name
+  //     // if (hasGetUserInfo) {
+  //     //   next()
+  //     // } else {
+  //     //   try {
+  //     //     // get user info
+  //     //     await store.dispatch('user/getInfo')
 
-      //     next()
-      //   } catch (error) {
-      //     // remove token and go to login page to re-login
-      //     await store.dispatch('user/resetToken')
-      //     Message.error(error || 'Has Error')
-      //     next(`/login?redirect=${to.path}`)
-      //     NProgress.done()
-      //   }
-      // }
-    }
-  } else {
-    /* has no token*/
+  //     //     next()
+  //     //   } catch (error) {
+  //     //     // remove token and go to login page to re-login
+  //     //     await store.dispatch('user/resetToken')
+  //     //     Message.error(error || 'Has Error')
+  //     //     next(`/login?redirect=${to.path}`)
+  //     //     NProgress.done()
+  //     //   }
+  //     // }
+  //   }
+  // } else {
+  //   /* has no token*/
 
-    if (whiteList.indexOf(to.path) !== -1) {
-      // in the free login whitelist, go directly
-      next();
-    } else {
-      // other pages that do not have permission to access are redirected to the login page.
-      next(`/login?redirect=${to.path}`);
-      NProgress.done();
-    }
-  }
+  //   if (whiteList.indexOf(to.path) !== -1) {
+  //     // in the free login whitelist, go directly
+  //     next();
+  //   } else {
+  //     // other pages that do not have permission to access are redirected to the login page.
+  //     next(`/login?redirect=${to.path}`);
+  //     NProgress.done();
+  //   }
+  // }
 });
 
 router.afterEach(() => {

+ 32 - 100
vue-admin-template-master/src/views/shapmap/mtmap/index.vue

@@ -1,30 +1,11 @@
 <template>
   <div class="content">
-    <el-row class="search-row">
-      <el-col :span="5">
-        <div class="grid-content bg-purple">
-          <el-input
-            id="keyword"
-            v-model="searchValue"
-            placeholder="请输入地址"
-          ></el-input>
-        </div>
-      </el-col>
-
-      <el-col :span="12">
-        <div class="grid-content bg-purple-light">
-          <el-button type="primary" @click="searchKeyword">搜索</el-button>
-        </div>
-      </el-col>
-    </el-row>
-    <div id="container">门店地图</div>
+    <div id="container"></div>
   </div>
 </template>
 
 <script>
 import { getshopmt } from "@/api/shop.js";
-
-import shop_icon from "@/assets/img/shop_icon.png";
 var searchService,
   markers = [],
   that;
@@ -40,97 +21,48 @@ export default {
   },
   methods: {
     async init() {
-      //步骤:定义map变量 调用 qq.maps.Map() 构造函数   获取地图显示容器
+      //步骤:定义map变量 调用 TMap.Map() 构造函数   获取地图显示容器
       //设置地图中心点
-      var myLatlng = new qq.maps.LatLng(31.169083, 121.432358);
+      var myLatlng = new TMap.LatLng(31.169083, 121.432358);
       //定义工厂模式函数
       var myOptions = {
         zoom: 12, //设置地图缩放级别
-        center: myLatlng, //设置中心点样式
-        mapTypeId: qq.maps.MapTypeId.ROADMAP //设置地图样式详情参见MapType
+        center: myLatlng //设置中心点样式
+        // mapTypeId: TMap.MapTypeId.ROADMAP //设置地图样式详情参见MapType
       };
       //获取dom元素添加地图信息
-      var map = new qq.maps.Map(
-        document.getElementById("container"),
-        myOptions
-      );
-      //   new qq.maps.MarkerImage(shop_icon);
+      var map = new TMap.Map(document.getElementById("container"), myOptions);
+      //   new TMap.MarkerImage(shop_icon);
       let res = await getshopmt();
-      console.log(res);
-      res.forEach(v => {
-        let marker = new qq.maps.Marker({
-          position: new qq.maps.LatLng(v.lat - 0, v.lng - 0),
-          map: map
-        });
-        marker.setIcon(
-          new qq.maps.MarkerImage(
-            shop_icon
-            // new qq.maps.Size(28, 34),
-            // new qq.maps.ScaleSize(28, 34)
-          )
-        );
-        //获取标记的点击事件
-        let info = new qq.maps.InfoWindow({
-          map: map
-        });
-        qq.maps.event.addListener(marker, "click", function() {
-          info.open();
-          info.setContent(
-            `<div style="text-align:center;white-space:nowrap;margin:10px;">${v.name}(${v.mtid})</div>`
-          );
-          info.setPosition(new qq.maps.LatLng(v.lat - 0, v.lng - 0));
-        });
-      });
 
-      var latlngBounds = new qq.maps.LatLngBounds();
-      //设置Poi检索服务,用于本地检索、周边检索
-      searchService = new qq.maps.SearchService({
-        //设置搜索范围为北京
-        location: "上海",
-        //设置搜索页码为1
-        pageIndex: 1,
-        //设置每页的结果数为5
-        pageCapacity: 5,
-        //设置展现查询结构到infoDIV上
-        panel: document.getElementById("infoDiv"),
-        //设置动扩大检索区域。默认值true,会自动检索指定城市以外区域。
-        autoExtend: true,
-        //检索成功的回调函数
-        complete: function(results) {
-          //设置回调函数参数
-          var pois = results.detail.pois;
-          for (var i = 0, l = pois.length; i < l; i++) {
-            var poi = pois[i];
-            //扩展边界范围,用来包含搜索到的Poi点
-            latlngBounds.extend(poi.latLng);
-            var marker = new qq.maps.Marker({
-              map: map,
-              position: poi.latLng
-            });
+      //初始化marker
 
-            marker.setTitle(i + 1);
+      let geometries = [];
+      res.forEach(v => {
+        if (v.lat) {
+          geometries.push({
+            id: "marker1",
+            styleId: "marker",
+            position: new TMap.LatLng(v.lat, v.lng),
+            properties: {
+              title: v.name
+            }
+          });
+        }
+      });
 
-            markers.push(marker);
-          }
-          //调整地图视野
-          map.fitBounds(latlngBounds);
+      new TMap.MultiMarker({
+        id: "marker-layer",
+        map: map,
+        styles: {
+          marker: new TMap.MarkerStyle({
+            width: 25,
+            height: 35,
+            anchor: { x: 16, y: 32 }
+          })
         },
-        //若服务请求失败,则运行以下函数
-        error: function() {
-          that.$message.error("请输入正确地址!");
-        }
+        geometries
       });
-    },
-    searchKeyword() {
-      this.clearOverlays(markers);
-      //根据输入的关键字在搜索范围内检索
-      searchService.search(this.searchValue);
-    },
-    clearOverlays(overlays) {
-      var overlay;
-      while ((overlay = overlays.pop())) {
-        overlay.setMap(null);
-      }
     }
   }
 };
@@ -142,7 +74,7 @@ export default {
 }
 #container {
   width: 100%;
-  height: 85vh;
+  height: 90vh;
 }
 .search-row {
   padding-bottom: 20px;

+ 29 - 114
vue-admin-template-master/src/views/shapmap/mtmarker/index.vue

@@ -1,25 +1,6 @@
 <template>
   <div class="content">
-    <el-row class="search-row">
-      <el-col :span="5">
-        <div class="grid-content bg-purple">
-          <el-input
-            id="keyword"
-            v-model="searchValue"
-            placeholder="请输入地址"
-          ></el-input>
-        </div>
-      </el-col>
-
-      <el-col :span="12">
-        <div class="grid-content bg-purple-light">
-          <el-button type="primary" @click="searchKeyword">搜索</el-button>
-        </div>
-      </el-col>
-    </el-row>
-
-    <div id="container">门店覆盖区域</div>
-    <!-- <div style="width: 500px; height: 180px" id="infoDiv"></div> -->
+    <div id="container"></div>
   </div>
 </template>
 
@@ -40,97 +21,42 @@ export default {
   },
   methods: {
     async init() {
-      var latlngBounds = new qq.maps.LatLngBounds();
-      //设置Poi检索服务,用于本地检索、周边检索
-      searchService = new qq.maps.SearchService({
-        //设置搜索范围为北京
-        location: "上海",
-        //设置搜索页码为1
-        pageIndex: 1,
-        //设置每页的结果数为5
-        pageCapacity: 5,
-        //设置展现查询结构到infoDIV上
-        panel: document.getElementById("infoDiv"),
-        //设置动扩大检索区域。默认值true,会自动检索指定城市以外区域。
-        autoExtend: true,
-        //检索成功的回调函数
-        complete: function(results) {
-          console.log(results);
-          //设置回调函数参数
-          var pois = results.detail.pois;
-          for (var i = 0, l = pois.length; i < l; i++) {
-            var poi = pois[i];
-            //扩展边界范围,用来包含搜索到的Poi点
-            latlngBounds.extend(poi.latLng);
-            var marker = new qq.maps.Marker({
-              map: map,
-              position: poi.latLng
-            });
-
-            marker.setTitle(i + 1);
-
-            markers.push(marker);
-          }
-          //调整地图视野
-          map.fitBounds(latlngBounds);
-        },
-        //若服务请求失败,则运行以下函数
-        error: function() {
-          that.$message.error("请输入正确地址!");
-        }
-      });
-      //步骤:定义map变量 调用 qq.maps.Map() 构造函数   获取地图显示容器
       //设置地图中心点
-      var myLatlng = new qq.maps.LatLng(31.169083, 121.432358);
+      var myLatlng = new TMap.LatLng(31.169083, 121.432358);
       //定义工厂模式函数
       var myOptions = {
         zoom: 12, //设置地图缩放级别
-        center: myLatlng, //设置中心点样式
-        mapTypeId: qq.maps.MapTypeId.ROADMAP //设置地图样式详情参见MapType
+        center: myLatlng //设置中心点样式
+        // mapTypeId: TMap.MapTypeId.ROADMAP //设置地图样式详情参见MapType
       };
       //获取dom元素添加地图信息
-      var map = new qq.maps.Map(
-        document.getElementById("container"),
-        myOptions
-      );
-      //   new qq.maps.MarkerImage(shop_icon);
+      var map = new TMap.Map(document.getElementById("container"), myOptions);
+      //   new TMap.MarkerImage(shop_icon);
       let res = await getshopmt();
-
+      let geometries = [];
       res.forEach(v => {
-        new qq.maps.Circle({
-          //圆形的中心点坐标。
-          center: new qq.maps.LatLng(v.lat - 0, v.lng - 0),
-          //圆形是否可点击。
-          clickable: true,
-
-          //鼠标在圆形内的光标样式。
-          cursor: "pointer",
-
-          //圆形的填充色,可通过Color对象的alpha属性设置透明度。
-          //fillColor: "#00f",
-          fillColor: new qq.maps.Color(0, 15, 255, 0.3),
-
-          //要显示圆形的地图。
-          map: map,
-
-          //圆形的半径。
-          radius: 3000,
-
-          //圆形的边框颜色,可通过Color对象的alpha属性设置透明度。
-          strokeColor: "rgba(0,0,0,0)",
-
-          //圆形的边框样式。实线是solid,虚线是dash。
-          // strokeDashStyle: "solid",
-
-          //圆形的边框线宽。
-          strokeWeight: 1,
-
-          //圆形是否可见。
-          visible: true,
+        if (v.lat) {
+          geometries.push({
+            styleId: "circle",
+            center: new TMap.LatLng(v.lat, v.lng),
+            // position: new TMap.LatLng(v.lat, v.lng),
+            radius: 3000
+          });
+        }
+      });
 
-          //圆形的zIndex值。
-          zIndex: 1000
-        });
+      var circle = new TMap.MultiCircle({
+        map,
+        styles: {
+          // 设置圆形样式
+          circle: new TMap.CircleStyle({
+            color: "rgba(41,91,255,0.16)",
+            showBorder: true,
+            borderColor: "rgba(41,91,255,1)",
+            borderWidth: 1
+          })
+        },
+        geometries
       });
     },
     getData() {
@@ -143,17 +69,6 @@ export default {
             resolve(myJson);
           });
       });
-    },
-    searchKeyword() {
-      this.clearOverlays(markers);
-      //根据输入的关键字在搜索范围内检索
-      searchService.search(this.searchValue);
-    },
-    clearOverlays(overlays) {
-      var overlay;
-      while ((overlay = overlays.pop())) {
-        overlay.setMap(null);
-      }
     }
   }
 };
@@ -165,7 +80,7 @@ export default {
 }
 #container {
   width: 100%;
-  height: 85vh;
+  height: 90vh;
 }
 .search-row {
   padding-bottom: 20px;