aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/Map.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/map/Map.js')
-rw-r--r--modern/src/map/Map.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js
index 47ebb1f0..4ba36554 100644
--- a/modern/src/map/Map.js
+++ b/modern/src/map/Map.js
@@ -7,10 +7,10 @@ import React, {
import { SwitcherControl } from './switcher/switcher';
import deviceCategories from '../common/deviceCategories';
import { prepareIcon, loadImage } from './mapUtil';
+import t, { useLocalization } from '../common/localization';
import {
styleCarto, styleMapbox, styleMapTiler, styleOsm,
} from './mapStyles';
-import t from '../common/localization';
import { useAttributePreference } from '../common/preferences';
import palette from '../theme/palette';
@@ -64,10 +64,6 @@ const initMap = async () => {
map.on('load', initMap);
-map.addControl(new maplibregl.NavigationControl({
- showCompass: false,
-}));
-
const switcher = new SwitcherControl(
[
{ title: t('mapOsm'), uri: styleOsm() },
@@ -92,15 +88,32 @@ const switcher = new SwitcherControl(
},
);
+const addPrimaryControls = position => {
+ map.addControl(navigationControl, position);
+ map.addControl(switcher, position);
+}
+
+const removePrimaryControls =()=> {
+ map.removeControl(navigationControl);
+ map.removeControl(switcher);
+}
+
+
map.addControl(switcher);
const Map = ({ children }) => {
const containerEl = useRef(null);
-
+ const {direction} = useLocalization();
const [mapReady, setMapReady] = useState(false);
const mapboxAccessToken = useAttributePreference('mapboxAccessToken');
+ useEffect(()=>{
+ const controlsPosition = direction ==='rtl' ? 'top-left' : 'top-right';
+ addPrimaryControls(controlsPosition);
+ return removePrimaryControls;
+ },[direction])
+
useEffect(() => {
maplibregl.accessToken = mapboxAccessToken;
}, [mapboxAccessToken]);