[GIS] hiding some “feature”s in GeoJSON file on map

featuresgeojsonleafletpolygon

I have geojson file including boundaries of most countries in world.

When I clicked on a "feature" (aka country, or polygon) I want to hide it while keep showing the others. because I am planing to showing more detailed geojson (states, cities) for that clicked country.

I am planning to use Leaflet JS, but I am open to any other libraries as well.

===================

This is the first screen, apply the world countries boundaries.
enter image description here

This is after clicking somewhere on map, I added to US boundaries geoJson to main map variable.

enter image description here

As you can see, I put US geojson upon the world geojson (you can realize that there is still some green area(which comes from world geojson) on the top left part of USA).

What i want is to hide only clicked country, USA in this case, and show more detailed geojson belong to that country.

PS: I dont use tiles, I need to clarify countries by geojson

Best Answer

Leaflet has a useful filter function that could easily be triggered based on some event.

Alternatively, mapbox.js which is built on top of leaflet, has a useful setFilter function that you can apply to the a geojson feature layer.