forked from aws-samples/amazon-location-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapPane.vue
98 lines (85 loc) · 2.28 KB
/
MapPane.vue
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
95
96
97
98
<template>
<div class="map-header">
<div>
<label>Map Style</label>
<select v-model="renderedMap">
<option v-for="map in availableMaps" :key="map.mapName" :label="map.style" :value="map.mapName" />
</select>
</div>
</div>
<div :id="id" class="map"></div>
</template>
<script>
import { createMap, createAmplifyGeocoder } from 'maplibre-gl-js-amplify';
import { NavigationControl } from 'maplibre-gl';
import { Geo } from 'aws-amplify';
import { ref, watch, toRefs } from 'vue';
export default {
props: {
id: String,
availableMaps: Array,
zoom: Number,
center: Object,
pitch: Number,
bearing: Number,
ActiveMap: String,
},
setup(props, context) {
const renderedMap = ref(Geo.getDefaultMap().mapName);
const map = ref(null);
const { id, zoom, center, pitch, bearing, ActiveMap } = toRefs(props);
const mapCreate = async () => {
map.value = await createMap({
container: id.value,
zoom: zoom.value,
center: center.value,
pitch: pitch.value,
bearing: bearing.value,
});
map.value.addControl(createAmplifyGeocoder());
map.value.addControl(new NavigationControl({ visualizePitch: true }));
map.value.on('mouseover', () => {
context.emit('active-map-update', id.value);
});
map.value.on('move', () => {
if (ActiveMap.value == id.value) {
context.emit(
'state-update',
map.value.getZoom(),
map.value.getCenter(),
map.value.getBearing(),
map.value.getPitch()
);
}
});
};
mapCreate();
watch(renderedMap, (renderedMap) => {
map.value.setStyle(renderedMap);
});
watch(zoom, (zoom) => {
if (ActiveMap.value !== id.value) {
map.value.setZoom(zoom);
}
});
watch(center, (center) => {
if (ActiveMap.value !== id.value) {
map.value.setCenter([center.lng, center.lat]);
}
});
watch(bearing, (bearing) => {
if (ActiveMap.value !== id.value) {
map.value.setBearing(bearing);
}
});
watch(pitch, (pitch) => {
if (ActiveMap.value !== id.value) {
map.value.setPitch(pitch);
}
});
return {
renderedMap,
};
},
};
</script>