Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Tooltip Feature for ImageOverlays #1321

Merged
merged 74 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
18bc466
reversal of unintended changes
segun-codes Dec 9, 2022
4ced8eb
updated select.html
segun-codes Dec 10, 2022
c5beb1e
reverted to previous state
segun-codes Dec 10, 2022
d755efa
revert ExportAction.js
segun-codes Dec 10, 2022
16aacf1
Merge pull request #1 from segun-codes/Leaflet.DistortableImage-feature
segun-codes Dec 10, 2022
f71ad84
rebuild to resolve conflict
segun-codes Dec 10, 2022
802486a
Merge pull request #2 from segun-codes/Leaflet.DistortableImage-feature
segun-codes Dec 10, 2022
75e8fe3
Merge branch 'main' into main
segun-codes Dec 10, 2022
dcc2ea0
update listeners.html
segun-codes Dec 10, 2022
4f09c61
Merge pull request #3 from segun-codes/Leaflet.DistortableImage-featu…
segun-codes Dec 10, 2022
971ce75
Merge branch 'main' into main
jywarren Dec 10, 2022
2961a5f
fix more indentation issues
segun-codes Dec 10, 2022
67bb362
Merge branch 'main' of https://github.com/segun-codes/Leaflet.Distort…
segun-codes Dec 14, 2022
1d8fe70
placeholder update
segun-codes Dec 15, 2022
bde1749
Merge branch 'main' into main
segun-codes Dec 15, 2022
82d297e
updated to support restoring welcomemodal
segun-codes Dec 15, 2022
dd8cf1f
Merge branch 'main' of https://github.com/segun-codes/Leaflet.Distort…
segun-codes Dec 15, 2022
72e37ad
rename id on welcomemodal
segun-codes Dec 15, 2022
4677c2c
update
segun-codes Dec 15, 2022
383c072
removed makeshift commenting
segun-codes Dec 15, 2022
1b3f785
Merge branch 'publiclab:main' into main
segun-codes Dec 17, 2022
6e1b5f3
removed duplicate code in archive.js
segun-codes Dec 17, 2022
dfc9ee2
Merge branch 'main' of https://github.com/segun-codes/Leaflet.Distort…
segun-codes Dec 17, 2022
88cf6ca
fixed issue on geosearch bar
segun-codes Dec 17, 2022
603bbb9
Merge branch 'main' into main
segun-codes Dec 17, 2022
1fc0c1c
tooltip feature built for index.js
segun-codes Dec 29, 2022
fbf910a
tooltip feature rigged up for archive.js & index.js
segun-codes Dec 29, 2022
89772c5
updates
segun-codes Dec 29, 2022
fa51b78
updates
segun-codes Dec 29, 2022
97e2a89
update on tooltip feature
segun-codes Dec 29, 2022
0c47683
enabled tooltip feature on more sourcefiles
segun-codes Dec 29, 2022
15390ae
tooltip feature implemented using alternative approach
segun-codes Jan 5, 2023
ed68ed6
update
segun-codes Jan 5, 2023
a2eac1b
update
segun-codes Jan 5, 2023
4b11af9
update
segun-codes Jan 5, 2023
36a8bc9
update
segun-codes Jan 5, 2023
82fe23d
update
segun-codes Jan 5, 2023
ae7160c
new update
segun-codes Jan 5, 2023
8f3d21f
update
segun-codes Jan 5, 2023
7e57f3e
update
segun-codes Jan 6, 2023
9aec26e
hot-fix
segun-codes Jan 6, 2023
1fcea57
tooltip centered on image
segun-codes Jan 6, 2023
413267e
quick update
segun-codes Jan 6, 2023
7516502
Merge branch 'main' into main
segun-codes Jan 6, 2023
4d7663a
update
segun-codes Jan 7, 2023
20dd153
switchable tooltip feature
segun-codes Jan 9, 2023
7d9c8c7
update
segun-codes Jan 9, 2023
c5de57f
update
segun-codes Jan 9, 2023
ef2fb6e
updated and cleared failed test issue
segun-codes Jan 12, 2023
7b00604
update
segun-codes Jan 12, 2023
a0cc2d1
hotfix
segun-codes Jan 12, 2023
63953c6
update
segun-codes Jan 12, 2023
e6d4389
update
segun-codes Jan 12, 2023
13e04f9
hotfix
segun-codes Jan 12, 2023
f79faf8
update
segun-codes Jan 12, 2023
24c08af
fixed typo
segun-codes Jan 12, 2023
0afd5d7
non-switchable tooltip
segun-codes Jan 16, 2023
96ad807
Quick cleanup
segun-codes Jan 16, 2023
0a0807d
hotfix
segun-codes Jan 16, 2023
59938e1
conflict resolution
segun-codes Jan 16, 2023
bd63422
update
segun-codes Jan 16, 2023
9537359
hotfix
segun-codes Jan 16, 2023
0c1cd18
update
segun-codes Jan 16, 2023
9ea2d35
conflict resolution
segun-codes Jan 16, 2023
a91b0e2
update
segun-codes Jan 16, 2023
d1f6d0a
remove cc file
segun-codes Jan 16, 2023
c9d0a13
update
segun-codes Jan 17, 2023
55d3997
cleanup
segun-codes Jan 17, 2023
961cd01
Update src/DistortableCollection.js
jywarren Jan 17, 2023
e320171
Update src/DistortableCollection.js
jywarren Jan 17, 2023
079ec14
Update examples/js/archive.js
jywarren Jan 17, 2023
f9cfe2e
Update .gitignore
jywarren Jan 17, 2023
8b11891
Merge branch 'main' into main
jywarren Jan 17, 2023
6d8f547
Update examples/js/archive.js
jywarren Jan 17, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
coverage
todo.txt
observation.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, is this something we need in the shared .gitignore or just for you? I'm ok either way i guess, I'm just thinking it's not 100% necessary to share.

Copy link
Collaborator Author

@segun-codes segun-codes Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! yeah... I'd would remove these fast, thanks for spotting them @jywarren.

jywarren marked this conversation as resolved.
Show resolved Hide resolved
*.swp
*.swo
package-lock.json
Expand Down
33 changes: 25 additions & 8 deletions dist/leaflet.distortableimage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ <h2 class="modal-title">Welcome to MapKnitter Lite</h2>
<div class="offcanvas offcanvas-end" data-bs-backdrop="false" data-bs-keyboard="false" tabindex="1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<h3 id="offcanvasRightLabel">Images</h3>
<button type="button" id="restoreWelcomeModalBtn" class="btn btn-primary" data-bs-dismiss="offcanvas" aria-label="Close">Get Image</button>
<button type="button" class="btn btn-primary" data-bs-dismiss="offcanvas" aria-label="Close">View Map</button>
<button type="button" id="restoreWelcomeModalBtn" class="btn btn-primary btn-sm" data-bs-dismiss="offcanvas" aria-label="Close">Get Image</button>
<button type="button" class="btn btn-primary btn-sm" data-bs-dismiss="offcanvas" aria-label="Close">View Map</button>
</div>
<hr>
<div class="offcanvas-body">
Expand Down
26 changes: 21 additions & 5 deletions examples/js/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function extractKey() {
else if (input.value.includes('http://')) {
getUrl = input.value.replace('http:', 'https:');
input.value = getUrl;
console.log('input', input.value);
showImages(getUrl);
}
else
Expand All @@ -60,7 +59,6 @@ function extractKey() {
let imageCount = 0;
let fetchedFrom;


const renderImages = (fullResImages, url) => {
fullResImages.forEach((file) => {
const imageRow = document.createElement('div');
Expand Down Expand Up @@ -110,13 +108,19 @@ const renderThumbnails = (thumbnails = [], url, fullResImgs) => {
placeButton.innerHTML = 'Place';
placeButton.setAttribute('title', 'Place image on map');

// store the full-resolution image URL in a "data-original" attribute
image.setAttribute('data-original', `${url.replace('metadata', 'download')}/${thumbnails ? file.original : file.name}`);
image.src = `${url.replace('metadata', 'download')}/${file.name}`;
imageRow.classList.add('col-4', 'd-flex', 'flex-column', 'p-2', 'align-items-center');
imageRow.append(image, placeButton, fileName);
// store the full-resolution image URL in a "data-original" attribute
image.setAttribute('data-original', `${url.replace('metadata', 'download')}/${thumbnails ? file.original : file.name}`);
image.src = `${url.replace('metadata', 'download')}/${file.name}`;
imageRow.classList.add('col-4', 'd-flex', 'flex-column', 'p-2', 'align-items-center');
imageRow.append(image, placeButton, fileName);
imageContainer.appendChild(imageRow);
imageContainer.setAttribute('class', 'row');
imageContainer.setAttribute('class', 'row');
imageCount++;
});
};
Expand Down Expand Up @@ -148,7 +152,6 @@ function showImages(getUrl) {
})
.catch((error) => {
jywarren marked this conversation as resolved.
Show resolved Hide resolved
responseText.innerHTML = 'Uh-oh! Something\'s not right with the link provided!';
jywarren marked this conversation as resolved.
Show resolved Hide resolved
console.log(error);
})
.finally(() => {
bootstrap.Modal.getInstance(welcomeModal).hide();
Expand All @@ -172,10 +175,23 @@ tileMap.addEventListener('click', (event) => {
bootstrap.Offcanvas.getInstance(sidebar).hide();
});

function getImageName(imageURL) {
startIndex = imageURL.lastIndexOf('/') + 1;
endIndex = imageURL.lastIndexOf('.');
const imageName = imageURL.substring(startIndex, endIndex);

return imageName;
}

document.addEventListener('click', (event) => {
if (event.target.classList.contains('place-button')) {
const imageURL = event.target.previousElementSibling.dataset.original;
const image = L.distortableImageOverlay(imageURL);
const imageURL = event.target.previousElementSibling.src;
const imageTooltipText = getImageName(imageURL);

const image = L.distortableImageOverlay(
imageURL,
{tooltipText: imageTooltipText}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we used the filename, we could just split event.target.previousElementSibling.src with split('/') and take any text after the final / - saving us a lot of complexity above, see?

Copy link
Collaborator Author

@segun-codes segun-codes Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.... I'll give this a shot. Many thanks!

);
map.imgGroup.addLayer(image);
}
});
2 changes: 1 addition & 1 deletion src/DistortableCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ L.DistortableCollection = L.FeatureGroup.extend({

onRemove() {
if (this.editing) { this.editing.disable(); }
jywarren marked this conversation as resolved.
Show resolved Hide resolved

jywarren marked this conversation as resolved.
Show resolved Hide resolved
this.off('layeradd', this._addEvents, this);
this.off('layerremove', this._removeEvents, this);
},
Expand Down
25 changes: 25 additions & 0 deletions src/DistortableImageOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
editable: true,
mode: 'distort',
selected: false,
interactive: true,
tooltipText: '',
},

initialize(url, options) {
Expand All @@ -19,6 +21,9 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
this._selected = this.options.selected;
this._url = url;
this.rotation = {};

this.interactive = this.options.interactive;
this.tooltipText = this.options.tooltipText;
},

onAdd(map) {
Expand Down Expand Up @@ -81,6 +86,9 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
}

this.fire('add');

L.DomEvent.on(this.getElement(), 'mousemove', this.activateTooltip, this);
L.DomEvent.on(this.getElement(), 'mouseout', this.closeTooltip, this);
},

onRemove(map) {
Expand All @@ -96,6 +104,9 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
this.fire('remove');

L.ImageOverlay.prototype.onRemove.call(this, map);

L.DomEvent.on(this.getElement(), 'mouseout', this.closeTooltip, this);
L.DomEvent.off(this.getElement(), 'mousemove', this.deactivateTooltip, this);
},

_initImageDimensions() {
Expand Down Expand Up @@ -227,6 +238,20 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
}
},

activateTooltip() {
if (!this._selected) {
this.bindTooltip(this.tooltipText, {direction: 'top'}).openTooltip();
}
},

closeToolTip() {
this.closeTooltip();
},

deactivateTooltip() {
this.unbindTooltip();
},

setCorners(latlngObj) {
const map = this._map;
const zoom = map.getZoom();
Expand Down