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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
| <template>
| <div id="container"></div>
| </template>
| <script>
| import AMapLoader from "@amap/amap-jsapi-loader";
| export default {
| data() {
| return {
| map: null,
| _point: { x: "119.27179890", y: "28.59027084" },
| _zoom: 15,
| };
| },
| created() {
|
| // if (this.point) {
| // this._point = this.point;
| // }
| // if (this.zoom) {
| // this._zoom = this.zoom;
| // }
| },
| methods: {
| locationMap() {
| const that = this;
|
|
| // console.log("_zoom---", that.zoom);
| // console.log("_point---", JSON.stringify(that.point));
| that.map.setZoomAndCenter(that.zoom, [that.point.x, that.point.y]);
| if (that.mark) {
| // 创建一个 Marker 实例:
| var marker = new AMap.Marker({
| position: new AMap.LngLat(that._point.x, that._point.y), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
| title: that.mark.title,
| });
|
| // 将创建的点标记添加到已有的地图实例:
| that.map.add(marker);
| marker.on('click',function(e){
| console.log('666')
| that.$emit('fatherMethod')
| // that.$parent.fatherMethod();
|
| })
| }
|
| },
| },
| mounted() {
| const that = this;
| AMapLoader.load({
| key: "091ade377d4db40f68cc78cb9658ce8d", // 申请好的Web端开发者Key,首次调用 load 时必填
| version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
| plugins: [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
| })
| .then((AMap) => {
| that.map = new AMap.Map("container");
| that.locationMap();
| })
| .catch((e) => {
| console.log(e);
| });
| // const that = this;
| // that.map.setZoomAndCenter(that._zoom, [that._point.x, that._point.y]);
| // if (that.mark) {
| // // 创建一个 Marker 实例:
| // var marker = new AMap.Marker({
| // position: new AMap.LngLat(that._point.x, that._point.y), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
| // title: that.mark.title,
| // });
|
| // // 将创建的点标记添加到已有的地图实例:
| // that.map.add(marker);
| // }
| },
| watch: {
| point(newval, oldval) {
| this._point = newval;
| this.locationMap();
| },
| zoom(newval, oldval) {
| this._zoom = newval;
| },
| },
| props: ["point", "zoom", "mark"],
| };
| </script>
| <style lang="scss" scoped>
| #container {
| width: 100%;
| height: 100%;
| }
| </style>
|
|