-
Notifications
You must be signed in to change notification settings - Fork 7
/
MapBase.vue
97 lines (83 loc) · 2.07 KB
/
MapBase.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
<template>
<l-map
ref="map"
:zoom="zoom"
:center="center"
:style="{ height }"
:use-global-leaflet="false"
>
<l-tile-layer
url="https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png"
:attribution="attribution"
></l-tile-layer>
<l-marker
v-for="marker in markers"
:key="
marker.position.lat +
'-' +
marker.position.lng +
'-' +
new Date().getTime()
"
:lat-lng="[marker.position.lat, marker.position.lng]"
class="marker"
></l-marker>
</l-map>
</template>
<script lang="ts" setup>
import { defineProps, defineAsyncComponent } from 'vue';
import { PointExpression } from 'leaflet';
import 'leaflet/dist/leaflet.css';
const LMap = defineAsyncComponent(() =>
import('@vue-leaflet/vue-leaflet').then((exports) => exports.LMap)
);
const LTileLayer = defineAsyncComponent(() =>
import('@vue-leaflet/vue-leaflet').then((exports) => exports.LTileLayer)
);
const LMarker = defineAsyncComponent(() =>
import('@vue-leaflet/vue-leaflet').then((exports) => exports.LMarker)
);
interface Marker {
position: Position;
}
interface Position {
lat: number;
lng: number;
}
withDefaults(
defineProps<{
center?: PointExpression;
markers: Array<Marker>;
zoom?: number;
height?: string;
}>(),
{
center: () => [40, 40],
markers: () => [],
zoom: 8,
height: '400px',
}
);
const attribution =
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>';
</script>
<style>
.map-ct .ol-control {
@apply bg-white p-0;
-webkit-box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.4);
box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.4);
}
.map-ct .ol-control button {
@apply bg-white hover:bg-gray-100 text-black opacity-100 text-2xl
relative m-0;
}
.map-ct .ol-control button:first-child::after {
@apply w-full bg-gray-300 left-0 absolute;
content: '';
height: 2px;
bottom: -1px;
}
.map-ct .ol-full-screen {
@apply hidden pointer-events-none;
}
</style>