Skip to main content
100%

Toggle topojson layers (change visibility)

✓ Published0🌍 Public
Aandrew-reid
Last edited Mar 17, 2017
Created on Nov 6, 2016

Clicking toggles visibility of countries from a TopoJSON world map, which are rendered as SVG paths using d3.geoPath with a Robinson projection. The `countries.json` TopoJSON file is loaded with d3.json, converted to GeoJSON, and each country is drawn as a separate path element in an SVG group. A button enables users to show or hide all country layers simultaneously by toggling the CSS visibility of the group, while preserving the map's layout and interactivity.

AI-generated description

Alternative approach to toggling layers, compared to : Toggling layers, reload file

Has the advantage of loading data only once, so it should be a smoother transition between toggles.

Click anywhere on the map to toggle layers.

Similar vizzes