Got it, I needed to use a layerGroup for clearLayers to work, and my filter expression was ignored when I used a variable, so I just passed the layer creation into by radiobutton listener. A little extra code but it works.
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Layers Control Example</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<style>
html, body, #map {
width : 100%;
height : 100%;
}
</style>
</head>
<body>
<div id="panel">
<form>
<input type="radio" id="radioOne" name="verify" value="N" checked> Verified No <br>
<input type="radio" id="radioTwo" name="verify" value="Y" > Verified Yes <br>
</form><hr>
</div>
<div id="map" ></div>
<script>
var url = 'CIPts.json'; //REST service
var map = L.map('map').setView([42.736424, -73.762713], 10);
var osm=new L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',{
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'});
osm.addTo(map);
////////////////////
var ci_data;
ci_data = L.geoJson(null, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
color:'black',
fillColor: 'blue',
fillOpacity: 1,
radius: 8
})
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.Verified);
},
filter: function(feature, layer) {
return (feature.properties.Verified !== "Y" );
},
});
$.getJSON(url, function(data) {
ci_data.addData(data);
});
var myData = L.layerGroup([]);
myData.addLayer(ci_data);
myData.addTo(map);
document.getElementById("radioOne").addEventListener('click', function(event) {
theExpression = 'feature.properties.Verified !== "Y" ';
console.log(theExpression);
myData.clearLayers();
map.removeLayer(myData);
ci_data = L.geoJson(null, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
color:'black',
fillColor: 'blue',
fillOpacity: 1,
radius: 8
})
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.Verified);
},
filter: function(feature, layer) {
return (feature.properties.Verified !== "Y" );
},
});
$.getJSON(url, function(data) {
ci_data.addData(data);
});
myData.addLayer(ci_data);
myData.addTo(map);;
});
document.getElementById("radioTwo").addEventListener('click', function(event) {
theExpression = 'feature.properties.Verified == "Y" ';
console.log(theExpression);
map.removeLayer(myData);
myData.clearLayers();
ci_data = L.geoJson(null, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
color:'black',
fillColor: 'blue',
fillOpacity: 1,
radius: 8
})
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.Verified);
},
filter: function(feature, layer) {
return (feature.properties.Verified == "Y" );
},
});
$.getJSON(url, function(data) {
ci_data.addData(data);
});
myData.addLayer(ci_data);
myData.addTo(map);
});
</script>
</body>
</html>