Working with base layers
In this recipe, we will explore layers. Actually, we already added a base layer in the previous recipes using the addLayer(<ILayer> layer)
method.
One of the advantages of the Mapbox API is the power to add multiple overlaid layers at runtime, which is an extremely useful feature that allows us to switch between different types of data without using a different map.
How to do it…
We will add a base layer on our map. This layer will be displayed when the page is displayed when first opening the browser.
Then, we will use hasLayer(<ILayer> layer)
to check whether a layer is already on the map, and if not, we will add it with addLayer(<ILayer> layer)
. In case a layer is already on the map, we will remove it first using removeLayer(<ILayer> layer)
.
There are various types of layers. The first type is a base layer, which can display tiles from various sources, such as Mapbox Street, Mapbox Terrain, or Mapbox Satellite. The second type of layer is an...