Your Name il y a 2 ans
Parent
révision
c47016ac90
2 fichiers modifiés avec 35 ajouts et 18 suppressions
  1. 9
    0
      index.html
  2. 26
    18
      src/components/CustMap.vue

+ 9
- 0
index.html Voir le fichier

@@ -15,6 +15,15 @@
15 15
         securityJsCode: AMAP_SEC_CODE,
16 16
       };
17 17
     </script>
18
+    <style type="text/css">
19
+      .amap-logo{
20
+      display: none;
21
+      opacity:0 !important;
22
+      }
23
+      .amap-copyright {
24
+          opacity:0;
25
+      }
26
+    </style>
18 27
     <!-- <script src="./vconsole.min.js"></script>
19 28
     <script>
20 29
       const vConsole = new VConsole();

+ 26
- 18
src/components/CustMap.vue Voir le fichier

@@ -34,15 +34,30 @@
34 34
       const { AMap, img } = nw;
35 35
       mapStyle.value = { width: `${img.width}px`, height: `${img.height}px` };
36 36
 
37
+      // 初始化地图      
38
+      const center = [118.798954,31.963517];
39
+      const map = new AMap.Map(elRef.value, {
40
+        center,
41
+        zooms,
42
+        zoom: 15,
43
+      });
44
+
45
+      // 获取左上角经纬度
46
+      // 正常情况坐标应该是 0,0 ; 但是实际 0,0 正好是地图的一半位置, 不清楚为啥
47
+      const lt = map.containerToLngLat(new AMap.Pixel(0, -img.height / 2));
48
+      // 获取右下角经纬度
49
+      const rb = map.containerToLngLat(new AMap.Pixel(img.width, img.height / 2));
50
+
37 51
       // 图片层
38 52
       const imageLayer = new AMap.ImageLayer({
39 53
         url: props.image,
40 54
         bounds: new AMap.Bounds(
41
-            [118.791036, 31.973077],
42
-            [118.806915, 31.953999]
55
+            [lt.lng, lt.lat],
56
+            [rb.lng, rb.lat]
43 57
         ),
44 58
         zooms,
45 59
       });
60
+      map.setLayers([imageLayer])
46 61
 
47 62
       // 背景层
48 63
       const backCovers = [
@@ -53,32 +68,22 @@
53 68
           new AMap.LngLat(360,90,true),
54 69
         ],
55 70
         [
56
-          [118.791036, 31.973077],
57
-          [118.806915, 31.973077],
58
-          [118.806915, 31.953999],
59
-          [118.791036, 31.953999],
71
+          [lt.lng, lt.lat],
72
+          [rb.lng, lt.lat],
73
+          [rb.lng, rb.lat],
74
+          [lt.lng, rb.lat],
60 75
         ]
61 76
       ]
62 77
 
63 78
       const polygon = new AMap.Polygon({
64 79
           pathL: backCovers,
65
-          strokeColor: '#00eeff',
66
-          strokeWeight: 1,
80
+          strokeWeight: 0,
67 81
           fillColor: '#71B3ff',
68 82
           fillOpacity: 0.5
69 83
       });
70 84
       polygon.setPath(backCovers);
71
-      
72
-      const center = [118.798954,31.963517];
73
-      const map = new AMap.Map(elRef.value, {
74
-        center,
75
-        zooms,
76
-        zoom: 15,
77
-        layers: [
78
-          imageLayer
79
-        ],
80
-      });
81 85
       map.add(polygon);
86
+
82 87
       map.on('click',function(e){
83 88
         console.log('--------->', e)
84 89
       })
@@ -104,6 +109,9 @@
104 109
   overflow: hidden;
105 110
 
106 111
   & > div {
112
+    position: absolute;
113
+    left: 0;
114
+    top: 0;
107 115
     width: 100%;
108 116
     height: 100%;
109 117
   }