Book Image

Mastering OpenLayers 3

By : Gábor Farkas
Book Image

Mastering OpenLayers 3

By: Gábor Farkas

Overview of this book

OpenLayers 3 allows you to create stunning web mapping and WebGIS applications. It uses modern, cutting edge browser technologies. It is written with Closure Library, enabling you to build browser-independent applications without painful debugging ceremonies, which even have some limited fallback options for older browsers. With this guide, you will be introduced to the world of advanced web mapping and WebGIS. First, you will be introduced to the advanced features and functionalities available in OpenLayers 3. Next, you will be taken through the key points of creating custom applications with OpenLayers 3. You will then learn how to create the web mapping application of yours (or your company's) dream with this open source, expense-free, yet very powerful library. We’ll also show you how to make amazing looking thematic maps and create great effects with canvas manipulation. By the end of this book, you will have a strong command of web mapping and will be well on your way to creating amazing applications using OpenLayers 3.
Table of Contents (17 chapters)
Mastering OpenLayers 3
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

As in every other computer-related field, the Web has also become a determining factor in GIS. In this new trend, with some client-based knowledge, we can easily publish our maps and layers on the Web. However, as technology rapidly develops, we can now perform some more serious GIS-related work on the Web as well. With enough browser capabilities and client-side computational power, an even newer trend has emerged from the Web-based GIS world: WebGIS. This new trend researches the possibilities of deploying powerful GIS applications on the Web, making the most general workflows of a spatial analyst possible on a browser in a platform-independent manner.

Thanks to OSGEO, OGC, and other initiatives, companies, individuals, and the open source philosophy have made a quick and great impact on this brand new field. Consequently, there is a wide palette of open source applications and libraries to work with and build upon. One of the most original and robust web mapping projects is OpenLayers. This library debuted a brand new, cutting-edge technology with a major version change. OpenLayers 3 is capable of things that we could not even imagine a few years ago.

An unplanned consequence (we could probably call it externality) of its powerful capabilities is the added difficulty of using it and a steep learning curve. The twisted version of a famous quote also states: with great power comes great complexity. Creating simple maps and deploying simple web mapping applications is easy with OpenLayers 3; however, if we need something more advanced, we need more stable and in-depth knowledge of the library. Gaining this knowledge is a great journey, which Mastering OpenLayers 3 is designed to start you on and aid you through.

What this book covers

Chapter 1, Creating Simple Maps with OpenLayers 3, guides you through the process of creating a simple map with the library. It also discusses some key concepts of OpenLayers 3, an effective way of using the API documentation, and a method to debug broken code.

Chapter 2, Applying Custom Styles, shows you how you can use CSS and JavaScript to customize the appearance of your application. It discusses which parts of the library can be styled with CSS and those that can be styled with JavaScript. It provides some methods for you to use to create a custom style.

Chapter 3, Working with Layers, introduces you to layer management. In this chapter, you will learn how to modify the layer stack, what the most common and useful operations you can perform with layers, and essentially, how to build a complete layer tree.

Chapter 4, Using Vector Data, shows you various vector formats and operations. You will learn a lot about geospatial features. You will read, write, modify, and style vector layers, attributes, and geometries.

Chapter 5, Creating Responsive Applications with Interactions and Controls, guides you through the various controls in OpenLayers 3. You will learn how to use the available controls effectively and build your very own.

Chapter 6, Controlling the Map – View and Projection, discusses some essential views and projection-based concepts. You will learn how to modify the view, use extents dynamically, and use custom projections.

Chapter 7, Mastering the Renderers, is a bit of a specialized chapter. You will take a look at how rendering works in OpenLayers 3 and how you can modify these rendering mechanisms. There will be some examples using Canvas and the WebGL HTML technologies, ranging from novice to expert skill levels.

Chapter 8, OpenLayers 3 for Mobile, shows you how to create responsive applications for desktop and mobile browsers at the same time. You will be able to make some mobile-based considerations and create a mobile-friendly OpenLayers 3 application by the end of this chapter.

Chapter 9, Tools of the Trade – Integrating Third-Party Applications, introduces some other tools into your workflow, making the development of your application more efficient and enjoyable. You will get some tips about some very useful third-party applications and libraries, which can be easily integrated with OpenLayers 3.

Chapter 10, Compiling Custom Builds with Closure, shows you how to build your own version of OpenLayers 3. Along with the custom building process, you will learn how to bundle your own application with the library and generate a custom API documentation automatically.

What you need for this book

For this book, you will generally need a modern web browser on your system. For some of the chapters, you will also need some additional software. For a better experience, it is strongly advised to have a working server on your machine. It can be either an Apache, an Nginx, or a HTTP Server created from Python.

For Chapter 8, OpenLayers 3 for Mobile, you will either need a handheld touch device to test some touch based features, or a browser, which can emulate such a device. For emulation, any of Google Chrome, Mozilla Firefox, or Opera are good enough. Unfortunately, Microsoft browsers are not suitable for this purpose. For Chapter 9, Tools of the Trade – Integrating Third Party Applications, you will need a fresh version of QGIS.

Who this book is for

This book is intended for frontend developers with a basic understanding of JavaScript and GIS concepts, and preferably for those who are familiar with the fundamentals of OpenLayers 3. You might have never used OpenLayers 3 as a seasoned JavaScript developer. If this is the case, and you are ambitious and eager to learn web mapping, this book will definitely set you on the right track.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, and user input are shown as follows: "To make our map's div element focusable, we must add a tabindex property to it in the HTML file." Key combinations are also distinguished from regular text: "F12 in modern ones, or CTRL + J, if F12 does not work".

A block of code is set as follows:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 1 - Creating a simple map</title>
<link href="../../js/ol3-3.11.0/ol.css" rel="stylesheet">
<link href="ch01.css" rel="stylesheet">

Any command-line input or output is written as follows:

node tasks/build.js config/ol.json ol.js
node tasks/build.js config/ol-debug.json ol-debug.js

Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "From the available shortcuts, we will need the command prompt (Node.js command prompt) as we will need to start various JavaScript programs."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/MasteringOpenlayers3_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.