Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
Leaflet Control Search: Search only markers which are currently visible on the map

I am working on my first project using Leaflet javascript library. After succesfully importing a geoJSON file on the map, I am trying to create a new geoJSON layer (currShownMarkersLayer), populated with only the markers which are currently within the map tile displayed, to use it as input to leaflet control search, so only these markers are searchable by leaflet control search. However, when I type something in leaflet control search box, I get this error:

Uncaught TypeError: this._retrieveData is undefined.

What am I doing wrong? Below I attach my code.

//////////////////////////Return geoJson Layer of visible markers on map///////////////////////


map.on('move', function() {
function getCurrentlyShownMarkers() {
    var currShownMarkers = [];
    map.eachLayer( function(layer) {
        if(layer instanceof L.CircleMarker) {
            if(map.getBounds().contains(layer.getLatLng())) {
                currShownMarkers.push(layer.feature);
            }
        }
        featuresLayer = new L.GeoJSON(currShownMarkers, {
        });
    });
    return featuresLayer;
    }   
currShownMarkersLayer = getCurrentlyShownMarkers();
});


////////////////////////////////////////Leaflet-Search/////////////////////////////////////////////


var searchControl = new L.Control.Search({
        layer: currShownMarkersLayer,
        propertyName: 'name',
        marker: false,
    });
    searchControl.on('search:locationfound', function(e) {
            e.layer.openPopup();
    });

map.addControl( searchControl ); 

Thanks for reading!

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda