How can I hide(opacity) all polygons, and only show the one with ID 73 [click example code]: https://jsfiddle.net/etrv684u/1/
HTML:
<div id="map"></div>
<button id="highlight">highlight left triangle</button>
CSS:
#map {
height:90vh;
width:820px;
}
JS:
// center of the map
var center = [40.8990418, 29.1568548];
// Create the map
var map = L.map('map', { pmIgnore: false }).setView(center, 9);
//Add Leaflet-Geoman controls with some options to the map
map.pm.addControls({
position: 'topleft',
drawCircleMarker: false,
rotateMode: false,
});
// JSON to map
let data = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[28.539734,40.840356],[28.935242,40.813315],[28.685303,41.174338],[28.539734,40.840356]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[29.369202,40.948411],[29.663086,41.021041],[29.138489,41.232249],[29.369202,40.948411]]]}}]};
var group = L.featureGroup().addTo(map);
L.geoJSON(data, {
onEachFeature: colorlayer,
style: {
color: "#00008c",
opacity: 0.6,
fillColor: '#333333',
fillOpacity: 0
}
}).addTo(group);
function colorlayer(feature, layer) {
layer.on('click', function (e) {
alert(this._leaflet_id);
});
}
document.querySelector('#highlight').addEventListener('click', function(){
//hide all polygons except 1 polygon
})
// Set up the OSM layer
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18
}).addTo(map);