From d470a08e9ce329f1a6ff9a4591c41e1e04fb62bb Mon Sep 17 00:00:00 2001 From: Aubrey-Li <63608597+Aubrey-Li@users.noreply.github.com> Date: Sat, 31 Jul 2021 12:36:12 -0700 Subject: allow locating user location --- src/client/views/nodes/MapBox/MapBox.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/client/views/nodes/MapBox/MapBox.tsx') diff --git a/src/client/views/nodes/MapBox/MapBox.tsx b/src/client/views/nodes/MapBox/MapBox.tsx index 2b3bcb0a2..6447d9715 100644 --- a/src/client/views/nodes/MapBox/MapBox.tsx +++ b/src/client/views/nodes/MapBox/MapBox.tsx @@ -69,7 +69,7 @@ export class MapBox extends ViewBoxAnnotatableComponent { this._map = map; drawingManager.setMap(map); + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition( + (position: GeolocationPosition) => { + const pos = { + lat: position.coords.latitude, + lng: position.coords.longitude, + }; + this._map.setCenter(pos); + } + ); + } else { + alert("Your geolocation is not supported by browser.") + } this.fitBounds(map); } @@ -268,7 +281,7 @@ export class MapBox extends ViewBoxAnnotatableComponent this.loadHandler(map)} options={mapOptions} > -- cgit v1.2.3-70-g09d2