@@ -27,6 +27,7 @@ const TILE_SIZE = Number(import.meta.env.VITE_TILE_SIZE);
27
27
let map : maplibregl . Map ;
28
28
const infoBox : HTMLElement | null = document . getElementById ( 'info_box' ) ;
29
29
const mapContainer : HTMLElement | null = document . getElementById ( 'map_container' ) ;
30
+ let popup : maplibregl . Popup | undefined ;
30
31
31
32
let omUrl : string ;
32
33
let timeSelected = new Date ( ) ;
@@ -95,6 +96,10 @@ const changeOMfileURL = () => {
95
96
variableSelector . replaceChildren ( '' ) ;
96
97
variableSelector . innerHTML = `${ getVariableOptions ( ) } ` ;
97
98
99
+ if ( popup ) {
100
+ popup . remove ( ) ;
101
+ }
102
+
98
103
if ( ! domain . variables . includes ( variable . value ) ) {
99
104
variable = variables . find ( ( v ) => v . value === domain . variables [ 0 ] ) as Variable ;
100
105
}
@@ -155,6 +160,19 @@ if (mapContainer) {
155
160
156
161
map . touchZoomRotate . disableRotation ( ) ;
157
162
163
+ // Add geolocate control to the map.
164
+ map . addControl (
165
+ new maplibregl . GeolocateControl ( {
166
+ fitBoundsOptions : {
167
+ maxZoom : 9.5
168
+ } ,
169
+ positionOptions : {
170
+ enableHighAccuracy : true
171
+ } ,
172
+ trackUserLocation : true
173
+ } )
174
+ ) ;
175
+
158
176
map . on ( 'load' , async ( ) => {
159
177
omUrl = getOMUrl ( ) ;
160
178
source = map . addSource ( 'omFileSource' , {
@@ -173,7 +191,6 @@ if (mapContainer) {
173
191
'road_area_pier'
174
192
) ;
175
193
176
- let popup : maplibregl . Popup | undefined ;
177
194
map . on ( 'mousemove' , function ( e ) {
178
195
if ( showPopup ) {
179
196
const coordinates = e . lngLat ;
@@ -192,7 +209,11 @@ if (mapContainer) {
192
209
coordinates . lng
193
210
) ;
194
211
if ( index ) {
195
- if ( hideZero . includes ( variable . value ) && value <= 0.25 ) {
212
+ if (
213
+ ( hideZero . includes ( variable . value ) &&
214
+ value <= 0.25 ) ||
215
+ ! value
216
+ ) {
196
217
popup . remove ( ) ;
197
218
} else {
198
219
let string = '' ;
0 commit comments