mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-04-18 18:18:42 +00:00
Invalidate map and geolocate only when visible
Move the setTimeout and its contents inside the visible check so map.invalidateSize() and navigator.geolocation.getCurrentPosition(...) are only invoked when the map container is shown. This avoids unnecessary map invalidation and geolocation requests when the view is hidden; try/catch and the 0ms defer are preserved.
This commit is contained in:
parent
2804a4a4df
commit
92f434ec07
|
|
@ -367,17 +367,17 @@
|
|||
containerRef.current.style.display = (visible ? "block" : "none");
|
||||
|
||||
// defer until after layout/display change
|
||||
setTimeout(function () {
|
||||
try {
|
||||
map.invalidateSize();
|
||||
if (visible) {
|
||||
setTimeout(function () {
|
||||
try {
|
||||
map.invalidateSize();
|
||||
|
||||
if (visible) {
|
||||
navigator.geolocation.getCurrentPosition(pos => {
|
||||
mark(pos.coords.latitude, pos.coords.longitude, `My Location: (${pos.coords.latitude}, ${pos.coords.longitude})`);
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
}, 0);
|
||||
} catch (e) {}
|
||||
}, 0);
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
return _e('div', { id: 'mapView', ref: containerRef });
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user