0

I am using a L.control.search to search for points in GeoJSON file and create a layer with the points I´m seaching according to a features.properties.value, and dispay them on a map. The var that creates de layer with the points is:

var lights= L.geoJson(data, {
  filter: function(feature, layer) {
    return (feature.properties.type === "Lights");
  },
    pointToLayer: function(feature,latlng) {
    return new L.CircleMarker(latlng, {radius: 3, 
        fillOpacity: 1, 
        color: 'black', 
        fillColor: '#E0E0E0', 
        weight: 1,})
    },
    onEachFeature: setPopup
}  
); // end geojson layer all lights
lights.addTo(map);

Than I add a layer group and pass it to L.control.search to be able to search using feature.properties.maclora

var allLayers = L.layerGroup([lights]);

L.control.search({
    layer: allLayers,
    initial: false,
    propertyName: 'maclora',
    zoom: 20,
    buildTip: function(text, val) {
        var type = val.layer.feature.properties.maclora;
        return '<a href="#" class="' + type + '">' + text + '<b>' + type + '</b></a>';
    }
}).addTo(map);

But when I try to use another L.Control that searches for addresses the L.control.search disapears:

I´m using https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js to create another control and search for streets names and add a marker to it.

var geocoder = L.Control.geocoder({
        defaultMarkGeocode: true
    })
        .addTo(map);

How can I create something similar to a L.Control.Cluster() and add the controls to it?

7
  • Hi TomazicM, I have refrased my question. Yes I want to create another control to search for street names and add a marker to it. But when I do so, the L.ControlSearch. disapears from the map. Commented Nov 21, 2022 at 22:26
  • Where is L.control.search coming from? Please edit your question and add that info. Commented Nov 22, 2022 at 9:42
  • Hi TomazicM, just edit my question. Commented Nov 22, 2022 at 10:29
  • 1
    For me it works without problems. I tested with Leaflet 1.6.0 and 1.9.3. Commented Nov 22, 2022 at 10:34
  • What I find strange is, if I duplicate de L.control.search it shows in the map. But If I set L.Control.geocoder it doesn´t. Commented Nov 22, 2022 at 12:15

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.