OpenLayers OpenLayers

Table Of Contents

Previous topic

Understanding OpenLayers Syntax

Next topic

Controls

This Page

Layers

Layers are the ‘datasources’ in OpenLayers.

Base Layers and Non-Base Layers

OpenLayers has two types of layers when operating in your application: base layers and overlays. This difference controls several aspects of how you interact with an OpenLayers Map.

Base Layers

Base Layers are mutually exclusive layers, meaning only one can be enabled at any given time. The currently active base layer determines the available projection (coordinate system) and zoom levels available on the map.

Whether a layer is a base layer or not is determined by the isBaseLayer property on the layer. Most raster layers have the isBaseLayer property set to true by default. It can be changed in the layer options.

Base Layers always display below overlay layers.

Non Base Layers

Non base layers – sometimes called overlays – are the alternative to Base Layers. Multiple non-base layer can be enabled at a time. These layers do not control the zoom levels of the map, but can be enabled or disabled at certain scales by min/max scale/resolution parameters so that they are only enabled at a certain level.

Some types of overlays support reprojection to the base layer projection at layer load time. Most overlay layers default to non-base overlays, as does the base Layer class. Non-base Layers always display above base layers.

Raster Layers

Raster Layers are imagery layers. These layers are typically in a fixed projection which can not be changed on the client side.

Google

Layer for using Google Maps data within OpenLayers. For API information, see the Google Layer API Docs. For an example of usage, see the Spherical Mercator example.

If you are overlaying other data on a Google Maps base layer, you will want to be interacting with the Google Maps layer in projected coordinates. (This is important if you are working with imagery data especially.) You can read more about the ‘Spherical Mercator’ projection that Google Maps – and other commercial layers – use in the Spherical Mercator documentation.

The Google Layer class is designed to be used only as a base layer.

Image

For API information, see the Image Layer API Docs.

KaMap

For API information, see the KaMap Layer API Docs.

KaMapCache

For API information, see the KaMapCache Layer API Docs.

MapGuide

For API information, see the MapGuide Layer API Docs.

MapServer

This layer is not required to interact with MapServer. In general, the WMS Layer is preferred over the MapServer Layer. Since MapServer exposes most of its CGI functionality in WMS mode as well, the WMS layer is preferred. The MapServer layer can often lead to maps which seem to work, but don’t due to projection issues or other similar misconfigurations. Unless you have a strong reason not to, you should use the Layer.WMS instead of a Layer.MapServer.

If you are using a Layer.MapServer, and your map is being repeated several times, this indicates that you have not properly configured your map to be in a different projection. OpenLayers can not read this information from your mapfile, and it must be configured explicitly. The FAQ on setting different projection properties provides information on how to configure different projections in OpenLayers.

For API information, see the MapServer Layer API Docs.

MultiMap

For API information, see the MultiMap Layer API Docs.

TMS

For API information, see the TMS Layer API Docs.

TileCache

For API information, see the TileCache Layer API Docs.

VirtualEarth

For API information, see the VirtualEarth Layer API Docs.

WMS

Layer type for accessing data served according to the Web Mapping Service standard.

For API information, see the WMS Layer API Docs.

WorldWind

For API information, see the WorldWind Layer API Docs.

Yahoo

For API information, see the Yahoo Layer API Docs.

Overlay Layers

Overlay layers are any layers that have their source data in a format other than imagery. This includes subclasses of both Markers Layers and Vector Layers. For more information on the differences between these two base classes, see the Overlays documentation.

Boxes

Based on subclassing markers. In general, it is probably better to implement this functionality with a Vectors layer and polygon geometries. Maintained for backwards compatibility.

For API information, see the Boxes Layer API Docs.

GML

The GML layer is a vector layer subclass designed to read data from a file once and display it. It is ideal for working with many formats, not just GML, and can be configured to read other formats via the ‘format’ option on the layer.

The simplest use case of the GML layer is simply to load a GML file. The GML Layer Example shows this: simply add:

var layer = new OpenLayers.Layer.GML("GML", "gml/polygon.xml")
map.addLayer(layer);

If you want to add a different type of format, you can change the format option of the layer at initialization. The KML example demonstrates this:

var layer = new OpenLayers.Layer.GML("KML", "kml/lines.kml", {
   format: OpenLayers.Format.KML
})
map.addLayer(layer);

You can also add formatOption to the layer: these options are used when creating the format class internally to the layer.

var layer = new OpenLayers.Layer.GML("KML", "kml/lines.kml", {
   format: OpenLayers.Format.KML,
   formatOptions: {
     'extractStyles': true
   }
});
map.addLayer(layer);

The format options are determined by the format class.

For API information, see the GML Layer API Docs.

GeoRSS

The GeoRSS layer uses the GeoRSS format, and displays the results as clickable markers. It is a subclass of the Markers layer, and does not support lines or polygons. It has many hardcoded behaviors, and in general, you may be better off using a GML layer with a SelectFeature Control instead of the GeoRSS layer if you want configurability of your application behavior. (For more information on how to make that transition, see Transitioning from Text Layer or GeoRSS Layer to Vectors.)

For API information, see the GeoRSS Layer API Docs.

Markers

The Markers base layer is simple, and allows use of the addMarkers function to add markers to the layer. It supports only points, not lines or polygons.

For API information, see the Markers Layer API Docs.

PointTrack

For API information, see the PointTrack Layer API Docs.

Text

The Text layer uses the Text format, and displays the results as clickable markers. It is a subclass of the Markers layer, and does not support lines or polygons. It has many hardcoded behaviors, and in general, you may be better off using a GML layer with a SelectFeature Control instead of the Text layer if you want configurability of your application behavior. (For more information on how to make that transition, see Transitioning from Text Layer or GeoRSS Layer to Vectors.)

For API information, see the Text Layer API Docs.

Vector

The Vector Layer is the basis of the advanced geometry support in OpenLayers. Classes like GML and WFS subclass from the Vector layer. When creating features in JavaScript code, using the Vector layer directly is likely a good way to go.

As of OpenLayers 2.7, development has begun on extending the Vector Layer to have additional capabilities for loading data, to replace the large number of layer subclasses. This work on Strategy and Protocol classes is designed to make it easier to interact with data from remote datasources. For more information on Protocols and Strategies, see the OpenLayers API documentation.

For API information, see the Vector Layer API Docs.

WFS

For API information, see the WFS Layer API Docs.

Generic Subclasses

  • EventPane
  • FixedZoomLevels
  • Grid
  • HTTPRequest
  • SphericalMercator