Table of Contents for
OpenLayers 3.x Cookbook - Second Edition

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition OpenLayers 3.x Cookbook - Second Edition by Antonio Santiago Perez Published by Packt Publishing, 2016
  1. Cover
  2. Table of Contents
  3. OpenLayers 3.x Cookbook Second Edition
  4. OpenLayers 3.x Cookbook Second Edition
  5. Credits
  6. About the Authors
  7. About the Reviewer
  8. www.PacktPub.com
  9. Preface
  10. What you need for this book
  11. Who this book is for
  12. Sections
  13. Conventions
  14. Reader feedback
  15. Customer support
  16. 1. Web Mapping Basics
  17. Creating a simple fullscreen map
  18. Playing with the map's options
  19. Managing the map's stack layers
  20. Managing the map's controls
  21. Moving around the map view
  22. Restricting the map's extent
  23. 2. Adding Raster Layers
  24. Using Bing imagery
  25. Using OpenStreetMap imagery
  26. Adding WMS layers
  27. Changing the zoom effect
  28. Changing layer opacity
  29. Buffering the layer data to improve map navigation
  30. Creating an image layer
  31. Setting the tile size in WMS layers
  32. 3. Working with Vector Layers
  33. Adding a GML layer
  34. Adding a KML layer
  35. Creating features programmatically
  36. Exporting features as GeoJSON
  37. Reading and creating features from a WKT
  38. Using point features as markers
  39. Removing or cloning features using overlays
  40. Zooming to the extent of a layer
  41. Adding text labels to geometry points
  42. Adding features from a WFS server
  43. Using the cluster strategy
  44. Reading features directly using AJAX
  45. Creating a heat map
  46. 4. Working with Events
  47. Creating a side-by-side map comparator
  48. Implementing a work-in-progress indicator for map layers
  49. Listening for the vector layer features' events
  50. Listening for mouse or touch events
  51. Using the keyboard to pan or zoom
  52. 5. Adding Controls
  53. Adding and removing controls
  54. Working with geolocation
  55. Placing controls outside the map
  56. Drawing features across multiple vector layers
  57. Modifying features
  58. Measuring distances and areas
  59. Getting feature information from a data source
  60. Getting information from a WMS server
  61. 6. Styling Features
  62. Styling layers
  63. Styling features based on geometry type
  64. Styling based on feature attributes
  65. Styling interaction render intents
  66. Styling clustered features
  67. 7. Beyond the Basics
  68. Working with projections
  69. Creating a custom control
  70. Selecting features by dragging out a selection area
  71. Transitioning between weather forecast imagery
  72. Using the custom OpenLayers library build
  73. Drawing in freehand mode
  74. Modifying layer appearance
  75. Adding features to the vector layer by dragging and dropping them
  76. Making use of map permalinks
  77. Index

Chapter 3. Working with Vector Layers

In this chapter, we will cover the following topics:

  • Adding a GML layer
  • Adding a KML layer
  • Creating features programmatically
  • Exporting features as GeoJSON
  • Reading and creating features from a WKT
  • Using point features as markers
  • Removing or cloning features using overlays
  • Zooming to the extent of a layer
  • Adding text labels to geometry points
  • Adding features from a WFS server
  • Using the cluster strategy
  • Reading features directly using AJAX
  • Creating a heat map

Introduction

This chapter talks about vector layers. In addition to raster imagery, vector information is the other important type of data that we can work with in a GIS system. Throughout the coming recipes, we'll summarize the most common and important concepts that you may need to work with in OpenLayers.

Note

We will make some AJAX requests during this chapter. If you're following along with this book's source code, then be sure to download and install Node.js (https://nodejs.org) and follow the README.md instructions.

In GIS, a real-world phenomenon is represented by the concept of a feature. This can be a place, such as a city or a village; it can be a road or a railway, it can be a region, a lake, the border of a country, or something entirely arbitrary.

Features can have a set of attributes, such as population, length, and so on. These can be represented visually through the use of points, lines, polygons, and so on, using some visual style: color, radius, width, and so on.

As you can see, there are many concepts to take into account when working with vector information. Fortunately, OpenLayers provides an extensive range of feature-related classes to work with. We will learn more about these in this chapter.

The base class for vector layers is ol.layer.Vector, which defines the common properties and methods. Most of these are inherited from ol.layer.Base. The vector layer's properties and methods share close similarities with the ol.layer.Tile class, which we've explored in detail in Chapter 2, Adding Raster Layers.

The vector layer class requires a source of ol.source.Vector, in the same way as the raster layers do. The vector source expects a set of features, which can come in numerous formats (GeoJSON, GML, or an OpenLayers-specific type of ol.geom, and so on). These features are converted to the ol.Feature types when added to the layer.

Each feature can contain custom attribute properties, and it will typically have a single geometry. Features can also be individually styled, or they can inherit styles through cascading methods. We'll explore many of the methods that the ol.Feature class has to offer.

In addition to representation onscreen, we need to take into account the data source. OpenLayers offers classes to read/write features from/to many sources or protocols in different formats, such as GML, KML, GeoJSON, WKT, and so on.

Additionally, the vector layer can utilize different feature loading strategies, such as load all features onto the map in one go, load features based on the current extent, and so on.

Without further ado, let's discover and embrace the capabilities of vector layers and features.