Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mapbox Cookbook

You're reading from   Mapbox Cookbook Over 35 recipes to design and implement uniquely styled maps using the Mapbox platform

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781784397357
Length 264 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (8) Chapters Close

Preface 1. Introduction to Mapbox FREE CHAPTER 2. Mapbox Services 3. TileMill and Mapbox Studio 4. Mapbox.js 5. Mapbox.js Advanced 6. Mapbox GL Index

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image