Tuesday, 22 October 2019

Switching baselayers as user zooms in to map in OpenLayers?


I have a map which overlays Open Street Map data on imagery for Pennsylvania. As a baselayer to the roads (and eventually other layers) I have two baselayers - Blue Marble NG and USGS EROS 1ft imagery. I would like to be able to combine these two layers into a single base map object that switches automatically as the user zooms in since it makes no sense to view the 1ft imagery for the whole state or the Blue Marble imagery when you are zoomed in.


Ideally I'd like to do this on the client side as I'm pulling the imagery from two different sites.



Answer





  1. Add 2 base layers to the map

  2. Subscribe to the map's zoomend event


  3. Check the zoom level and just switch the base map for your user



Here's a sample page with an event handler for zoomend - http://www.openlayers.org/dev/examples/events.html.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...