Skip to content

Commit

Permalink
Update view.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-leech committed Nov 15, 2023
1 parent 7ebd1d1 commit 3bf199e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/ui/layers/view.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ export default (layer) => {
}

// Create a div for the magnifying glass icon
const zoomDiv = mapp.utils.html.node`<div class="mask-icon search" title="Zoom To Layer Extent" data-id="zoom-to" style="opacity: 1; pointer-events: auto ; background-color:#003D57">`
const zoomDiv = mapp.utils.html.node`<div class="mask-icon search" title="Zoom To" data-id="zoom-to" style="opacity: 1; pointer-events: auto ; background-color:#003D57">`
// Add an event listener to the magnifying glass icon to show the zoom level div when clicked
zoomDiv.addEventListener('click', () => {
// Zoom to the zoom level
// Zoom to the extent of the layer if table provided.
if (layer.tableCurrent() !== null) {
layer.zoomToExtent();
layer.show();
};

// Zoom to the zoom level if tables object.
for (const key in layer.tables) {
if (layer.tables[key] !== null) {
layer.mapview.Map.getView().setZoom(key);
Expand All @@ -125,6 +131,9 @@ export default (layer) => {
}
});

// Add the zoom Button before the layer toggle.
layer.view.querySelector('[data-id=display-toggle]').before(zoomDiv)

// The layer view drawer should be disabled if layer.tables are not available for the current zoom level.
layer.mapview.Map.getTargetElement().addEventListener('changeEnd', () => {

Expand All @@ -139,14 +148,10 @@ export default (layer) => {
layer.view.querySelector('[data-id=display-toggle]').classList.remove('on')
// Set the layer toggle button to disabled.
layer.view.querySelector('[data-id=display-toggle]').classList.add('disabled')
// Add the zoom Button before the layer toggle.
layer.view.querySelector('[data-id=display-toggle]').before(zoomDiv)

} else {
// Set the layer toggle button to enabled.
layer.view.querySelector('[data-id=display-toggle]').classList.remove('disabled')
// Remove the zoom Button before the layer toggle.
zoomDiv?.remove();
}

})
Expand Down

0 comments on commit 3bf199e

Please sign in to comment.