From 4d5cbd74c4824eeb861476c7fd1cb1eb41a39091 Mon Sep 17 00:00:00 2001 From: Rastislav Chynoransky Date: Fri, 8 Nov 2024 14:47:37 +0700 Subject: [PATCH] Force translate geolocate control label --- resources/js/components/MapContainer.vue | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/resources/js/components/MapContainer.vue b/resources/js/components/MapContainer.vue index 178769f..2a66fae 100644 --- a/resources/js/components/MapContainer.vue +++ b/resources/js/components/MapContainer.vue @@ -92,6 +92,16 @@ onUnmounted(() => { resizeObserver.value.disconnect(); }); +const onGeolocateControlLoaded = (ctrlGeolocate) => { + const ctrlGeolocateIcon = ctrlGeolocate.querySelector( + '.mapboxgl-ctrl-geolocate .mapboxgl-ctrl-icon', + ); + + if (ctrlGeolocate) ctrlGeolocate.setAttribute('aria-label', 'Lokalizuj ma'); + if (ctrlGeolocateIcon) + ctrlGeolocateIcon.setAttribute('title', 'Lokalizuj ma'); +}; + const loaded = ([{ data }, map]) => { map.addSource('artworks', { type: 'geojson', @@ -120,6 +130,17 @@ const loaded = ([{ data }, map]) => { ) .addControl(new mapboxgl.GeolocateControl(), 'top-right'); + const checkGeolocateControlLoaded = () => { + const el = document.querySelector('.mapboxgl-ctrl-geolocate'); + if (el) { + onGeolocateControlLoaded(el); + } else { + setTimeout(checkGeolocateControlLoaded, 100); + } + }; + + checkGeolocateControlLoaded(); + map.scrollZoom.disable(); mapRef.value = map; observeResize(map);