Skip to content

Commit f42ee5e

Browse files
authored
Adds a remove layer button to controls (#306)
* Adds a remove layer button to controls * Rename remove button class * Temporary fix to x location
1 parent 8b263b4 commit f42ee5e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/mapml.css

+5
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,9 @@ summary {
434434
z-index: 1000;
435435
pointer-events: none;
436436
position: relative;
437+
}
438+
439+
.mapml-layer-remove-button {
440+
margin-left: 15px;
441+
text-decoration: none;
437442
}

src/mapml/layers/MapLayer.js

+13
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,18 @@ export var MapMLLayer = L.Layer.extend({
494494
opacityControlSummaryLabel = document.createElement('label'),
495495
mapEl = this._layerEl.parentNode;
496496

497+
let removeButton = document.createElement('a');
498+
removeButton.href = '#';
499+
removeButton.role = 'button';
500+
removeButton.title = 'Remove Layer';
501+
removeButton.innerHTML = "<span aria-hidden='true'>&#10006;</span>";
502+
removeButton.classList.add('mapml-layer-remove-button');
503+
L.DomEvent.disableClickPropagation(removeButton);
504+
L.DomEvent.on(removeButton, 'click', L.DomEvent.stop);
505+
L.DomEvent.on(removeButton, 'click', (e)=>{
506+
mapEl.removeChild(e.target.closest("fieldset").querySelector("span").layer._layerEl);
507+
}, this);
508+
497509
input.defaultChecked = this._map ? true: false;
498510
input.type = 'checkbox';
499511
input.className = 'leaflet-control-layers-selector';
@@ -598,6 +610,7 @@ export var MapMLLayer = L.Layer.extend({
598610
fieldset.appendChild(details);
599611
details.appendChild(summary);
600612
summary.appendChild(label);
613+
summary.appendChild(removeButton);
601614
details.appendChild(opacityControl);
602615

603616
if (this._styles) {

0 commit comments

Comments
 (0)