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

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:

  1. Open the chapter-4-example2-starter folder in your favorite text editor. The project...

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