Adding a navigation history control
Probably the most commonly used control in our mapping applications will be the Navigation control. OpenLayers.Control.Navigation
control integrates (makes use of) some other controls, such as OpenLayers.Control.DragPan
, OpenLayers.Control.ZoomBox
, or a wheel handler, which allows us to pan and zoom the map.
While navigating, moving, or zooming, it can be interesting to store a history of the navigation actions made by the user, so he/she can go back or forward to previous places. Fortunately, we don't need to reinvent the wheel. OpenLayers offers us the OpenLayers.Control.NavigationHistory
control.
This recipe shows how easy it is to add it to our applications and benefit from its features.
As you can see in the screenshot, we are going to add a button above the map that will enable or disable the Navigation component.
How to do it...
Create an HTML file with the required OpenLayers dependencies. Add the code for the toggle button that will enable/disable...