-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTheMap.vue
73 lines (67 loc) · 1.93 KB
/
TheMap.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
<script setup lang="ts">
import { GeoCircleLayer } from 'mapbox-geo-circle-layer'
import mapboxgl from 'mapbox-gl'
import { markRaw, ref, watchEffect } from 'vue'
import mapboxConfig from '../configs/mapbox-config'
const circleLayerParameters = [
{
radiusInMeters: 100,
center: { lng: 139.7671, lat: 35.6812 },
fill: { red: 0.5, green: 0.5, blue: 1.0, alpha: 0.5 }
},
{
radiusInMeters: 250,
center: { lng: 139.7671, lat: 35.6812 },
fill: { red: 1.0, green: 0.5, blue: 0.5, alpha: 0.3 }
},
{
radiusInMeters: 1000,
center: { lng: 139.7671, lat: 35.6812 },
fill: { red: 0.5, green: 1.0, blue: 0.5, alpha: 0.75 }
}
]
const circleLayer = new GeoCircleLayer('example-circle', circleLayerParameters[0])
const mapContainer = ref<HTMLElement>()
const map = ref<mapboxgl.Map>()
const circleLayerParamIndex = ref(0)
// configures the map when the map container becomes ready
watchEffect(() => {
if (mapContainer.value == null) {
return
}
if (map.value != null) {
console.warn('map has already been initialized')
}
mapboxgl.accessToken = mapboxConfig.accessToken
map.value = markRaw(
new mapboxgl.Map({
container: mapContainer.value,
style: 'mapbox://styles/mapbox/streets-v12',
center: [139.7671, 35.6812], // Tokyo station
zoom: 15
})
)
map.value.on('load', () => {
map.value!.addLayer(circleLayer)
map.value!.on('click', () => {
++circleLayerParamIndex.value
if (circleLayerParamIndex.value >= circleLayerParameters.length) {
circleLayerParamIndex.value = 0
}
const params = circleLayerParameters[circleLayerParamIndex.value]
circleLayer.radiusInMeters = params.radiusInMeters
circleLayer.center = params.center
circleLayer.fill = params.fill
})
})
})
</script>
<template>
<div ref="mapContainer" class="map-container"></div>
</template>
<style scoped>
.map-container {
width: 100%;
height: 100%;
}
</style>