mapbox / mapbox-gl-geocoder

Geocoder control for mapbox-gl-js using Mapbox Geocoding API
https://mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder/
ISC License
364 stars 180 forks source link

Make "No results found" configurable via configs #490

Open dev7ch opened 1 year ago

dev7ch commented 1 year ago

This should add a dynamic label for "No results found", related to #328

Disclaimer: not tested, just a walk by fix, hopefully it fits

mbardelmeijer commented 10 months ago

Would be great to have! We now have to resort to hacky mutation observer fixes:

(function () {
    // Create a new MutationObserver instance
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.type === 'childList') {
                var noResults = document.querySelector('.mapbox-gl-geocoder--no-results');
                if (noResults && noResults.innerText === "No results found") {
                    noResults.innerHTML = 'Geen resultaten gevonden.';
                }
            }
        });
    });

    // Select the target node for observing changes
    const targetNode = document.getElementsByClassName('suggestions')[0];

    // Set up the observer configuration
    const config = { childList: true, subtree: true };

    // Start observing the target node for configured mutations
    observer.observe(targetNode, config);
})();