Your Name преди 2 години
родител
ревизия
c47016ac90
променени са 2 файла, в които са добавени 35 реда и са изтрити 18 реда
  1. 9
    0
      index.html
  2. 26
    18
      src/components/CustMap.vue

+ 9
- 0
index.html Целия файл

15
         securityJsCode: AMAP_SEC_CODE,
15
         securityJsCode: AMAP_SEC_CODE,
16
       };
16
       };
17
     </script>
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
     <!-- <script src="./vconsole.min.js"></script>
27
     <!-- <script src="./vconsole.min.js"></script>
19
     <script>
28
     <script>
20
       const vConsole = new VConsole();
29
       const vConsole = new VConsole();

+ 26
- 18
src/components/CustMap.vue Целия файл

34
       const { AMap, img } = nw;
34
       const { AMap, img } = nw;
35
       mapStyle.value = { width: `${img.width}px`, height: `${img.height}px` };
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
       const imageLayer = new AMap.ImageLayer({
52
       const imageLayer = new AMap.ImageLayer({
39
         url: props.image,
53
         url: props.image,
40
         bounds: new AMap.Bounds(
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
         zooms,
58
         zooms,
45
       });
59
       });
60
+      map.setLayers([imageLayer])
46
 
61
 
47
       // 背景层
62
       // 背景层
48
       const backCovers = [
63
       const backCovers = [
53
           new AMap.LngLat(360,90,true),
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
       const polygon = new AMap.Polygon({
78
       const polygon = new AMap.Polygon({
64
           pathL: backCovers,
79
           pathL: backCovers,
65
-          strokeColor: '#00eeff',
66
-          strokeWeight: 1,
80
+          strokeWeight: 0,
67
           fillColor: '#71B3ff',
81
           fillColor: '#71B3ff',
68
           fillOpacity: 0.5
82
           fillOpacity: 0.5
69
       });
83
       });
70
       polygon.setPath(backCovers);
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
       map.add(polygon);
85
       map.add(polygon);
86
+
82
       map.on('click',function(e){
87
       map.on('click',function(e){
83
         console.log('--------->', e)
88
         console.log('--------->', e)
84
       })
89
       })
104
   overflow: hidden;
109
   overflow: hidden;
105
 
110
 
106
   & > div {
111
   & > div {
112
+    position: absolute;
113
+    left: 0;
114
+    top: 0;
107
     width: 100%;
115
     width: 100%;
108
     height: 100%;
116
     height: 100%;
109
   }
117
   }