0

I'm using L.Control.geocoder to search my map by address and coordinates, but I wanted to do an autocomplete search using data from the GeoJSON properties.Nemesis file. Is it possible to add this functionality to the geocoder?

enter image description here

JS:

var geocoder = L.Control.geocoder({
    position: 'topleft',
    collapsed: false,
    placeholder: 'Search...',
    defaultMarkGeocode: false,
})
geocoder.on('markgeocode', function(event) {
    var center = event.geocode.center;
    if(document.getElementById("divRadar") != null) {
        removeMarkerRadar();
    } else {
    }
    showMarkerRadar(center);
    map.flyToBounds(L.polygon([
        event.geocode.bbox.getNorthWest(),
        event.geocode.bbox.getSouthWest(),
        event.geocode.bbox.getSouthEast(),
        event.geocode.bbox.getNorthEast()
    ]).getBounds(), { maxZoom: 15 });
}).addTo(map);

GeoJSON:

"features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -9.224396,
                    38.706905
                ]
            },
            "properties": {
                "id": "1",
                "L4": "OCICS",
                "n_ordem": "",
                "tecnico": "",
                "a3_crm_outros": "",
                "nemesis": "17DOI_SUBS064375",
                "a6_geca_af": "1032548843",
                "acl": "01MF01",
                "desig_trabalho": "Substituir poste de 8 metros",
                "morada": "Rua General Ferreira Martins, traseiras do nº 4 - Miraflores",
                "coordenadas": "38.706905, -9.224396",
                "data_entrega": "",
                "estado": "Suspenso",
                "data_producao": "",
                "data_policia": "",
                "observacoes": "Poste em terreno muito inclinado com acesso muito difícil, atrás de edifício. (fotos via email)"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -9.4152948,
                    38.711593
                ]
            },
            "properties": {
                "id": "5",
                "L4": "OCICS",
                "n_ordem": "",
                "tecnico": "",
                "a3_crm_outros": "",
                "nemesis": "18DOI_SUBC119815",
                "a6_geca_af": "1032908299",
                "acl": "01CS01",
                "desig_trabalho": "Substituir cabo TPC, para o PD 600 (interior), por cabo  plástico  10 pares, e em simultâneo instalar cabo FO, para futuro PDO.. Duvidas, falar com César Fonseca.",
                "morada": "(GM)- Praceta Marqês de Soveral nº 81, Cascais",
                "coordenadas": "38.711593,-9.4152948",
                "data_entrega": "",
                "estado": "Suspenso",
                "data_producao": "",
                "data_policia": "",
                "observacoes": "11/11/2019-  CF Sim, é necessário tentar substituir o cobre e deixar guia para depois passar a fibra."
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -9.3772091,
                    38.7088777
                ]
            },
            "properties": {
                "id": "7",
                "L4": "OCICS",
                "n_ordem": "",
                "tecnico": "",
                "a3_crm_outros": "",
                "nemesis": "18DOI_SUBS120917",
                "a6_geca_af": "1032910014",
                "acl": "01ES01",
                "desig_trabalho": "Acondicionar correctamente rolos de cabo no poste e apear cabos RAD/drops desactivos.. Solicitação da CMC.",
                "morada": "(MJ)-Rua Vasco da Gama nº 58, Alapraia",
                "coordenadas": "38.7088777,-9.3772091",
                "data_entrega": "",
                "estado": "Suspenso",
                "data_producao": "",
                "data_policia": "",
                "observacoes": "Solicitei à VIATEL devolução"
            }
        }
1
  • There is no such functionality included in the L.Control.geocoder control itself. You will have to use one of the JS autocomplete libraries for that. There are plenty, here is a list of some of them: cssscript.com/best-autocomplete. This is then not GIS related question any more. If you'll have questions about using those libraries, you'll have to ask on StackOverflow site
    – TomazicM
    Commented Feb 21 at 19:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.