Skip to content

Instantly share code, notes, and snippets.

@geog4046instructor
geog4046instructor / leaflet-jquery-geojson-layer-control.js
Last active June 29, 2023 06:37
Leaflet - Control to show/hide a GeoJSON layer that has been added with AJAX through jQuery
/*
* This example shows how to add a layer list to a map where users can check and uncheck boxes to show and hide layers.
* The code below is combined with the code to add geojson to a map, since those two things are often used together.
* The code consists of five main parts:
* 1. Create the basemap(s) and layer(s)
* 2. Get geojson data and run a function to add it to a layer from step 1
* 3. Create the function that will be run in step 2
* 4. Create the list of layers that will appear in the control component
* 5. Create the control component
*/