-
Notifications
You must be signed in to change notification settings - Fork 19
/
App.vue
276 lines (258 loc) · 9.68 KB
/
App.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<template>
<div style="padding: 20px">
<div style="height: 400px; width: 800px; resize: both; overflow: auto; border: 1px solid #d6d6d6; margin-bottom: 20px">
<mgl-map
v-if="showMap"
ref="map"
:center="center"
:zoom="zoom"
:attribution-control="true"
language="fr"
@map:load="onLoad"
@map:zoomstart="isZooming = true"
@map:zoomend="isZooming = false"
>
<mgl-frame-rate-control/>
<mgl-fullscreen-control/>
<mgl-attribution-control/>
<mgl-navigation-control/>
<mgl-scale-control/>
<mgl-geolocation-control/>
<mgl-custom-control v-if="showCustomControl" position="top-left" :no-classes="!useClasses">
<mgl-button type="mdi" :path="buttonIcon" style="color: deepskyblue"/>
</mgl-custom-control>
<mgl-style-switch-control :map-styles="mapStyles" :position="controlPosition"/>
<mgl-marker :coordinates="markerCoordinates" color="#cc0000" :scale="0.5"/>
<mgl-geo-json-source source-id="geojson" :data="geojsonSource.data as any">
<mgl-line-layer
v-if="geojsonSource.show"
layer-id="geojson"
:layout="layout"
:paint="paint"
@mouseenter="onMouseenter"
/>
</mgl-geo-json-source>
<mgl-vector-source source-id="libraries" :tiles="librariesSourceTiles">
<mgl-circle-layer layer-id="libraries" source-layer="libraries" :paint="librariesLayerCirclesPaint"/>
</mgl-vector-source>
</mgl-map>
</div>
<div style="margin-bottom: 20px">Version: {{ mapVersion }}</div>
Loaded Count: {{ loaded }}<br>
Is Zooming: {{ isZooming }}<br>
<div>
<input type="radio" id="one" value="top-left" v-model="controlPosition"/>
<label for="one">top-left</label>
<br/>
<input type="radio" id="tw0" value="top-right" v-model="controlPosition"/>
<label for="tw0">top-right</label>
<br/>
<input type="radio" id="three" value="bottom-left" v-model="controlPosition"/>
<label for="three">bottom-left</label>
<br/>
<input type="radio" id="four" value="bottom-right" v-model="controlPosition"/>
<label for="four">bottom-right</label>
<br/>
<span>Attribution Position: {{ controlPosition }}</span>
</div>
<div>
<input type="checkbox" v-model="useClasses" id="noclasses">
<label for="noclasses">Use Custom Control Classes</label>
</div>
<div>
<input type="checkbox" v-model="showCustomControl" id="showcustom">
<label for="showcustom">Show Custom Control</label>
</div>
<div>
<input type="checkbox" v-model="showMap" id="showmap">
<label for="showmap">Show Map</label>
</div>
<div>
<label for="cars">Language:</label>
<select :value="map?.language" @input="setLanguage">
<option value="">n/a</option>
<option value="de">German</option>
<option value="en">English</option>
<option value="fr">French</option>
<option value="ja">Japanese</option>
</select>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref, watch } from 'vue';
import { MglDefaults, MglEvent, Position, StyleSwitchItem, useMap, ValidLanguages } from '@/lib/main';
import { mdiCursorDefaultClick } from '@mdi/js';
import { CircleLayerSpecification, LineLayerSpecification, LngLatLike, MapLayerMouseEvent } from 'maplibre-gl';
import MglMap from '@/lib/components/map.component';
import MglFrameRateControl from '@/lib/components/controls/frameRate.control';
import MglFullscreenControl from '@/lib/components/controls/fullscreen.control';
import MglAttributionControl from '@/lib/components/controls/attribution.control';
import MglNavigationControl from '@/lib/components/controls/navigation.control';
import MglScaleControl from '@/lib/components/controls/scale.control';
import MglGeolocationControl from '@/lib/components/controls/geolocation.control';
import MglCustomControl from '@/lib/components/controls/custom.control';
import MglButton from '@/lib/components/button.component';
import MglStyleSwitchControl from '@/lib/components/controls/styleSwitch.control';
import MglMarker from '@/lib/components/marker.component';
import MglGeoJsonSource from '@/lib/components/sources/geojson.source';
import MglLineLayer from '@/lib/components/layers/line.layer';
import { FeatureCollection, LineString } from 'geojson';
import MglVectorSource from '@/lib/components/sources/vector.source';
import MglCircleLayer from '@/lib/components/layers/circle.layer';
MglDefaults.style = 'https://api.maptiler.com/maps/streets/style.json?key=cQX2iET1gmOW38bedbUh';
console.log('MglDefaults', MglDefaults);
const lineString = [
[ -122.483696, 37.833818 ],
[ -122.483482, 37.833174 ],
[ -122.483396, 37.8327 ],
[ -122.483568, 37.832056 ],
[ -122.48404, 37.831141 ],
[ -122.48404, 37.830497 ],
[ -122.483482, 37.82992 ],
[ -122.483568, 37.829548 ],
[ -122.48507, 37.829446 ],
[ -122.4861, 37.828802 ],
[ -122.486958, 37.82931 ],
[ -122.487001, 37.830802 ],
[ -122.487516, 37.831683 ],
[ -122.488031, 37.832158 ],
[ -122.488889, 37.832971 ],
[ -122.489876, 37.832632 ],
[ -122.490434, 37.832937 ],
[ -122.49125, 37.832429 ],
[ -122.491636, 37.832564 ],
[ -122.492237, 37.833378 ],
[ -122.493782, 37.833683 ]
];
export default defineComponent({
name : 'App',
components: {
MglCircleLayer, MglVectorSource, MglLineLayer, MglGeoJsonSource, MglMarker, MglStyleSwitchControl, MglButton, MglCustomControl,
MglGeolocationControl, MglScaleControl, MglNavigationControl, MglAttributionControl, MglFullscreenControl, MglFrameRateControl, MglMap
},
setup() {
const map = useMap(),
mapVersion = ref<string>(),
showCustomControl = ref(true),
loaded = ref(0),
markerCoordinates = ref<LngLatLike>([ 13.377507, 52.516267 ]),
geojsonSource = {
data: ref<FeatureCollection<LineString>>({
type : 'FeatureCollection',
features: [
{
type : 'Feature',
properties: {},
geometry : {
type : 'LineString',
coordinates: [
[ -122.483696, 37.833818 ],
[ -122.483482, 37.833174 ]
]
}
}
]
}),
show: ref(true)
};
watch(() => map.isLoaded, () => (console.log('IS LOADED', map)), { immediate: true });
watch(() => map.isMounted, (v: boolean) => (console.log('IS MOUNTED', v)), { immediate: true });
onMounted(() => {
setTimeout(() => (markerCoordinates.value = [ 13.377507, 42.516267 ]), 5000);
setInterval(() => {
if (geojsonSource.data.value.features[ 0 ].geometry.coordinates.length >= lineString.length) {
geojsonSource.data.value = <FeatureCollection<LineString>>{
type : 'FeatureCollection',
features: [
{
type : 'Feature',
properties: {},
geometry : {
type : 'LineString',
coordinates: [
[ -122.483696, 37.833818 ],
[ -122.483482, 37.833174 ]
]
}
}
]
};
} else {
geojsonSource.data.value = <FeatureCollection<LineString>>{
type : 'FeatureCollection',
features: [
{
type : 'Feature',
properties: {},
geometry : {
type : 'LineString',
coordinates: [
...geojsonSource.data.value.features[ 0 ].geometry.coordinates,
lineString[ geojsonSource.data.value.features[ 0 ].geometry.coordinates.length ]
]
}
}
]
};
}
}, 1000);
});
function onLoad(e: MglEvent) {
loaded.value++;
mapVersion.value = e.map.version;
console.log(e.type, e, e.map.version);
}
function onMouseenter(e: MapLayerMouseEvent) {
console.log('EVENT', e.type, e.lngLat);
}
function setLanguage(e: Event) {
console.log('setLanguage', e);
map.language = (e.target as HTMLSelectElement).value as ValidLanguages;
}
return {
showCustomControl, loaded, map, mapVersion, markerCoordinates, geojsonSource, onLoad, onMouseenter, setLanguage,
geojsonSourceData : geojsonSource.data,
isZooming : ref(false),
controlPosition : ref(Position.TOP_LEFT),
showMap : ref(true),
center : [ 10.288107, 49.405078 ] as LngLatLike,
zoom : 3,
useClasses : ref(true),
mapStyles : [
{
name : 'Streets',
label: 'Streets',
// icon : { path: mdiRoad },
style: 'https://api.maptiler.com/maps/streets/style.json?key=cQX2iET1gmOW38bedbUh'
},
{ name: 'Basic', label: 'Basic', style: 'https://api.maptiler.com/maps/basic/style.json?key=cQX2iET1gmOW38bedbUh' },
{ name: 'Bright', label: 'Bright', style: 'https://api.maptiler.com/maps/bright/style.json?key=cQX2iET1gmOW38bedbUh' },
{ name: 'Satellite', label: 'Satellite', style: 'https://api.maptiler.com/maps/hybrid/style.json?key=cQX2iET1gmOW38bedbUh' },
{ name: 'Voyager', label: 'Voyager', style: 'https://api.maptiler.com/maps/voyager/style.json?key=cQX2iET1gmOW38bedbUh' }
] as StyleSwitchItem[],
buttonIcon : mdiCursorDefaultClick,
layout : {
'line-join': 'round',
'line-cap' : 'round'
} as LineLayerSpecification['layout'],
paint : {
'line-color': '#FF0000',
'line-width': 8
} as LineLayerSpecification['paint'],
librariesSourceTiles : [ 'https://api.librarydata.uk/libraries/{z}/{x}/{y}.mvt' ],
librariesLayerCirclesPaint: {
'circle-radius': 5,
'circle-color' : '#1b5e20'
} as CircleLayerSpecification['paint']
};
}
});
</script>
<style lang="scss">
@import "~maplibre-gl/dist/maplibre-gl.css";
@import "@/lib/css/maplibre.scss";
body {
margin: 0;
}
</style>