Chapter 3. Working with Vector Layers

In this chapter we cover:

  • Adding a GML layer
  • Adding KML layer
  • Creating features programmatically
  • Reading and creating features from a WKT
  • Adding markers to the map
  • Using point features as markers
  • Working with popups
  • Adding features from a WFS server
  • Using the cluster strategy
  • Filtering features in WFS requests
  • Reading features directly using Protocols

Introduction

This chapter talks about vector layers. In addition to raster, vector information is the other important type of information we can work with in a GIS system.

The chapter tries to summarize the most common and important recipes you may need to work with in OpenLayers.

In GIS, a real-world phenomenon is represented by the concept of a feature. It can be a place—like 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 similar.

Every feature has a set of attributes: population, length, and so on. It is represented visually by a geometrical symbol: point, line, polygon, 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 us classes to work with them. We will learn more about these in this chapter.

The base class for vector layers is OpenLayers.Layer.Vector class, which defines the common properties and behavior for all the subclasses.

The OpenLayers.Layer.Vector class contains a set of features. These features are instances of the OpenLayers.Feature.Vector subclasses (which, in fact, are inherited from a more generic OpenLayers.Feature class).

Each feature has an attributes property and an OpenLayers.Geometry class instance associated with it.

The vector layer itself or each feature can have a visual style associated with it, which will be used to render the feature on the map.

In addition to the representation on the screen, we need to take into account the data source. OpenLayers offers classes to read/write features from/to many sources, or protocols, and using different formats: GML, KML, GeoJSON, GeoRSS, and so on.

The vector layer has optionally associated an instance of the OpenLayers.Protocol class and a list of instances of the OpenLayers.Strategy class. The first is responsible to read/write data using some protocol, such as HTTP or WFS, while the second (the strategy) is responsible to control tasks such as when to load or refresh the data in the layer: only once, every time the layer is moved, every few seconds, and so on.

Let's get started and see these classes in action.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.12.232