Changing map properties programmatically
Map properties are interaction handlers that allow you to customize how a user interacts with the map at runtime. You can enable or disable certain features, such as zoom, dragging, touch zoom, scroll wheel, and many more.
In this recipe, we will use our previous example and modify it to change the map properties programmatically.
You will learn how to change the zoom and center of the map, pan to specific coordinates or bounds, and restrict the movement to a region.
How to do it…
We will add a basic map with a base layer on the screen as in the previous recipe. Then we will use the onClick
handler on various screen elements to trigger the panTo
or zoomIn
method in order to pan or zoom the map programmatically.
Panning the map programmatically
In this recipe, we will use the methods we discussed to change the map properties programmatically. Perform the following steps:
Open the
chapter-4-example2-starter
folder in your favorite text editor. The project...