T
T
TyzhSysAdmin2015-08-03 00:49:36
JavaScript
TyzhSysAdmin, 2015-08-03 00:49:36

LeaFlet + LeaFlet.search + GeoJSON, search across multiple marker sets?

Hello dear community.
Trying to figure out " LeaFlet JS". With the output of the map itself and markers, everything is clear, but with LeaFlet.search I can’t solve problems.
Two sets of markers are superimposed on the map, in turn, I get them from a GeoJSON file
GeoJSON example

{
"type": "Feature",
"properties": {
  "name": "Что-то этакое",
  "category": "категория 1",
  "popupContent": "Какое-то описание",
  "icon": "green"
  },
"geometry":{
  "type": "Point",
  "coordinates": [37.60869026184082,48.8507382697713]
  }
}

Part of getting GeoJSON data
function onEachFeature(feature, layer) {
    if (feature.properties && feature.properties.popupContent) {
        layer.bindPopup(feature.properties.popupContent);
    }
};

function setMarkerIcon(feature, latlng) {
    var marker = new L.Marker(latlng, {icon: set_icon(feature.properties.icon)});
    return marker
}


function getMarkers(json_url) {
    var sLayer = new L.GeoJSON.AJAX(json_url, {
        onEachFeature: onEachFeature,
        pointToLayer: setMarkerIcon,
    });
    return sLayer
}

Add a search control to the map
markersLayer = getMarkers('ololo.olol/data.geojson');
map.addControl( new L.Control.Search({
        layer: markersLayer,
        propertyName: 'name',
    }) );

Searching on the 'name' field works just fine.
This is where my problems start, I don't understand how to add a second set of coordinates to the search.
For example, if you combine the sets into a group
markersLayer0 = getMarkers('ololo.olol/data0.geojson');
markersLayer1 = getMarkers('ololo.olol/data1.geojson');
groupLayer = new L.LayerGroup();

map.addControl( new L.Control.Search({
        layer: groupLayer ,
        propertyName: 'name',
    }) );

map.addLayer(groupLayer );
groupLayer .addLayer(markersLayer0);
groupLayer .addLayer(markersLayer1);

Here the search stops working on any of the layers and I don’t understand how to solve this problem.
Although, judging by the examples and the sources of LeaFlet.search, it accepts " L.LayerGroup() " as input to 'layers:' and theoretically should process the group without any problems. Don't drink too hard :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TyzhSysAdmin, 2015-09-04
@POS_troi

The problem was solved, the author took the pull request.
Who cares, look into the turnip and library examples.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question