Leaflet proof-of-concept - filter GeoJSON based on two parameters
Listen for 'change' event of checkbox and then readd data filtering out features that don't have both parameters checked. In answer to https://gis.stackexchange.com/q/307985/122597
by Stefan
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.js"></script>
<div id="map"></div>
<div class="inputs" id="event-types">
<input type="checkbox" class="event-type" name="funfair" value="funfair" checked="true">
<label for="funfair">Funfair</label>
<input type="checkbox" class="event-type" name="trade" value="trade-demonstration" checked="true">
<label for="trade">Trade demonstration</label>
<input type="checkbox" class="event-type" name="free-exhibition" value="free-exhibition" checked="true">
<label for="free-exhibition">Free exhibition</label>
<input type="checkbox" class="event-type" name="paying-exhibition" value="paying-exhibition" checked="true">
<label for="exhibition">Paying exhibition</label>
<input type="checkbox" class="event-type" name="paying-demonstration" value="paying-demonstration" checked="true">
<label for="paying-demonstration">Paying demonstration</label>
<input type="checkbox" class="event-type" name="unknown" value="unknown" checked="true">
<label for="unknown">Unknown</label>
</div>
<div class="inputs" id="years">
<input type="checkbox" class="year" name="1890" value="1890" checked="true">
<label for="1890">1890</label>
<input type="checkbox" class="year" value="1892" checked="true">
<label for="1892">1892</label>
<input type="checkbox" class="year" value="1893" checked="true">
<label for="1893">1893</label>
</div>
CSS
#map {
height: 300px;
}
.inputs {
padding-bottom: 2em;
}
JavaScript
let checkboxStates
const jsontest = {"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ -16.5471268,28.4136726 ]
},
"properties": {
"Name":"Gran Hotel, Puerto de la Cruz",
"year":'1890',
"month":"February",
"days":"11-13th",
"organiser":"Pedro Reid, English tradesman living in Puerto de la Cruz",
"eventType":"funfair",
"notes":""
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 2.1753895,41.3767925 ]
},
"properties": {
"Name":"Teatro Circo, Barcelona",
"year":'1890',
"month":"February-March",
"days":"early",
"organiser":"Charles Kalb, representative of Edison",
"eventType":"trade-demonstration",
"notes":""
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 2.8241,41.98219 ]
},
"properties": {
"Name":"Casino, Girona",
"year":'1890',
"month":"March",
"days":"early",
"organiser":"Charles Kalb",
"eventType":"trade-demonstration",
"notes":""
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 2.188959,41.4304234 ]
},
"properties": {
"Name":"Teatre Sant Andreu, Barcelona",
"year":'1890',
"month":"September",
"days":"",
"organiser":"Paz y Esperanza choir",
"eventType":"free-exhibition",
"notes":"for working class communities"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 4.2660212,39.8887063 ]
},
"properties": {
"Name":"Claustros del Carmen, Maó",
"year":'1892',
"month":"June",
"days":"",
"organiser":"Mr Natini",
"eventType":"trade-demonstration",
"notes":""
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ -2.4635124,36.834363 ]
},
"properties": {
"Name":"Unknown location, Almería",
"year":'1892',
"month":"August",
"days":"ca. 12",
"organiser":"Mr Freixas",
"eventType":"paying-exhibition",
"notes":""
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
...