Comments (11)
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.
any solution here?
from leaflet-search.
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.
this is a duplicate of #34
from leaflet-search.
@juliermegeotube try to look here:
http://labs.easyblog.it/maps/leaflet-search/examples/multiple-layers.html
from leaflet-search.
from leaflet-search.
@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.
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.
Hi All,
I got the solution. Thank you very much @stefanocudini and @reyemtm.
Find code bellow:
onEachFeature: function (feature, layer)
{ layer.bindPopup("Estação Maregrá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.
@juliermegeotube thank you too for share! ^_^
from leaflet-search.
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)
- How do I use my own local nominatim server? HOT 2
- Package seems to be interfering with other leaflet packages HOT 1
- Are there TypeScript typings for this project? HOT 6
- use react js. HOT 1
- I want to custom search box,How to deal with it? HOT 1
- Refactoring - Reformatting HOT 1
- Leaflet search + multiple geojson layers HOT 1
- How to disable further client-side filtering of ajax results? HOT 1
- error on marker false and hideMarkerOnCollapse true
- multiple equal search results HOT 1
- Dynamic alert on Location not found when result is not available.
- HTML in search result HOT 1
- Use Case WordPress HOT 1
- Bad url call composition HOT 1
- html characters in search results
- Wrong `location` in JS files in Demo page HOT 1
- JSONP broken HOT 2
- Error in css HOT 1
- Geocoding examples broken HOT 4
- Console returning Uncaught TypeError e.split is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflet-search.