OpenLayers.Layer

Summary
OpenLayers.Layer
Properties
id{String}
name{String}
div{DOMElement}
alwaysInRange{Boolean} If a layer’s display should not be scale-based, this should be set to true.
Constants
EVENT_TYPES{Array(String)} Supported application event types.
Properties
events{OpenLayers.Events}
map{OpenLayers.Map} This variable is set when the layer is added to the map, via the accessor function setMap().
isBaseLayer{Boolean} Whether or not the layer is a base layer.
displayInLayerSwitcher{Boolean} Display the layer’s name in the layer switcher.
visibility{Boolean} The layer should be displayed in the map.
attribution{String} Attribution string, displayed when an OpenLayers.Control.Attribution has been added to the map.
eventListeners{Object} If set as an option at construction, the eventListeners object will be registered with <OpenLayers.Events.on>.
gutter{Integer} Determines the width (in pixels) of the gutter around image tiles to ignore.
projection{OpenLayers.Projection} or {String} Set in the layer options to override the default projection string this layer - also set maxExtent, maxResolution, and units if appropriate.
units{String} The layer map units.
scales{Array} An array of map scales in descending order.
resolutions{Array} A list of map resolutions (map units per pixel) in descending order.
maxExtent{OpenLayers.Bounds} The center of these bounds will not stray outside of the viewport extent during panning.
minExtent{OpenLayers.Bounds}
maxResolution{Float} Default max is 360 deg / 256 px, which corresponds to zoom level 0 on gmaps.
minResolution{Float}
numZoomLevels{Integer}
minScale{Float}
maxScale{Float}
displayOutsideMaxExtent{Boolean} Request map tiles that are completely outside of the max extent for this layer.
wrapDateLine{Boolean} #487 for more info.
transitionEffect{String} The transition effect to use when the map is panned or zoomed.
Constructor
OpenLayers.Layer
Functions
setNameSets the new layer name for this layer.
addOptions
onMapResizeThis function can be implemented by subclasses
redrawRedraws the layer.
removeMapJust as setMap() allows each layer the possibility to take a personalized action on being added to the map, removeMap() allows each layer to take a personalized action on being removed from it.
getImageSize{OpenLayers.Size} The size that the image should be, taking into account gutters.
setTileSizeSet the tile size based on the map size.
getVisibility{Boolean} The layer should be displayed (if in range).
setVisibilitySet the visibility flag for the layer and hide/show & redraw accordingly.
displayHide or show the Layer
calculateInRange{Boolean} The layer is displayable at the current map’s current resolution.
setIsBaseLayer
getResolution{Float} The currently selected resolution of the map, taken from the resolutions array, indexed by current zoom level.
getExtent{OpenLayers.Bounds} A Bounds object which represents the lon/lat bounds of the current viewPort.
getZoomForExtent
getResolutionForZoom
getZoomForResolution
getLonLatFromViewPortPx
getViewPortPxFromLonLatReturns a pixel location given a map location.
setOpacitySets the opacity for the entire layer (all images)

Properties

id

{String}

name

{String}

div

{DOMElement}

alwaysInRange

{Boolean} If a layer’s display should not be scale-based, this should be set to true.  This will cause the layer, as an overlay, to always be ‘active’, by always returning true from the calculateInRange() function.

If not explicitly specified for a layer, its value will be determined on startup in initResolutions() based on whether or not any scale-specific properties have been set as options on the layer.  If no scale-specific options have been set on the layer, we assume that it should always be in range.

See #987 for more info.

Constants

EVENT_TYPES

{Array(String)} Supported application event types.  Register a listener for a particular event with the following syntax:

layer.events.register(type, obj, listener);

Listeners will be called with a reference to an event object.  The properties of this event depends on exactly what happened.

All event objects have at least the following properties

object{Object} A reference to layer.events.object.
element{DOMElement} A reference to layer.events.element.

Supported map event types

loadstartTriggered when layer loading starts.
loadendTriggered when layer loading ends.
loadcancelTriggered when layer loading is canceled.
visibilitychangedTriggered when layer visibility is changed.
moveTriggered when layer moves (triggered with every mousemove during a drag).
moveendTriggered when layer is done moving, object passed as argument has a zoomChanged boolean property which tells that the zoom has changed.

Properties

map

{OpenLayers.Map} This variable is set when the layer is added to the map, via the accessor function setMap().

isBaseLayer

{Boolean} Whether or not the layer is a base layer.  This should be set individually by all subclasses.  Default is false

displayInLayerSwitcher

{Boolean} Display the layer’s name in the layer switcher.  Default is true.

visibility

{Boolean} The layer should be displayed in the map.  Default is true.

attribution

{String} Attribution string, displayed when an OpenLayers.Control.Attribution has been added to the map.

eventListeners

{Object} If set as an option at construction, the eventListeners object will be registered with <OpenLayers.Events.on>.  Object structure must be a listeners object as shown in the example for the events.on method.

gutter

{Integer} Determines the width (in pixels) of the gutter around image tiles to ignore.  By setting this property to a non-zero value, images will be requested that are wider and taller than the tile size by a value of 2 x gutter.  This allows artifacts of rendering at tile edges to be ignored.  Set a gutter value that is equal to half the size of the widest symbol that needs to be displayed.  Defaults to zero.  Non-tiled layers always have zero gutter.

projection

{OpenLayers.Projection} or {String} Set in the layer options to override the default projection string this layer - also set maxExtent, maxResolution, and units if appropriate.  Can be either a string or an OpenLayers.Projection object when created -- will be converted to an object when setMap is called if a string is passed.

units

{String} The layer map units.  Defaults to ‘degrees’.  Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’.

scales

{Array} An array of map scales in descending order.  The values in the array correspond to the map scale denominator.  Note that these values only make sense if the display (monitor) resolution of the client is correctly guessed by whomever is configuring the application.  In addition, the units property must also be set.  Use resolutions instead wherever possible.

resolutions

{Array} A list of map resolutions (map units per pixel) in descending order.  If this is not set in the layer constructor, it will be set based on other resolution related properties (maxExtent, maxResolution, maxScale, etc.).

maxExtent

{OpenLayers.Bounds} The center of these bounds will not stray outside of the viewport extent during panning.  In addition, if displayOutsideMaxExtent is set to false, data will not be requested that falls completely outside of these bounds.

maxResolution

{Float} Default max is 360 deg / 256 px, which corresponds to zoom level 0 on gmaps.  Specify a different value in the layer options if you are not using a geographic projection and displaying the whole world.

minResolution

{Float}

numZoomLevels

{Integer}

minScale

{Float}

maxScale

{Float}

displayOutsideMaxExtent

{Boolean} Request map tiles that are completely outside of the max extent for this layer.  Defaults to false.

wrapDateLine

{Boolean} #487 for more info.

transitionEffect

{String} The transition effect to use when the map is panned or zoomed.

There are currently two supported values

  • null No transition effect (the default).
  • resize Existing tiles are resized on zoom to provide a visual effect of the zoom having taken place immediately.  As the new tiles become available, they are drawn over top of the resized tiles.

Constructor

OpenLayers.Layer

Parameters

name{String} The layer name
options{Object} Hashtable of extra options to tag onto the layer

Functions

setName

setName: function(newName)

Sets the new layer name for this layer.  Can trigger a changelayer event on the map.

Parameters

newName{String} The new name.

addOptions

addOptions: function (newOptions)

Parameters

newOptions{Object}

onMapResize

onMapResize: function()

This function can be implemented by subclasses

redraw

redraw: function()

Redraws the layer.  Returns true if the layer was redrawn, false if not.

Returns

{Boolean} The layer was redrawn.

removeMap

removeMap: function(map)

Just as setMap() allows each layer the possibility to take a personalized action on being added to the map, removeMap() allows each layer to take a personalized action on being removed from it.  For now, this will be mostly unused, except for the EventPane layer, which needs this hook so that it can remove the special invisible pane.

Parameters

map{OpenLayers.Map}

getImageSize

getImageSize: function()

Returns

{OpenLayers.Size} The size that the image should be, taking into account gutters.

setTileSize

setTileSize: function(size)

Set the tile size based on the map size.  This also sets layer.imageSize and layer.imageOffset for use by Tile.Image.

Parameters

size{OpenLayers.Size}

getVisibility

getVisibility: function()

Returns

{Boolean} The layer should be displayed (if in range).

setVisibility

setVisibility: function(visibility)

Set the visibility flag for the layer and hide/show & redraw accordingly.  Fire event unless otherwise specified

Note that visibility is no longer simply whether or not the layer’s style.display is set to “block”.  Now we store a ‘visibility’ state property on the layer class, this allows us to remember whether or not we desire for a layer to be visible.  In the case where the map’s resolution is out of the layer’s range, this desire may be subverted.

Parameters

visible{Boolean} Whether or not to display the layer (if in range)

display

display: function(display)

Hide or show the Layer

Parameters

display{Boolean}

calculateInRange

calculateInRange: function()

Returns

{Boolean} The layer is displayable at the current map’s current resolution.  Note that if ‘alwaysInRange’ is true for the layer, this function will always return true.

setIsBaseLayer

setIsBaseLayer: function(isBaseLayer)

Parameters

isBaseLayer{Boolean}

getResolution

getResolution: function()

Returns

{Float} The currently selected resolution of the map, taken from the resolutions array, indexed by current zoom level.

getExtent

getExtent: function()

Returns

{OpenLayers.Bounds} A Bounds object which represents the lon/lat bounds of the current viewPort.

getZoomForExtent

getZoomForExtent: function(extent,
closest)

Parameters

bounds{OpenLayers.Bounds}
closest{Boolean} Find the zoom level that most closely fits the specified bounds.  Note that this may result in a zoom that does not exactly contain the entire extent.  Default is false.

Returns

{Integer} The index of the zoomLevel (entry in the resolutions array) for the passed-in extent.  We do this by calculating the ideal resolution for the given extent (based on the map size) and then calling getZoomForResolution(), passing along the ‘closest’ parameter.

getResolutionForZoom

getResolutionForZoom: function(zoom)

Parameter

zoom{Float}

Returns

{Float} A suitable resolution for the specified zoom.

getZoomForResolution

getZoomForResolution: function(resolution,
closest)

Parameters

resolution{Float}
closest{Boolean} Find the zoom level that corresponds to the absolute closest resolution, which may result in a zoom whose corresponding resolution is actually smaller than we would have desired (if this is being called from a getZoomForExtent() call, then this means that the returned zoom index might not actually contain the entire extent specified... but it’ll be close).  Default is false.

Returns

{Integer} The index of the zoomLevel (entry in the resolutions array) that corresponds to the best fit resolution given the passed in value and the ‘closest’ specification.

getLonLatFromViewPortPx

getLonLatFromViewPortPx: function (viewPortPx)

Parameters

viewPortPx{OpenLayers.Pixel}

Returns

{OpenLayers.LonLat} An OpenLayers.LonLat which is the passed-in view port OpenLayers.Pixel, translated into lon/lat by the layer.

getViewPortPxFromLonLat

getViewPortPxFromLonLat: function (lonlat)

Returns a pixel location given a map location.  This method will return fractional pixel values.

Parameters

lonlat{OpenLayers.LonLat}

Returns

{OpenLayers.Pixel} An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,translated into view port pixels.

setOpacity

setOpacity: function(opacity)

Sets the opacity for the entire layer (all images)

Parameter

opacity{Float}
Instances of OpenLayers.Map are interactive maps embedded in a web page.
The attribution control adds attribution from layers to the map display.
Class for coordinate transforms between coordinate systems.
Contains convenience functions for string manipulation.
Instances of this class represent bounding boxes.
setName: function(newName)
Sets the new layer name for this layer.
addOptions: function (newOptions)
onMapResize: function()
This function can be implemented by subclasses
redraw: function()
Redraws the layer.
removeMap: function(map)
Just as setMap() allows each layer the possibility to take a personalized action on being added to the map, removeMap() allows each layer to take a personalized action on being removed from it.
getImageSize: function()
{OpenLayers.Size} The size that the image should be, taking into account gutters.
Instances of this class represent a width/height pair
setTileSize: function(size)
Set the tile size based on the map size.
getVisibility: function()
{Boolean} The layer should be displayed (if in range).
setVisibility: function(visibility)
Set the visibility flag for the layer and hide/show & redraw accordingly.
display: function(display)
Hide or show the Layer
calculateInRange: function()
{Boolean} The layer is displayable at the current map’s current resolution.
setIsBaseLayer: function(isBaseLayer)
getResolution: function()
{Float} The currently selected resolution of the map, taken from the resolutions array, indexed by current zoom level.
getExtent: function()
{OpenLayers.Bounds} A Bounds object which represents the lon/lat bounds of the current viewPort.
getZoomForExtent: function(extent,
closest)
getResolutionForZoom: function(zoom)
getZoomForResolution: function(resolution,
closest)
getLonLatFromViewPortPx: function (viewPortPx)
getViewPortPxFromLonLat: function (lonlat)
Returns a pixel location given a map location.
setOpacity: function(opacity)
Sets the opacity for the entire layer (all images)
{Array} A list of map resolutions (map units per pixel) in descending order.
{Boolean} Request map tiles that are completely outside of the max extent for this layer.
This class represents a screen coordinate, in x and y coordinates
This class represents a longitude and latitude pair
Close