Ver código fonte

地图提交

wang_xy 1 ano atrás
pai
commit
c5da1a968f
3 arquivos alterados com 133 adições e 3 exclusões
  1. 31 0
      libs/amap-wx.130.js
  2. 13 3
      manifest.json
  3. 89 0
      pages/mapindex/mapindex.vue

Diferenças do arquivo suprimidas por serem muito extensas
+ 31 - 0
libs/amap-wx.130.js


+ 13 - 3
manifest.json

@@ -17,7 +17,9 @@
             "delay" : 0
         },
         /* 模块配置 */
-        "modules" : {},
+        "modules" : {
+            "Maps" : {}
+        },
         /* 应用发布信息 */
         "distribute" : {
             /* android打包配置 */
@@ -43,14 +45,22 @@
             /* ios打包配置 */
             "ios" : {},
             /* SDK配置 */
-            "sdkConfigs" : {}
+            "sdkConfigs" : {
+                "maps" : {
+                    "amap" : {
+                        "name" : "amapGzUJuxzK",
+                        "appkey_ios" : "82398063f3d780bf71d840d0a43a296f",
+                        "appkey_android" : "82398063f3d780bf71d840d0a43a296f"
+                    }
+                }
+            }
         }
     },
     /* 快应用特有相关 */
     "quickapp" : {},
     /* 小程序特有相关 */
     "mp-weixin" : {
-        "appid" : "wxa537100824cd1a15",
+        "appid" : "wxf75b34dd1f737174",
         "setting" : {
             "urlCheck" : true,
             "minified" : true,

+ 89 - 0
pages/mapindex/mapindex.vue

@@ -0,0 +1,89 @@
+<template>
+  <view class="content">
+    <map id="map" class="map" :show-location="true" :latitude="latitude" :longitude="longitude"></map>
+  </view>
+</template>
+
+<script>
+  const img = '/static/logo.png';
+
+  export default {
+    data() {
+      return {
+        latitude: 43.780458,
+        longitude: 125.384426,
+      }
+    },
+    onReady() {
+      this._mapContext = uni.createMapContext("map", this);
+
+      // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
+      this._mapContext.initMarkerCluster({
+        enableDefaultStyle: false,
+        zoomOnClick: true,
+        gridSize: 60,
+        complete(res) {
+          console.log('initMarkerCluster', res)
+        }
+      });
+
+      this._mapContext.on("markerClusterCreate", (e) => {
+        console.log("markerClusterCreate", e);
+      });
+
+      this.addMarkers();
+    },
+    methods: {
+      addMarkers() {
+        const positions = [
+          {
+            latitude: 43.780458,
+            longitude: 125.384426,
+          }
+        ]
+
+        const markers = []
+
+        positions.forEach((p, i) => {
+          console.log(i)
+          markers.push(
+            Object.assign({},{
+              id: i + 1,
+              iconPath: img,
+              width: 50,
+              height: 100,
+              joinCluster: true, // 指定了该参数才会参与聚合
+              label: {
+                  width: 50,
+                  height: 30,
+                  borderWidth: 1,
+                  borderRadius: 10,
+                  bgColor: '#ffffff',
+                  content: `定位点`
+              }
+            },p)
+          )
+        })
+        this._mapContext.addMarkers({
+            markers,
+            clear: false,
+            complete(res) {
+              console.log('addMarkers', res)
+            }
+        })
+      }
+    }
+  }
+</script>
+
+<style>
+  .content {
+    flex: 1;
+  }
+
+  .map {
+	  width: 20rem;
+	  height: 40rem;
+    flex: 1;
+  }
+</style>