question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

showing and hiding elements depending on zoom level

See original GitHub issue

Hi, 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:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Salitehkatcommented, Aug 3, 2018

Thank you!!! Ill apply these ideas and come back with a report,

0reactions
msalsberycommented, Jul 27, 2020

@Salitehkat Looks resolved, closing. Please feel free to reopen this issue if necessary!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found