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

feat: 🎸 display collection's images in sidebar #1028

Merged
merged 3 commits into from
Sep 20, 2022
Merged
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
54 changes: 43 additions & 11 deletions examples/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<script src="../dist/vendor.js"></script>
<script src="../dist/leaflet.distortableimage.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body style="margin:0;">
Expand Down Expand Up @@ -57,7 +58,8 @@ <h3 id="offcanvasRightLabel">Images</h3>
</div>
<hr>
<div class="offcanvas-body">
<p id="response">No images yet...</p>
<p id="response" class="mb-5">No link = No images...</p>
<div id="imgContainer"></div>
</div>
</div>
</body>
Expand All @@ -69,6 +71,7 @@ <h3 id="offcanvasRightLabel">Images</h3>
let form = document.getElementById('form');
let input = document.getElementById('input');
let responseText = document.getElementById('response');
let imageContainer = document.getElementById('imgContainer');

const setupMap = () => {
map = L.map('map').setView([51.505, -0.09], 13);
Expand All @@ -77,23 +80,52 @@ <h3 id="offcanvasRightLabel">Images</h3>

map.addGoogleMutant();

map.whenReady(function() {
map.whenReady(() => {
new bootstrap.Modal(welcomeModal).show();
});
}
setupMap();

welcomeModal.addEventListener('hidden.bs.modal', function (event) {
new bootstrap.Offcanvas(sidebar).show();
});

form.addEventListener('submit', function(event){
console.log('here');
form.addEventListener('submit', (event) => {
event.preventDefault();
bootstrap.Modal.getInstance(welcomeModal).hide();
responseText.innerHTML = input.value
});
const url = input.value.replace('details', 'metadata');
axios.get(url)
.then((response) => {
if (response.data.files && response.data.files.length != 0) {
let imageCount = 0;
response.data.files.forEach(file => {
if (file.format === 'PNG' || file.format === 'JPEG'){
let imageRow = document.createElement('div');
let image = new Image(150, 150);
let placeButton = document.createElement('a');

placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary');
placeButton.innerHTML = 'Place on map';

image.src = `${url.replace('metadata', 'download')}/${file.name}`;

imageRow.classList.add('d-flex', 'justify-content-between', 'align-items-center', 'mb-4', 'pe-5');
imageRow.append(image, placeButton);

imageContainer.appendChild(imageRow);
imageCount++;
}
});
responseText.innerHTML = imageCount ? `${imageCount} image(s) fetched successfully.` : 'No images found in the link provided...'
} else {
responseText.innerHTML = 'No images found in the link provided...'
}
})
.catch((error) => {
responseText.innerHTML = 'Uh-oh! Something\'s not right with the link provided!'
})
.finally(() => {
bootstrap.Modal.getInstance(welcomeModal).hide();
});
});

welcomeModal.addEventListener('hidden.bs.modal', (event) => {
new bootstrap.Offcanvas(sidebar).show();
});
</script>
</html>