showing and hiding elements depending on zoom level
See original GitHub issueHi, I am trying to show and hide elements depending on the zoom level. I grabbed the function that tracks the zoom level on this example and added the conditions. Is this approach correct/clean or is there a better way to achieve it?
here is the code I am using:
` var updateZoom = function() { var zoom = viewer.viewport.getZoom(true); var imageZoom = viewer.viewport.viewportToImageZoom(zoom);
zoomEl.innerHTML = 'Zoom:<br>' + (Math.round(zoom * 100) / 100) +
'<br><br>Image Zoom:<br>' + (Math.round(imageZoom * 100) / 100);
var zoomL =(Math.round(zoom * 100) / 100)
var zoom0="0.01"
var zoom1="0.02"
var zoom2="0.03"
var square = document.getElementById("square");
var circle = document.getElementById("circle");
var triangle = document.getElementById("triangle");
if(zoomL>=zoom0&&zoomL<zoom1){
square.style.display = "none";
circle.style.display = "none";
triangle.style.display = "block";
console.log ("zoom level 0")
}
if(zoomL>=zoom1&&zoomL<zoom2){
square.style.display = "block";
circle.style.display = "none";
triangle.style.display = "none";
console.log ("zoom level 1")
}
if(zoomL>=zoom2){
square.style.display = "block";
circle.style.display = "block";
triangle.style.display = "none";
console.log ("zoom level 2")
}
} // FIN UPDATE ZOOM
viewer.addHandler('open', function() {
viewer.addHandler("animation-finish", function animationFinishHandler(event){
console.log("animation-finish");
updateZoom();
});
});`
Thanks so much for any light.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Show or Hide Markers Based on Zoom Level - Medium
Show or Hide Markers Based on Zoom Level · 1.init the map · 2.detect when the zoom level changes · 3.get the data...
Read more >Show/hide markers depending on zoom-level [duplicate]
I would like to show icons if the user zooms to level 7 or more and hide the markers when zoom level is...
Read more >Show or hide SVG elements based on zoom level
I managed to find a solution using jquery. Below example will display the text if the browser zoom level is at least 2....
Read more >Hide and reveal elements at different zoom levels | Miro
The problem arises when a lot of small, unreadable content becomes visually distracting when you are zoomed out at the overall system-level.
Read more >Show/hide markers, geometry, or labels based on zoom level
zoomControl.setPosition('bottomright'); //Hide polygons on front page map after a certain zoom level var show_polygon_zoom = 10; // zoom level ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you!!! Ill apply these ideas and come back with a report,
@Salitehkat Looks resolved, closing. Please feel free to reopen this issue if necessary!