Placing controls outside the map
By default, all the controls are placed on the map. This way, controls, such as Zoom
, Attribution
, or MousePosition
, are rendered on top of the map and over any layer. This is the default behavior, but OpenLayers is flexible enough to allow us to put controls outside the map. In this recipe (source code in ch05/ch05-controls-outside-map
), we are going to create a map where the Zoom to Extent and Scale Line controls are placed outside the map and within the sidebar, as you can see in the following screenshot:
How to do it…
To learn how to customize where the map controls are placed, follow these steps:
Create an HTML file and add the OpenLayers dependencies and
div
to hold the map. In particular, create adiv
element for each control within the sidebar markup:<div id="js-zoom-extent"></div> <div id="js-scale-line"></div>
Create a custom JavaScript file and instantiate the
map
instance withview
and a raster tile layer with the Open Street...