I'm using Mapbox's API to load markers on a map, and I want different markers to appear depending on whether the checkbox corresponding to their marker color is checked.
My data.geoJSON file looks something like this:
{
"type": "FeatureCollection",
"features": [ {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [13.353323936462402, 38.11200434622822]
},
"properties": {
"marker-color": "#9c89cc",
"marker-color": "#3b5998"
}
} ]
}
My HTML looks something like this:
<div id='filters' class='ui-select'>
<input type='checkbox' checked=checked class='filter' name='filter' id='blue' value='blue'/>
<label for='blue'>
Blue marker checkbox
</label>
</div>
<div id='map'></div>
However, I'm having trouble figuring out how to get a .change()
function to work inside .setFilter( function(feature) {} )
.
var featureLayer = L.mapbox.featureLayer()
.loadURL('/map/getjson/')
.addTo(map)
.setFilter(
function (feature) {
//$("input[type='checkbox']").click(function() {
if ($("#blue").prop("checked")) {
return (feature.properties["marker-color"] === "#3b5998");
} else {
return false;
}
//});
}
);
Basically, if return(feature.properties["marker-color"] === "#3b5998")
evaluates to true
, the marker with the indicated set of features will be display. Otherwise, the markers won't display.
This is some example javascript that Mapbox gives (no use of jQuery).
map.featureLayer.setFilter(function(feature) {
return (feature.properties['marker-symbol'] in enabled);
}
But I'm stumped about how to use .change()
or .click()
here, since I want the markers to display depending on whether or not their corresponding checkbox is checked.
I tried using .click():
function (feature) {
//$("input[type='checkbox']").click(function() {
if ($("#blue").prop("checked")) {
return (feature.properties["marker-color"] === "#3b5998");
} else {
return false;
}
//});
}
... but it doesn't work! I guess I can't use .click()
inside this function?