1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| <template>
| <div id="container"></div>
| </template>
| <script>
| import AMapLoader from "@amap/amap-jsapi-loader";
| export default {
| data() {
| return {
| map: null,
| };
| },
| created() {
| debugger;
| if (!this.point) {
| this.point = { x: "119.27179890", y: "28.59027084" };
| }
| if (!this.zoom) {
| this.zoom = 15;
| }
| },
| mounted() {
| AMapLoader.load({
| key: "091ade377d4db40f68cc78cb9658ce8d", // 申请好的Web端开发者Key,首次调用 load 时必填
| version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
| plugins: [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
| })
| .then((AMap) => {
| this.map = new AMap.Map("container");
| this.map.setZoomAndCenter(this.zoom, [this.point.x, this.point.y]);
| if (this.mark) {
| // 创建一个 Marker 实例:
| var marker = new AMap.Marker({
| position: new AMap.LngLat(this.point.x, this.point.y), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
| title: this.mark.title,
| });
|
| // 将创建的点标记添加到已有的地图实例:
| this.map.add(marker);
| }
| })
| .catch((e) => {
| console.log(e);
| });
| },
|
| props: ["point", "zoom", "mark"],
| };
| </script>
| <style lang="scss" scoped>
| #container {
| width: 100%;
| height: 100%;
| }
| </style>
|
|