Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add option to find own location in map views #10083

Merged
merged 18 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/components/views/location/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,31 @@ const useMapWithStyle = ({
}
}, [map, bounds]);

const [geolocate] = useState(
allowGeolocate
? new maplibregl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true,
},
trackUserLocation: false,
})
: null,
);
const [geolocate, setGeolocate] = useState<maplibregl.GeolocateControl | null>(null);

useEffect(() => {
if (map && geolocate) {
if (!map) {
return;
}
if (allowGeolocate && !geolocate) {
const geolocate = new maplibregl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true,
},
trackUserLocation: false,
});
setGeolocate(geolocate);
map.addControl(geolocate);
geolocate.on("error", onGeolocateError);
return () => {
Johennes marked this conversation as resolved.
Show resolved Hide resolved
geolocate.off("error", onGeolocateError);
};
}
}, [map, geolocate]);
if (!allowGeolocate && geolocate) {
map.removeControl(geolocate);
setGeolocate(null);
}
}, [map, geolocate, allowGeolocate]);

return {
map,
Expand Down
2 changes: 1 addition & 1 deletion test/components/views/location/LocationViewDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("<LocationViewDialog />", () => {
it("renders marker correctly for self share", () => {
const selfShareEvent = makeLocationEvent("geo:51.5076,-0.1276", LocationAssetType.Self);
const member = new RoomMember(roomId, userId);
// @ts-ignore cheat assignment to property
// @ts-ignore cheat assignment to property
selfShareEvent.sender = member;
const component = getComponent({ mxEvent: selfShareEvent });
// @ts-ignore fix when moving to rtl
Expand Down