Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenLayers 3.x Cookbook

You're reading from   OpenLayers 3.x Cookbook This book will provide users with a variety of recipes that illustrate different features present in OpenLayers 3

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781785287756
Length 304 pages
Edition 2nd Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Antonio Santiago Antonio Santiago
Author Profile Icon Antonio Santiago
Antonio Santiago
Peter J. Langley Peter J. Langley
Author Profile Icon Peter J. Langley
Peter J. Langley
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Web Mapping Basics FREE CHAPTER 2. Adding Raster Layers 3. Working with Vector Layers 4. Working with Events 5. Adding Controls 6. Styling Features 7. Beyond the Basics Index

Creating a custom control


OpenLayers has plenty of controls and interactions that address a broad range of needs. However, the requirements that we could have to build a new web application inevitably demand the creation of a new one or the extension of an existing one.

OpenLayers 2 came with a layer switcher control that's not made it to OpenLayers 3. This is not a problem, as for this recipe, we're going to create our own layer switcher control. Apart from enabling the user to switch between a list of layers, this control will demonstrate how to extend the base control class (ol.control.Control) to utilize some default control behavior and then build on top of the base control to deliver an interactive control the user can click or tap to change the layer.

The source code for this recipe can be found in ch07/ch07-custom-control, and here's a preview of our custom control placed at the bottom-left of the map:

How to do it…

  1. Create an HTML file with the OpenLayers dependencies and a div element...

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