1

I am trying to visualize specific GeoJSON data.

I am successfully loading the full GeoJSON file (Multipolygon) using Leaflet JS. Is there any query to find specific polygon from that GeoJSON file?

For an example I am using USA state GeoJSON data. I am using a dropdown list to call specific states such as California - CA. How can I call that specific GeoJSON data of where state = California?

closed as unclear what you're asking by Devdatta Tengshe, whuber Aug 10 '14 at 14:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What do you mean by 'call specific states'? You need to give us more information about what exactly you want to achieve. – Devdatta Tengshe Aug 10 '14 at 11:24
3

http://leafletjs.com/examples/geojson.html

Filter The filter option can be used to control the visibility of GeoJSON features. To accomplish this we pass a function as the filter option. This function gets called for each feature in your GeoJSON layer, and gets passed the feature and the layer. You can then utilise the values in the feature's properties to control the visibility by returning true or false.

In the example below "Busch Field" will not be shown on the map.

var someFeatures = [{
    "type": "Feature",
    "properties": {
        "name": "Coors Field",
        "show_on_map": true
    },
    "geometry": {
        "type": "Point",
        "coordinates": [-104.99404, 39.75621]
    }
}, {
    "type": "Feature",
    "properties": {
        "name": "Busch Field",
        "show_on_map": false
    },
    "geometry": {
        "type": "Point",
        "coordinates": [-104.98404, 39.74621]
    }
}];

L.geoJson(someFeatures, {
    filter: function(feature, layer) {
        return feature.properties.show_on_map;
    }
}).addTo(map);

Or you can parse your geojson manually:

var json = {
    "people": {
        "person": [{
            "name": "Peter",
            "age": 43,
            "sex": "male"},
        {
            "name": "Zara",
            "age": 65,
            "sex": "female"}]
    }
};
$.each(json.people.person, function(i, v) {
    if (v.name == "Peter") {
        alert(v.age);
        return;
    }
});

Not the answer you're looking for? Browse other questions tagged or ask your own question.