Skip to content

Show Legend Image #763

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/mapml.css
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,6 +74,21 @@
color: revert;
}

/* Style Legend */
.legendLink span {
position: absolute;
visibility: hidden;
}
.legendLink:hover span, .legendLink:focus span {
visibility:visible;
left: 0;
right: auto;
z-index: 1;
}
.legendLink img {
max-width: 200px;
}

.leaflet-top .leaflet-control {
margin-top: 5px;
}
Expand Down
7 changes: 7 additions & 0 deletions src/mapml/layers/MapMLLayer.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -651,10 +651,17 @@ export var MapMLLayer = L.Layer.extend({

if (this._legendUrl) {
var legendLink = document.createElement('a');
var viewerSpan = document.createElement('span');
var legendImg = document.createElement('img');
legendLink.text = ' ' + this._title;
legendLink.href = this._legendUrl;
legendLink.target = '_blank';
legendLink.draggable = false;
legendLink.setAttribute('class', 'legendLink');
legendImg.src = this._legendUrl;
legendImg.alt = "Legend for " + this._title;
viewerSpan.appendChild(legendImg);
legendLink.appendChild(viewerSpan);
layerItemName.appendChild(legendLink);
} else {
layerItemName.innerHTML = this._title;
Expand Down