OpenLayers OpenLayers

Creating A BaseLayer

For a Layer to function properly as a BaseLayer, it must:

  • Have its isBaseLayer property set to true.
  • Expose the following functions:
    • initResolutions()
    • getResolution()
    • getExtent()
    • getZoomForExtent()
    • getZoomForResolution()
    • getLonLatFromViewPortPx()
    • getViewPortPxFromLonLat()

All of the above functions are defined in OpenLayers.Layer?. Thus, any Layer which subclasses off of OpenLayers.Layer? automatically has all the necessary functionality to be a BaseLayer.

The only caveat, however, is that this new Layer must be able to draw itself in any resolution.

For Layers like OpenLayers.Layer.WMS, this is no problem.

When trying to implement 3rd Party Layers? like Google Maps or Virtual Earth, however, the luxury of being able to render at any resolution is no longer available: we are limited to the predefined zoom levels (resolutions) that the APIs expose.

For more information on Scale, Resolution, and how they translate into Zoom Levels, see SettingZoomLevels

Because these 3rd Party Layers? often do not directly expose the resolutions or scales which correspond to their ZoomLevels, we need a different way to calculate the resolution of a given zoomLevel and also a way to recommend a ZoomLevel for a specified Extent or Resolution.

To do this, we have created the pseudo-layer OpenLayers.Layer.FixedZoomLevels

By subclassing off of OpenLayers.Layer.FixedZoomLevels, any Layer can act as a BaseLayer, providing it overrides the following functions:

  • getLonLatFromViewPortPx()
  • getViewPortPxFromLonLat()
  • getZoomForExtent()

By providing special implementations of the above three functions, OpenLayers.Layer.FixedZoomLevels takes care of all the rest of the calculation, such that all of the functions mentioned at the very top of this page work correctly and return proper values.

For a more detailed description of how the library works, see OpenLayers.Layer.FixedZoomLevels