You are previewing Mastering OpenLayers 3.
O'Reilly logo
Mastering OpenLayers 3

Book Description

Create powerful applications with the most robust open source web mapping library using this advanced guide

About This Book

  • Develop responsive and platform-independent web mapping applications with OpenLayers 3

  • Learn the key points of creating great applications with native JavaScript through the step-by-step examples

  • Master the use of the library, from compiling custom builds to developing a complete WebGIS application

  • Who This Book Is For

    This book is intended for front-end developers with 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 eager to learn web mapping, this book will definitely set you on the right track.

    What You Will Learn

  • Use the advanced functionality of the OpenLayers 3 library effectively

  • Implement the library in your application, shaping it to your needs

  • Manage layers and the layer stack dynamically

  • Create not only stunning but also accurate thematic maps

  • Extend OpenLayers 3 with your own custom classes

  • Develop mobile-friendly web mapping applications

  • Make stunning effects with canvas manipulation, or visualize point clouds with WebGL

  • Integrate third-party applications, and create custom builds that completely satisfy your needs

  • In Detail

    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.

    Style and approach

    This is an advanced guide packed with comprehensive examples, and it concentrates on the advanced parts of OpenLayers 3 and JavaScript. It intentionally skips the basic and well-known methodologies, but discusses the hard-to-understand ones in great detail.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Mastering OpenLayers 3
      1. Table of Contents
      2. Mastering OpenLayers 3
      3. Credits
      4. About the Author
      5. About the Reviewer
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Creating Simple Maps with OpenLayers 3
        1. Before getting started
          1. Creating a working environment
        2. Structure of OpenLayers 3
        3. Building the layout
          1. Creating the appeal
          2. Writing the code
        4. Using the API documentation
          1. Understanding type definitions
        5. Debugging the code
        6. Summary
      9. 2. Applying Custom Styles
        1. Before getting started
          1. Basic considerations
        2. Customizing the default appearance
          1. Identifying the classes
          2. Styling the controls
          3. Customizing the attribution control
          4. Creating a custom zoom control with CSS
        3. Styling vector layers
        4. Customizing the appearance with JavaScript
          1. Changing the overview map and the scale bar
          2. Truncating the coordinate control
          3. Changing the attribution
        5. Creating a WebGIS client layout
          1. Building the HTML
          2. Styling the layout
          3. Writing the code
        6. Summary
      10. 3. Working with Layers
        1. Before getting started
          1. Using a proxy
          2. Resources to use
          3. Basic considerations
        2. Building a layer tree
          1. Styling the layer tree
          2. Creating a layer tree constructor
        3. Adding layers dynamically
          1. Creating the interface
          2. Extending the constructor
          3. Fetching the WMS metadata
          4. Adding WMS layers
          5. Adding WFS layers
          6. WFS considerations
        4. Adding vector layers with the File API
          1. Creating the interface
          2. Building the method
        5. Adding vector layers with a library
        6. Removing layers dynamically
          1. Extending a constructor
        7. Changing layer attributes
          1. Styling active layers
          2. Extending the method
        8. Changing the layer order with the Drag and Drop API
        9. Clearing the message bar
        10. Summary
      11. 4. Using Vector Data
        1. Before getting started
        2. Accessing attributes
          1. Writing the code
        3. Setting attributes
          1. Styling the form
          2. Writing the code
        4. Validating attributes
          1. Adjusting the styles
          2. Building headers
          3. Writing the code
        5. Creating thematic layers
          1. Extending the layer tree
          2. Creating choropleth maps
          3. Creating categorized maps
        6. Saving vector data
          1. Saving in arbitrary formats
        7. Saving with WFS-T
        8. Modifying the geometry
        9. Summary
      12. 5. Creating Responsive Applications with Interactions and Controls
        1. Before getting started
          1. Basic considerations
        2. Building the toolbar
        3. Mapping interactions to controls
          1. Creating the control
          2. Adding and removing the control
          3. Adding a selection control
        4. Building a set of feature selection controls
          1. Styling the controls
          2. Creating the selection tools
        5. Adding new vector layers
          1. Creating the HTML and the CSS
          2. Extending the layer tree
        6. Building a set of drawing tools
          1. Writing the method
        7. Modifying and snapping to features
          1. Extending the method
        8. Creating new interactions
          1. Understanding ol.interaction.Pointer
          2. Removing features
          3. Dragging features
          4. Extending the method
        9. Building a measuring control
          1. Creating the interaction
          2. Doing geodesic measurements
          3. Calculating lengths even more precisely
        10. Summary
      13. 6. Controlling the Map – View and Projection
        1. Before getting started
          1. Basic considerations
        2. Customizing a view
        3. Constraining a view
        4. Creating a navigation history
        5. Working with extents
          1. Creating a zoom control
          2. Extending the toolbar
        6. Rotating a view
        7. Changing the map's projection
        8. Creating custom animations
          1. Building the control
          2. Creating animations
        9. Summary
      14. 7. Mastering Renderers
        1. Before getting started
        2. Using different renderers
        3. Creating a WebGL map
        4. Drawing lines and polygons with WebGL
        5. Blending layers
        6. Clipping layers
        7. Exporting a map
        8. Creating a raster calculator
          1. Raster 101
          2. Operating with pixels
        9. Creating a convolution matrix
          1. How convolution works
          2. Converting an image to 8-bit
          3. Implementing the Sobel filter
          4. Normalizing an image
          5. Finalizing a control
        10. Clipping a layer with WebGL
          1. Writing programs
          2. Creating a clipping mask
        11. Summary
      15. 8. OpenLayers 3 for Mobile
        1. Before getting started
          1. Basic considerations
        2. Responsive styling with CSS
          1. Writing the style sheet
          2. Constructing the map
        3. Generating geocaches
        4. Adding device-dependent controls
          1. Adding controls for touch devices
          2. Adding controls for desktop computers
        5. Vectorizing the mobile version
        6. Making the mobile application interactive
        7. Summary
      16. 9. Tools of the Trade – Integrating Third-Party Applications
        1. Before getting started
        2. Exporting a QGIS project
          1. Installing the qgis2web plugin
          2. Inspecting the project
          3. Exporting a map
          4. Salvaging the results
        3. Importing shapefiles
          1. Editing the HTML file
          2. Replacing a function
        4. Spatial analysis with Turf
          1. Preparing an example
          2. Implementing a buffer operation
          3. Implementing a merge operation
          4. Implementing the self-intersect operation
        5. Spatial analysis with JSTS
          1. Implementing operations
        6. 3D rendering with Cesium
          1. Preparing a map
          2. Creating a control
          3. Observing a terrain
          4. Extending the Cesium scene
        7. Summary
      17. 10. Compiling Custom Builds with Closure
        1. Before getting started
        2. Configuring Node JS
          1. Installing Node JS on Windows
          2. Installing Node JS on Linux
          3. Resolving dependencies
        3. Compiling OpenLayers 3
          1. Building default versions
          2. Understanding a configuration file
          3. Building OpenLayers 3 with a subset of features
        4. Bundling an application with OpenLayers 3
          1. Editing the application
          2. Creating a configuration file
          3. Fixing the application
        5. Extending OpenLayers 3
        6. Creating rich documentation with JSDoc
          1. Customizing the documentation
        7. Summary
      18. Index