Giter VIP home page Giter VIP logo

Comments (11)

reyemtm avatar reyemtm commented on May 18, 2024 3

is this a duplicate of #34

To search more than one attribute/field, what you can do is create a new field to search on, that is a combination of whatever fields you want to search. You can do this in your GIS software, or in your Leaflet map. For example, if you want to search name, address and zipcode, you could create a new field called, for example, "index". Do this outside of leaflet search, before it is added:

L.geoJson(yourgeojson, {
    onEachFeature: function(feature, layer) {
        var p = layer.feature.properties;
        p.index = p.name + " | " + p.address + " | " + p.zip;
    }
}).addTo(map);

//then after the data has loaded, on('ready' or on('data:loaded' or whatever , add the data to leaflet search

Maybe not the best solution, but it works and is very easy. I am using this method in several maps.

from leaflet-search.

kaio328 avatar kaio328 commented on May 18, 2024

any solution here?

from leaflet-search.

indeOWS avatar indeOWS commented on May 18, 2024

Hi reyemtm,
Thank for the solution. Now, I have another issue in the same direction: I have several layers/Geojson (polygon and points). Is there any solution to make only one search in different column/attributes of different Geojson. Let's say that attribute "location" is in Json1 only and attribute "area" is in Json2 only, How could a I make only one search control for "location" and "area" in Json1 and Json2 respectively?
Thank you for your time in advance

from leaflet-search.

stefanocudini avatar stefanocudini commented on May 18, 2024

this is a duplicate of #34

from leaflet-search.

stefanocudini avatar stefanocudini commented on May 18, 2024

@juliermegeotube try to look here:
http://labs.easyblog.it/maps/leaflet-search/examples/multiple-layers.html

from leaflet-search.

reyemtm avatar reyemtm commented on May 18, 2024

from leaflet-search.

indeOWS avatar indeOWS commented on May 18, 2024

@reyemtm and @stefanocudini thank you very much for the help. I can search all nautical charts polygon using @reyemtm code:

{
var p = layer.feature.properties;
p.index = p.name + " | " + p.address + " | " + p.zip;
}
However I am getting a error while doing the same for the tide gauges point geojson ( maregrafos.json). Here is my code:

var markers_tide = L.markerClusterGroup();
var tide_gauges = L.geoJson(station, {
onEachFeature: function (feature, layer)
{
layer.bindPopup("Estação Maregráfica: "+feature.properties.ESTACAO+"
"+
"ID: "+feature.properties.ID+"
"+
"F-41: "+feature.properties.URL);
},
pointToLayer: function(feature, latlng) {
return L.marker(latlng, {icon: maregrafoIcon});
}

// creating another attribute "index" in the Geojson in order to maximize the search control.
var p = layer.feature.properties;
p.index = p.ID + " | " + p.ESTACAO + " | ";

  });

markers_tide.addLayer(tide_gauges); // add it to the cluster group
map.addLayer(markers_tide);

Here the Error Message: SyntaxError: missing } after property list
Any help on that, please?

Thank you very much in advance

from leaflet-search.

indeOWS avatar indeOWS commented on May 18, 2024

If I comment the code

var p = layer.feature.properties;
p.index = p.ID + " | " + p.ESTACAO + " | ";
The API works fine. I tried playing with some parenthesis, but I could not find the error.
Thanks

from leaflet-search.

indeOWS avatar indeOWS commented on May 18, 2024

Hi All,
I got the solution. Thank you very much @stefanocudini and @reyemtm.

Find code bellow:

onEachFeature: function (feature, layer)

  	{
  	layer.bindPopup("Esta&#231;&#227;o Maregr&#225;fica: "+feature.properties.ESTACAO+"<br>"+
  	                "ID: "+feature.properties.ID+"<br>"+
  					"F-41: "+feature.properties.URL);//just to show something in the popup. could be part of the geojson as well!
  	// creating another attribute "index" in the Geojson in order to maximize the search control. If needed, by removing the next two lines the code in fuction onEachFeaturestylelargegeoj does not make any change. 				
  	var p = layer.feature.properties;
        p.index = p.ID + " | " + p.ESTACAO + " | ";					
  	},				
      pointToLayer: function(feature, latlng) {
        return L.marker(latlng, {icon: maregrafoIcon});
  	}   
  
  });

from leaflet-search.

stefanocudini avatar stefanocudini commented on May 18, 2024

@juliermegeotube thank you too for share! ^_^

from leaflet-search.

hjrobinson avatar hjrobinson commented on May 18, 2024

I hate to be a pest, but is there a working example available of how to search two columns of GeoJSON data? I tried my best to understand the solutions presented here. Please use the geojson-layer.htm example as the basis. For example, I would like to know how to be able to search for both name and density in the us_states.js file. I'm new at this thanks for your help!

from leaflet-search.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.