OpenLayers.Map - OpenLayers

# OpenLayers.Map

Instances of OpenLayers.Map are interactive maps embedded in a web page. Create a new map with the OpenLayers.Map constructor.

On their own maps do not provide much functionality. To extend a map it’s necessary to add controls (OpenLayers.Control) and layers (OpenLayers.Layer) to the map.

Summary

OpenLayers.Map | Instances of OpenLayers.Map are interactive maps embedded in a web page.
Constants |
Z_INDEX_BASE | {Object} Base z-indexes for different classes of thing
Properties |
events | {OpenLayers.Events}
id | {String} Unique identifier for the map
fractionalZoom | {Boolean} For a base layer that supports it, allow the map resolution to be set to a value between one of the values in the resolutions array.
events | {OpenLayers.Events} An events object that handles all events on the map
allOverlays | {Boolean} Allow the map to function with “overlays” only.
div | {DOMElement|String} The element that contains the map (or an id for that element).
dragging | {Boolean} The map is currently being dragged.
size | {OpenLayers.Size} Size of the main div (this.div)
viewPortDiv | {HTMLDivElement} The element that represents the map viewport
layerContainerOrigin | {OpenLayers.LonLat} The lonlat at which the later container was re-initialized (on-zoom)
layerContainerDiv | {HTMLDivElement} The element that contains the layers.
layers | {Array(OpenLayers.Layer)} Ordered list of layers in the map
controls | {Array(OpenLayers.Control)} List of controls associated with the map.
popups | {Array(OpenLayers.Popup)} List of popups associated with the map
baseLayer | {OpenLayers.Layer} The currently selected base layer.
center | {OpenLayers.LonLat} The current center of the map
resolution | {Float} The resolution of the map.
zoom | {Integer} The current zoom level of the map
panRatio | {Float} The ratio of the current extent within which panning will tween.
options | {Object} The options object passed to the class constructor.
tileSize | {OpenLayers.Size} Set in the map options to override the default tile size for this map.
projection | {String} Set in the map options to specify the default projection for layers added to this map.
units | {String} The map units.
resolutions | {Array(Float)} A list of map resolutions (map units per pixel) in descending order.
maxResolution | {Float} Required if you are not displaying the whole world on a tile with the size specified in tileSize.
minResolution | {Float}
maxScale | {Float}
minScale | {Float}
maxExtent | {<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top).
minExtent | {<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top).
restrictedExtent | {<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top).
numZoomLevels | {Integer} Number of zoom levels for the map.
theme | {String} Relative path to a CSS file from which to load theme styles.
displayProjection | {OpenLayers.Projection} Requires proj4js support for projections other than EPSG:4326 or EPSG:900913/EPSG:3857.
tileManager | {<OpenLayers.TileManager>|Object} By default, and if the build contains TileManager.js, the map will use the TileManager to queue image requests and to cache tile image elements.
fallThrough | {Boolean} Should OpenLayers allow events on the map to fall through to other elements on the page, or should it swallow them?
autoUpdateSize | {Boolean} Should OpenLayers automatically update the size of the map when the resize event is fired.
eventListeners | {Object} If set as an option at construction, the eventListeners object will be registered with OpenLayers.Events.on.
panTween | {OpenLayers.Tween} Animated panning tween object, see panTo()
panMethod | {Function} The Easing function to be used for tweening.
panDuration | {Integer} The number of steps to be passed to the OpenLayers.Tween.start() method when the map is panned.
zoomTween | {OpenLayers.Tween} Animated zooming tween object, see zoomTo()
zoomMethod | {Function} The Easing function to be used for tweening.
zoomDuration | {Integer} The number of steps to be passed to the OpenLayers.Tween.start() method when the map is zoomed.
paddingForPopups | {OpenLayers.Bounds} Outside margin of the popup.
layerContainerOriginPx | {Object} Cached object representing the layer container origin (in pixels).
minPx | {Object} An object with a ‘x’ and ‘y’ values that is the lower left of maxExtent in viewport pixel space.
maxPx | {Object} An object with a ‘x’ and ‘y’ values that is the top right of maxExtent in viewport pixel space.
Constructor |
OpenLayers.Map | Constructor for a new OpenLayers.Map instance.
Functions |
getViewport | Get the DOMElement representing the view port.
render | Render the map to a specified container.
unloadDestroy | Function that is called to destroy the map on page unload.
updateSizeDestroy | When the map is destroyed, we need to stop listening to updateSize events: this method stores the function we need to unregister in non-IE browsers.
destroy | Destroy this map.
setOptions | Change the map options
getTileSize | Get the tile size for the map
getBy | Get a list of objects given a property and a match item.
getLayersBy | Get a list of layers with properties matching the given criteria.
getLayersByName | Get a list of layers with names matching the given name.
getLayersByClass | Get a list of layers of a given class (CLASS_NAME).
getControlsBy | Get a list of controls with properties matching the given criteria.
getControlsByClass | Get a list of controls of a given class (CLASS_NAME).
getLayer | Get a layer based on its id
setLayerZIndex |
resetLayersZIndex | Reset each layer’s z-index based on layer’s array index
addLayer |
addLayers |
removeLayer | Removes a layer from the map by removing its visual element (the layer.div property), then removing it from the map’s internal list of layers, setting the layer’s map property to null.
getNumLayers | {Int} The number of layers attached to the map.
getLayerIndex |
setLayerIndex | Move the given layer to the specified (zero-based) index in the layer list, changing its z-index in the map display.
raiseLayer | Change the index of the given layer by delta.
setBaseLayer | Allows user to specify one of the currently-loaded layers as the Map’s new base layer.
addControl | Add the passed over control to the map.
addControls | Add all of the passed over controls to the map.
addControlToMap |
getControl |
removeControl | Remove a control from the map.
addPopup |
removePopup |
getSize | {OpenLayers.Size} An OpenLayers.Size object that represents the size, in pixels, of the div into which OpenLayers has been loaded.
updateSize | This function should be called by any external code which dynamically changes the size of the map div (because mozilla wont let us catch the “onresize” for an element)
getCurrentSize | {OpenLayers.Size} A new OpenLayers.Size object with the dimensions of the map div
calculateBounds |
getCenter | {OpenLayers.LonLat}
getCachedCenter | {OpenLayers.LonLat}
getZoom | {Integer}
pan | Allows user to pan by a value of screen pixels
panTo | Allows user to pan to a new lonlat If the new lonlat is in the current extent the map will slide smoothly
setCenter | Set the map center (and optionally, the zoom level).
moveByPx | Drag the map by pixels.
adjustZoom |
getMinZoom | Returns the minimum zoom level for the current map view.
moveTo |
centerLayerContainer | This function takes care to recenter the layerContainerDiv.
isValidZoomLevel |
isValidLonLat |
getProjection | This method returns a string representing the projection.
getProjectionObject | Returns the projection obect from the baselayer.
getMaxResolution | {String} The Map’s Maximum Resolution
getMaxExtent |
getNumZoomLevels | {Integer} The total number of zoom levels that can be displayed by the current baseLayer.
getExtent | {OpenLayers.Bounds} A Bounds object which represents the lon/lat bounds of the current viewPort.
getResolution | {Float} The current resolution of the map.
getUnits | {Float} The current units of the map.
getScale | {Float} The current scale denominator of the map.
getZoomForExtent |
getResolutionForZoom |
getZoomForResolution |
zoomTo | Zoom to a specific zoom level.
zoomIn |
zoomOut |
zoomToExtent | Zoom to the passed in bounds, recenter
zoomToMaxExtent | Zoom to the full extent and recenter.
zoomToScale | Zoom to a specified scale
getLonLatFromViewPortPx |
getViewPortPxFromLonLat |
getZoomTargetCenter |
getLonLatFromPixel |
getPixelFromLonLat | Returns a pixel location given a map location.
getGeodesicPixelSize |
getViewPortPxFromLayerPx |
getLayerPxFromViewPortPx |
getLonLatFromLayerPx |
getLayerPxFromLonLat |
applyTransform | Applies the given transform to the layerContainerDiv.
Constants |
TILE_WIDTH | {Integer} 256 Default tile width (unless otherwise specified)
TILE_HEIGHT | {Integer} 256 Default tile height (unless otherwise specified)

### Constants

### Z_INDEX_BASE

{Object} Base z-indexes for different classes of thing

### Properties

### events

{OpenLayers.Events}

#### Register a listener for a particular event with the following syntax

>     map.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 map.events.object.
element | {DOMElement} A reference to map.events.element.

#### Browser events have the following additional properties

xy | {OpenLayers.Pixel} The pixel location of the event (relative to the the map viewport).

#### Supported map event types

preaddlayer | triggered before a layer has been added. The event object will include a layer property that references the layer to be added. When a listener returns “false” the adding will be aborted.
addlayer | triggered after a layer has been added. The event object will include a layer property that references the added layer.
preremovelayer | triggered before a layer has been removed. The event object will include a layer property that references the layer to be removed. When a listener returns “false” the removal will be aborted.
removelayer | triggered after a layer has been removed. The event object will include a layer property that references the removed layer.
changelayer | triggered after a layer name change, order change, opacity change, params change, visibility change (actual visibility, not the layer’s visibility property) or attribution change (due to extent change). Listeners will receive an event object with layer and property properties. The layer property will be a reference to the changed layer. The property property will be a key to the changed property (name, order, opacity, params, visibility or attribution).
movestart | triggered after the start of a drag, pan, or zoom. The event object may include a zoomChanged property that tells whether the zoom has changed.
move | triggered after each drag, pan, or zoom
moveend | triggered after a drag, pan, or zoom completes
zoomend | triggered after a zoom completes
mouseover | triggered after mouseover the map
mouseout | triggered after mouseout the map
mousemove | triggered after mousemove the map
changebaselayer | triggered after the base layer changes
updatesize | triggered after the updateSize method was executed

### id

{String} Unique identifier for the map

### fractionalZoom

{Boolean} For a base layer that supports it, allow the map resolution to be set to a value between one of the values in the resolutions array. Default is false.

When fractionalZoom is set to true, it is possible to zoom to an arbitrary extent. This requires a base layer from a source that supports requests for arbitrary extents (i.e. not cached tiles on a regular lattice). This means that fractionalZoom will not work with commercial layers (Google, Yahoo, VE), layers using TileCache, or any other pre-cached data sources.

If you are using fractionalZoom, then you should also use getResolutionForZoom instead of layer.resolutions[zoom] as the former works for non-integer zoom levels.

### events

{OpenLayers.Events} An events object that handles all events on the map

### allOverlays

{Boolean} Allow the map to function with “overlays” only. Defaults to false. If true, the lowest layer in the draw order will act as the base layer. In addition, if set to true, all layers will have isBaseLayer set to false when they are added to the map.

#### Note

If you set map.allOverlays to true, then you cannot use map.setBaseLayer or layer.setIsBaseLayer. With allOverlays true, the lowest layer in the draw layer is the base layer. So, to change the base layer, use setLayerIndex or raiseLayer to set the layer index to 0.

### div

{DOMElement|String} The element that contains the map (or an id for that element). If the OpenLayers.Map constructor is called with two arguments, this should be provided as the first argument. Alternatively, the map constructor can be called with the options object as the only argument. In this case (one argument), a div property may or may not be provided. If the div property is not provided, the map can be rendered to a container later using the render method.

#### Note

If you are calling render after map construction, do not use maxResolution auto. Instead, divide your maxExtent by your maximum expected dimension.

### dragging

{Boolean} The map is currently being dragged.

### size

{OpenLayers.Size} Size of the main div (this.div)

### viewPortDiv

{HTMLDivElement} The element that represents the map viewport

### layerContainerOrigin

{OpenLayers.LonLat} The lonlat at which the later container was re-initialized (on-zoom)

### layerContainerDiv

{HTMLDivElement} The element that contains the layers.

### layers

{Array(OpenLayers.Layer)} Ordered list of layers in the map

### controls

{Array(OpenLayers.Control)} List of controls associated with the map.

If not provided in the map options at construction, the map will by default be given the following controls if present in the build:

- OpenLayers.Control.Navigation or OpenLayers.Control.TouchNavigation
- OpenLayers.Control.Zoom or OpenLayers.Control.PanZoom
- OpenLayers.Control.ArgParser
- OpenLayers.Control.Attribution

### popups

{Array(OpenLayers.Popup)} List of popups associated with the map

### baseLayer

{OpenLayers.Layer} The currently selected base layer. This determines min/max zoom level, projection, etc.

### center

{OpenLayers.LonLat} The current center of the map

### resolution

{Float} The resolution of the map.

### zoom

{Integer} The current zoom level of the map

### panRatio

{Float} The ratio of the current extent within which panning will tween.

### options

{Object} The options object passed to the class constructor. Read-only.

### tileSize

{OpenLayers.Size} Set in the map options to override the default tile size for this map.

### projection

{String} Set in the map options to specify the default projection for layers added to this map. When using a projection other than EPSG:4326 (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator), also set maxExtent, maxResolution or resolutions. Default is “EPSG:4326”. Note that the projection of the map is usually determined by that of the current baseLayer (see baseLayer and getProjectionObject).

### units

{String} The map units. Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’. Normally taken from the projection. Only required if both map and layers do not define a projection, or if they define a projection which does not define units

### resolutions

{Array(Float)} 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.).

### maxResolution

{Float} Required if you are not displaying the whole world on a tile with the size specified in tileSize.

### minResolution

{Float}

### maxScale

{Float}

### minScale

{Float}

### maxExtent

{<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top). The maximum extent for the map. Default depends on projection; if this is one of those defined in OpenLayers.Projection.defaults (EPSG:4326 or web mercator), maxExtent will be set to the value defined there; else, defaults to null. To restrict user panning and zooming of the map, use restrictedExtent instead. The value for maxExtent will change calculations for tile URLs.

### minExtent

{<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top). The minimum extent for the map. Defaults to null.

### restrictedExtent

{<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top). Limit map navigation to this extent where possible. If a non-null restrictedExtent is set, panning will be restricted to the given bounds. In addition, zooming to a resolution that displays more than the restricted extent will center the map on the restricted extent. If you wish to limit the zoom level or resolution, use maxResolution.

### numZoomLevels

{Integer} Number of zoom levels for the map. Defaults to 16. Set a different value in the map options if needed.

### theme

{String} Relative path to a CSS file from which to load theme styles. Specify null in the map options (e.g. {theme: null}) if you want to get cascading style declarations - by putting links to stylesheets or style declarations directly in your page.

### displayProjection

{OpenLayers.Projection} Requires proj4js support for projections other than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by several controls to display data to user. If this property is set, it will be set on any control which has a null displayProjection property at the time the control is added to the map.

### tileManager

{<OpenLayers.TileManager>|Object} By default, and if the build contains TileManager.js, the map will use the TileManager to queue image requests and to cache tile image elements. To create a map without a TileManager configure the map with tileManager: null. To create a TileManager with non-default options, supply the options instead or alternatively supply an instance of {OpenLayers.TileManager}.

### fallThrough

{Boolean} Should OpenLayers allow events on the map to fall through to other elements on the page, or should it swallow them? (#457) Default is to swallow.

### autoUpdateSize

{Boolean} Should OpenLayers automatically update the size of the map when the resize event is fired. Default is true.

### 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.

### panTween

{OpenLayers.Tween} Animated panning tween object, see panTo()

### panMethod

{Function} The Easing function to be used for tweening. Default is OpenLayers.Easing.Expo.easeOut. Setting this to ‘null’ turns off animated panning.

### panDuration

{Integer} The number of steps to be passed to the OpenLayers.Tween.start() method when the map is panned. Default is 50.

### zoomTween

{OpenLayers.Tween} Animated zooming tween object, see zoomTo()

### zoomMethod

{Function} The Easing function to be used for tweening. Default is OpenLayers.Easing.Quad.easeOut. Setting this to ‘null’ turns off animated zooming.

### zoomDuration

{Integer} The number of steps to be passed to the OpenLayers.Tween.start() method when the map is zoomed. Default is 20.

### paddingForPopups

{OpenLayers.Bounds} Outside margin of the popup. Used to prevent the popup from getting too close to the map border.

### layerContainerOriginPx

{Object} Cached object representing the layer container origin (in pixels).

### minPx

{Object} An object with a ‘x’ and ‘y’ values that is the lower left of maxExtent in viewport pixel space. Used to verify in moveByPx that the new location we’re moving to is valid. It is also used in the getLonLatFromViewPortPx function of Layer.

### maxPx

{Object} An object with a ‘x’ and ‘y’ values that is the top right of maxExtent in viewport pixel space. Used to verify in moveByPx that the new location we’re moving to is valid.

### Constructor

### OpenLayers.Map

Constructor for a new OpenLayers.Map instance. There are two possible ways to call the map constructor. See the examples below.

#### Parameters

div | {DOMElement|String} The element or id of an element in your page that will contain the map. May be omitted if the div option is provided or if you intend to call the render method later.
options | {Object} Optional object with properties to tag onto the map.

#### Valid options (in addition to the listed API properties)

center | {<OpenLayers.LonLat>|Array} The default initial center of the map. If provided as array, the first value is the x coordinate, and the 2nd value is the y coordinate. Only specify if layers is provided. Note that if an ArgParser/Permalink control is present, and the querystring contains coordinates, center will be set by that, and this option will be ignored.
zoom | {Number} The initial zoom level for the map. Only specify if layers is provided. Note that if an ArgParser/Permalink control is present, and the querystring contains a zoom level, zoom will be set by that, and this option will be ignored.
extent | {<OpenLayers.Bounds>|Array} The initial extent of the map. If provided as an array, the array should consist of four values (left, bottom, right, top). Only specify if center and zoom are not provided.

#### Examples

>     // create a map with default options in an element with the id "map1"
>     var map = new OpenLayers.Map("map1");

>     // create a map with non-default options in an element with id "map2"
>     var options = {
>         projection: "EPSG:3857",
>         maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000),
>         center: new OpenLayers.LonLat(-12356463.476333, 5621521.4854095)
>     };
>     var map = new OpenLayers.Map("map2", options);

>     // map with non-default options - same as above but with a single argument,
>     // a restricted extent, and using arrays for bounds and center
>     var map = new OpenLayers.Map({
>         div: "map_id",
>         projection: "EPSG:3857",
>         maxExtent: [-18924313.432222, -15538711.094146, 18924313.432222, 15538711.094146],
>         restrictedExtent: [-13358338.893333, -9608371.5085962, 13358338.893333, 9608371.5085962],
>         center: [-12356463.476333, 5621521.4854095]
>     });

>     // create a map without a reference to a container - call render later
>     var map = new OpenLayers.Map({
>         projection: "EPSG:3857",
>         maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000)
>     });

### Functions

### getViewport

> getViewport: function()

Get the DOMElement representing the view port.

#### Returns

{DOMElement}

### render

> render: function( | div | )

Render the map to a specified container.

#### Parameters

div | {String|DOMElement} The container that the map should be rendered to. If different than the current container, the map viewport will be moved from the current to the new container.

### unloadDestroy

Function that is called to destroy the map on page unload. stored here so that if map is manually destroyed, we can unregister this.

### updateSizeDestroy

When the map is destroyed, we need to stop listening to updateSize events: this method stores the function we need to unregister in non-IE browsers.

### destroy

> destroy:function()

Destroy this map. Note that if you are using an application which removes a container of the map from the DOM, you need to ensure that you destroy the map before this happens; otherwise, the page unload handler will fail because the DOM elements that map.destroy() wants to clean up will be gone.

### setOptions

> setOptions: function( | options | )

Change the map options

#### Parameters

options | {Object} Hashtable of options to tag to the map

### getTileSize

> getTileSize: function()

Get the tile size for the map

#### Returns

{OpenLayers.Size}

### getBy

> getBy: function( | array,
> | property,
> | match | )

Get a list of objects given a property and a match item.

#### Parameters

array | {String} A property on the map whose value is an array.
property | {String} A property on each item of the given array.
match | {String | Object} A string to match. Can also be a regular expression literal or object. In addition, it can be any object with a method named test. For reqular expressions or other, if match.test(map[array][i][property]) evaluates to true, the item will be included in the array returned. If no items are found, an empty array is returned.

#### Returns

{Array} An array of items where the given property matches the given criteria.

### getLayersBy

> getLayersBy: function( | property,
> | match | )

Get a list of layers with properties matching the given criteria.

#### Parameters

property | {String} A layer property to be matched.
match | {String | Object} A string to match. Can also be a regular expression literal or object. In addition, it can be any object with a method named test. For reqular expressions or other, if match.test(layer[property]) evaluates to true, the layer will be included in the array returned. If no layers are found, an empty array is returned.

#### Returns

{Array(OpenLayers.Layer)} A list of layers matching the given criteria. An empty array is returned if no matches are found.

### getLayersByName

> getLayersByName: function( | match | )

Get a list of layers with names matching the given name.

#### Parameters

match | {String | Object} A layer name. The name can also be a regular expression literal or object. In addition, it can be any object with a method named test. For reqular expressions or other, if name.test(layer.name) evaluates to true, the layer will be included in the list of layers returned. If no layers are found, an empty array is returned.

#### Returns

{Array(OpenLayers.Layer)} A list of layers matching the given name. An empty array is returned if no matches are found.

### getLayersByClass

> getLayersByClass: function( | match | )

Get a list of layers of a given class (CLASS_NAME).

#### Parameters

match | {String | Object} A layer class name. The match can also be a regular expression literal or object. In addition, it can be any object with a method named test. For reqular expressions or other, if type.test(layer.CLASS_NAME) evaluates to true, the layer will be included in the list of layers returned. If no layers are found, an empty array is returned.

#### Returns

{Array(OpenLayers.Layer)} A list of layers matching the given class. An empty array is returned if no matches are found.

### getControlsBy

> getControlsBy: function( | property,
> | match | )

Get a list of controls with properties matching the given criteria.

#### Parameters

property | {String} A control property to be matched.
match | {String | Object} A string to match. Can also be a regular expression literal or object. In addition, it can be any object with a method named test. For reqular expressions or other, if match.test(layer[property]) evaluates to true, the layer will be included in the array returned. If no layers are found, an empty array is returned.

#### Returns

{Array(OpenLayers.Control)} A list of controls matching the given criteria. An empty array is returned if no matches are found.

### getControlsByClass

> getControlsByClass: function( | match | )

Get a list of controls of a given class (CLASS_NAME).

#### Parameters

match | {String | Object} A control class name. The match can also be a regular expression literal or object. In addition, it can be any object with a method named test. For reqular expressions or other, if type.test(control.CLASS_NAME) evaluates to true, the control will be included in the list of controls returned. If no controls are found, an empty array is returned.

#### Returns

{Array(OpenLayers.Control)} A list of controls matching the given class. An empty array is returned if no matches are found.

### getLayer

> getLayer: function( | id | )

Get a layer based on its id

#### Parameters

id | {String} A layer id

#### Returns

{OpenLayers.Layer} The Layer with the corresponding id from the map’s layer collection, or null if not found.

### setLayerZIndex

> setLayerZIndex: function ( | layer,
> | zIdx | )

#### Parameters

layer | {OpenLayers.Layer}
zIdx | {int}

### resetLayersZIndex

> resetLayersZIndex: function()

Reset each layer’s z-index based on layer’s array index

### addLayer

> addLayer: function ( | layer | )

#### Parameters

layer | {OpenLayers.Layer}

#### Returns

{Boolean} True if the layer has been added to the map.

### addLayers

> addLayers: function ( | layers | )

#### Parameters

layers | {Array(OpenLayers.Layer)}

### removeLayer

> removeLayer: function( | layer,
> | setNewBaseLayer | )

Removes a layer from the map by removing its visual element (the layer.div property), then removing it from the map’s internal list of layers, setting the layer’s map property to null.

a “removelayer” event is triggered.

very worthy of mention is that simply removing a layer from a map will not cause the removal of any popups which may have been created by the layer. this is due to the fact that it was decided at some point that popups would not belong to layers. thus there is no way for us to know here to which layer the popup belongs.

A simple solution to this is simply to call destroy() on the layer. the default OpenLayers.Layer class’s destroy() function automatically takes care to remove itself from whatever map it has been attached to.

The correct solution is for the layer itself to register an event-handler on “removelayer” and when it is called, if it recognizes itself as the layer being removed, then it cycles through its own personal list of popups, removing them from the map.

#### Parameters

layer | {OpenLayers.Layer}
setNewBaseLayer | {Boolean} Default is true

### getNumLayers

> getNumLayers: function ()

#### Returns

{Int} The number of layers attached to the map.

### getLayerIndex

> getLayerIndex: function ( | layer | )

#### Parameters

layer | {OpenLayers.Layer}

#### Returns

{Integer} The current (zero-based) index of the given layer in the map’s layer stack. Returns -1 if the layer isn’t on the map.

### setLayerIndex

> setLayerIndex: function ( | layer,
> | idx | )

Move the given layer to the specified (zero-based) index in the layer list, changing its z-index in the map display. Use map.getLayerIndex() to find out the current index of a layer. Note that this cannot (or at least should not) be effectively used to raise base layers above overlays.

#### Parameters

layer | {OpenLayers.Layer}
idx | {int}

### raiseLayer

> raiseLayer: function ( | layer,
> | delta | )

Change the index of the given layer by delta. If delta is positive, the layer is moved up the map’s layer stack; if delta is negative, the layer is moved down. Again, note that this cannot (or at least should not) be effectively used to raise base layers above overlays.

#### Paremeters

layer | {OpenLayers.Layer}
delta | {int}

### setBaseLayer

> setBaseLayer: function( | newBaseLayer | )

Allows user to specify one of the currently-loaded layers as the Map’s new base layer.

#### Parameters

newBaseLayer | {OpenLayers.Layer}

### addControl

> addControl: function ( | control,
> | px | )

Add the passed over control to the map. Optionally position the control at the given pixel.

#### Parameters

control | {OpenLayers.Control}
px | {OpenLayers.Pixel}

### addControls

> addControls: function ( | controls,
> | pixels | )

Add all of the passed over controls to the map. You can pass over an optional second array with pixel-objects to position the controls. The indices of the two arrays should match and you can add null as pixel for those controls you want to be autopositioned.

#### Parameters

controls | {Array(OpenLayers.Control)}
pixels | {Array(OpenLayers.Pixel)}

### addControlToMap

> addControlToMap: function ( | control,
> | px | )

#### Parameters

control | {OpenLayers.Control}
px | {OpenLayers.Pixel}

### getControl

> getControl: function ( | id | )

#### Parameters

id | {String} ID of the control to return.

#### Returns

{OpenLayers.Control} The control from the map’s list of controls which has a matching ‘id’. If none found, returns null.

### removeControl

> removeControl: function ( | control | )

Remove a control from the map. Removes the control both from the map object’s internal array of controls, as well as from the map’s viewPort (assuming the control was not added outsideViewport)

#### Parameters

control | {OpenLayers.Control} The control to remove.

### addPopup

> addPopup: function( | popup,
> | exclusive | )

#### Parameters

popup | {OpenLayers.Popup}
exclusive | {Boolean} If true, closes all other popups first

### removePopup

> removePopup: function( | popup | )

#### Parameters

popup | {OpenLayers.Popup}

### getSize

> getSize: function ()

#### Returns

{OpenLayers.Size} An OpenLayers.Size object that represents the size, in pixels, of the div into which OpenLayers has been loaded. Note - A clone() of this locally cached variable is returned, so as not to allow users to modify it.

### updateSize

> updateSize: function()

This function should be called by any external code which dynamically changes the size of the map div (because mozilla wont let us catch the “onresize” for an element)

### getCurrentSize

> getCurrentSize: function()

#### Returns

{OpenLayers.Size} A new OpenLayers.Size object with the dimensions of the map div

### calculateBounds

> calculateBounds: function( | center,
> | resolution | )

#### Parameters

center | {OpenLayers.LonLat} Default is this.getCenter()
resolution | {float} Default is this.getResolution()

#### Returns

{OpenLayers.Bounds} A bounds based on resolution, center, and current mapsize.

### getCenter

> getCenter: function ()

#### Returns

{OpenLayers.LonLat}

### getCachedCenter

> getCachedCenter: function()

#### Returns

{OpenLayers.LonLat}

### getZoom

> getZoom: function ()

#### Returns

{Integer}

### pan

> pan: function( | dx,
> | dy,
> | options | )

Allows user to pan by a value of screen pixels

#### Parameters

dx | {Integer}
dy | {Integer}
options | {Object} Options to configure panning:

- animate {Boolean} Use panTo instead of setCenter. Default is true.
- dragging {Boolean} Call setCenter with dragging true. Default is false.

### panTo

> panTo: function( | lonlat | )

Allows user to pan to a new lonlat If the new lonlat is in the current extent the map will slide smoothly

#### Parameters

lonlat | {OpenLayers.LonLat}

### setCenter

> setCenter: function( | lonlat,
> | zoom,
> | dragging,
> | forceZoomChange | )

Set the map center (and optionally, the zoom level).

#### Parameters

lonlat | {<OpenLayers.LonLat>|Array} The new center location. If provided as array, the first value is the x coordinate, and the 2nd value is the y coordinate.
zoom | {Integer} Optional zoom level.
dragging | {Boolean} Specifies whether or not to trigger movestart/end events
forceZoomChange | {Boolean} Specifies whether or not to trigger zoom change events (needed on baseLayer change)

TBD: reconsider forceZoomChange in 3.0

### moveByPx

> moveByPx: function( | dx,
> | dy | )

Drag the map by pixels.

#### Parameters

dx | {Number}
dy | {Number}

### adjustZoom

> adjustZoom: function( | zoom | )

#### Parameters

zoom | {Number} The zoom level to adjust

#### Returns

{Integer} Adjusted zoom level that shows a map not wider than its baseLayer’s maxExtent.

### getMinZoom

> getMinZoom: function()

Returns the minimum zoom level for the current map view. If the base layer is configured with <wrapDateLine> set to true, this will be the first zoom level that shows no more than one world width in the current map viewport. Components that rely on this value (e.g. zoom sliders) should also listen to the map’s “updatesize” event and call this method in the “updatesize” listener.

#### Returns

{Number} Minimum zoom level that shows a map not wider than its baseLayer’s maxExtent. This is an Integer value, unless the map is configured with fractionalZoom set to true.

### moveTo

> moveTo: function( | lonlat,
> | zoom,
> | options | )

#### Parameters

lonlat | {OpenLayers.LonLat}
zoom | {Integer}
options | {Object}

### centerLayerContainer

> centerLayerContainer: function ( | lonlat | )

This function takes care to recenter the layerContainerDiv.

#### Parameters

lonlat | {OpenLayers.LonLat}

### isValidZoomLevel

> isValidZoomLevel: function( | zoomLevel | )

#### Parameters

zoomLevel | {Integer}

#### Returns

{Boolean} Whether or not the zoom level passed in is non-null and within the min/max range of zoom levels.

### isValidLonLat

> isValidLonLat: function( | lonlat | )

#### Parameters

lonlat | {OpenLayers.LonLat}

#### Returns

{Boolean} Whether or not the lonlat passed in is non-null and within the maxExtent bounds

### getProjection

> getProjection: function()

This method returns a string representing the projection. In the case of projection support, this will be the srsCode which is loaded -- otherwise it will simply be the string value that was passed to the projection at startup.

FIXME: In 3.0, we will remove getProjectionObject, and instead return a Projection object from this function.

#### Returns

{String} The Projection string from the base layer or null.

### getProjectionObject

> getProjectionObject: function()

Returns the projection obect from the baselayer.

#### Returns

{OpenLayers.Projection} The Projection of the base layer.

### getMaxResolution

> getMaxResolution: function()

#### Returns

{String} The Map’s Maximum Resolution

### getMaxExtent

> getMaxExtent: function ( | options | )

#### Parameters

options | {Object}

#### Allowed Options

restricted | {Boolean} If true, returns restricted extent (if it is available.)

#### Returns

{OpenLayers.Bounds} The maxExtent property as set on the current baselayer, unless the ‘restricted’ option is set, in which case the ‘restrictedExtent’ option from the map is returned (if it is set).

### getNumZoomLevels

> getNumZoomLevels: function()

#### Returns

{Integer} The total number of zoom levels that can be displayed by the current baseLayer.

### getExtent

> getExtent: function ()

#### Returns

{OpenLayers.Bounds} A Bounds object which represents the lon/lat bounds of the current viewPort. If no baselayer is set, returns null.

### getResolution

> getResolution: function ()

#### Returns

{Float} The current resolution of the map. If no baselayer is set, returns null.

### getUnits

> getUnits: function ()

#### Returns

{Float} The current units of the map. If no baselayer is set, returns null.

### getScale

> getScale: function ()

#### Returns

{Float} The current scale denominator of the map. If no baselayer is set, returns null.

### getZoomForExtent

> getZoomForExtent: function ( | bounds,
> | 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} A suitable zoom level for the specified bounds. If no baselayer is set, returns null.

### getResolutionForZoom

> getResolutionForZoom: function( | zoom | )

#### Parameters

zoom | {Float}

#### Returns

{Float} A suitable resolution for the specified zoom. If no baselayer is set, returns null.

### 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} A suitable zoom level for the specified resolution. If no baselayer is set, returns null.

### zoomTo

> zoomTo: function( | zoom,
> | xy | )

Zoom to a specific zoom level. Zooming will be animated unless the map is configured with {zoomMethod: null}. To zoom without animation, use setCenter without a lonlat argument.

#### Parameters

zoom | {Integer}

### zoomIn

> zoomIn: function()

### zoomOut

> zoomOut: function()

### zoomToExtent

> zoomToExtent: function( | bounds,
> | closest | )

Zoom to the passed in bounds, recenter

#### Parameters

bounds | {<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top).
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.

### zoomToMaxExtent

> zoomToMaxExtent: function( | options | )

Zoom to the full extent and recenter.

#### Parameters

options | {Object}

#### Allowed Options

restricted | {Boolean} True to zoom to restricted extent if it is set. Defaults to true.

### zoomToScale

> zoomToScale: function( | scale,
> | closest | )

Zoom to a specified scale

#### Parameters

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

### getLonLatFromViewPortPx

> getLonLatFromViewPortPx: function ( | viewPortPx | )

#### Parameters

viewPortPx | {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object with a ‘x’ and ‘y’ properties.

#### Returns

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

### getViewPortPxFromLonLat

> getViewPortPxFromLonLat: function ( | lonlat | )

#### Parameters

lonlat | {OpenLayers.LonLat}

#### Returns

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

### getZoomTargetCenter

> getZoomTargetCenter: function ( | xy,
> | resolution | )

#### Parameters

xy | {OpenLayers.Pixel} The zoom origin pixel location on the screen
resolution | {Float} The resolution we want to get the center for

#### Returns

{OpenLayers.LonLat} The location of the map center after the transformation described by the origin xy and the target resolution.

### getLonLatFromPixel

> getLonLatFromPixel: function ( | px | )

#### Parameters

px | {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object with a ‘x’ and ‘y’ properties.

#### Returns

{OpenLayers.LonLat} An OpenLayers.LonLat corresponding to the given OpenLayers.Pixel, translated into lon/lat by the current base layer

### getPixelFromLonLat

> getPixelFromLonLat: function ( | lonlat | )

Returns a pixel location given a map location. The map location is translated to an integer pixel location (in viewport pixel coordinates) by the current base layer.

#### Parameters

lonlat | {OpenLayers.LonLat} A map location.

#### Returns

{OpenLayers.Pixel} An OpenLayers.Pixel corresponding to the OpenLayers.LonLat translated into view port pixels by the current base layer.

### getGeodesicPixelSize

> getGeodesicPixelSize: function( | px | )

#### Parameters

px | {OpenLayers.Pixel} The pixel to get the geodesic length for. If not provided, the center pixel of the map viewport will be used.

#### Returns

{OpenLayers.Size} The geodesic size of the pixel in kilometers.

### getViewPortPxFromLayerPx

> getViewPortPxFromLayerPx:function( | layerPx | )

#### Parameters

layerPx | {OpenLayers.Pixel}

#### Returns

{OpenLayers.Pixel} Layer Pixel translated into ViewPort Pixel coordinates

### getLayerPxFromViewPortPx

> getLayerPxFromViewPortPx:function( | viewPortPx | )

#### Parameters

viewPortPx | {OpenLayers.Pixel}

#### Returns

{OpenLayers.Pixel} ViewPort Pixel translated into Layer Pixel coordinates

### getLonLatFromLayerPx

> getLonLatFromLayerPx: function ( | px | )

#### Parameters

px | {OpenLayers.Pixel}

#### Returns

{OpenLayers.LonLat}

### getLayerPxFromLonLat

> getLayerPxFromLonLat: function ( | lonlat | )

#### Parameters

lonlat | {OpenLayers.LonLat} lonlat

#### Returns

{OpenLayers.Pixel} An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat, translated into layer pixels by the current base layer

### applyTransform

> applyTransform: function( | x,
> | y,
> | scale | )

Applies the given transform to the layerContainerDiv. This method has a 2-stage fallback from translate3d/scale3d via translate/scale to plain style.left/style.top, in which case no scaling is supported.

#### Parameters

x | {Number} x parameter for the translation. Defaults to the x value of the map’s layerContainerOriginPx
y | {Number} y parameter for the translation. Defaults to the y value of the map’s layerContainerOriginPx
scale | {Number} scale. Defaults to 1 if not provided.

### Constants

### TILE_WIDTH

{Integer} 256 Default tile width (unless otherwise specified)

### TILE_HEIGHT

{Integer} 256 Default tile height (unless otherwise specified)

Instances of this class represent a width/height pair
This class represents a longitude and latitude pair
Controls affect the display or behavior of the map.
A popup is a small div that can opened and closed on the map.
{OpenLayers.Size} Set in the map options to override the default tile size for this map.
Methods for coordinate transforms between coordinate systems.

> on: function( | object | )

Convenience method for registering listeners with a common scope.
Instances of this class represent bounding boxes.

> getViewport: function()

Get the DOMElement representing the view port.

> render: function( | div | )

Render the map to a specified container.

> destroy:function()

Destroy this map.

> setOptions: function( | options | )

Change the map options

> getTileSize: function()

Get the tile size for the map

> getBy: function( | array,
> | property,
> | match | )

Get a list of objects given a property and a match item.

> getLayersBy: function( | property,
> | match | )

Get a list of layers with properties matching the given criteria.

> getLayersByName: function( | match | )

Get a list of layers with names matching the given name.

> getLayersByClass: function( | match | )

Get a list of layers of a given class (CLASS_NAME).

> getControlsBy: function( | property,
> | match | )

Get a list of controls with properties matching the given criteria.

> getControlsByClass: function( | match | )

Get a list of controls of a given class (CLASS_NAME).

> getLayer: function( | id | )

Get a layer based on its id

> setLayerZIndex: function ( | layer,
> | zIdx | )

> resetLayersZIndex: function()

Reset each layer’s z-index based on layer’s array index

> addLayer: function ( | layer | )

> addLayers: function ( | layers | )

> removeLayer: function( | layer,
> | setNewBaseLayer | )

Removes a layer from the map by removing its visual element (the layer.div property), then removing it from the map’s internal list of layers, setting the layer’s map property to null.

> getNumLayers: function ()

{Int} The number of layers attached to the map.

> getLayerIndex: function ( | layer | )

> setLayerIndex: function ( | layer,
> | idx | )

Move the given layer to the specified (zero-based) index in the layer list, changing its z-index in the map display.

> raiseLayer: function ( | layer,
> | delta | )

Change the index of the given layer by delta.

> setBaseLayer: function( | newBaseLayer | )

Allows user to specify one of the currently-loaded layers as the Map’s new base layer.

> addControl: function ( | control,
> | px | )

Add the passed over control to the map.

> addControls: function ( | controls,
> | pixels | )

Add all of the passed over controls to the map.

> addControlToMap: function ( | control,
> | px | )

> getControl: function ( | id | )

> removeControl: function ( | control | )

Remove a control from the map.

> addPopup: function( | popup,
> | exclusive | )

> removePopup: function( | popup | )

> getSize: function ()

{OpenLayers.Size} An OpenLayers.Size object that represents the size, in pixels, of the div into which OpenLayers has been loaded.

> updateSize: function()

This function should be called by any external code which dynamically changes the size of the map div (because mozilla wont let us catch the “onresize” for an element)

> getCurrentSize: function()

{OpenLayers.Size} A new OpenLayers.Size object with the dimensions of the map div

> calculateBounds: function( | center,
> | resolution | )

> getCenter: function ()

{OpenLayers.LonLat}

> getCachedCenter: function()

{OpenLayers.LonLat}

> getZoom: function ()

{Integer}

> pan: function( | dx,
> | dy,
> | options | )

Allows user to pan by a value of screen pixels

> panTo: function( | lonlat | )

Allows user to pan to a new lonlat If the new lonlat is in the current extent the map will slide smoothly

> setCenter: function( | lonlat,
> | zoom,
> | dragging,
> | forceZoomChange | )

Set the map center (and optionally, the zoom level).

> moveByPx: function( | dx,
> | dy | )

Drag the map by pixels.

> adjustZoom: function( | zoom | )

> getMinZoom: function()

Returns the minimum zoom level for the current map view.

> moveTo: function( | lonlat,
> | zoom,
> | options | )

> centerLayerContainer: function ( | lonlat | )

This function takes care to recenter the layerContainerDiv.

> isValidZoomLevel: function( | zoomLevel | )

> isValidLonLat: function( | lonlat | )

> getProjection: function()

This method returns a string representing the projection.

> getProjectionObject: function()

Returns the projection obect from the baselayer.

> getMaxResolution: function()

{String} The Map’s Maximum Resolution

> getMaxExtent: function ( | options | )

> getNumZoomLevels: function()

{Integer} The total number of zoom levels that can be displayed by the current baseLayer.

> getExtent: function ()

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

> getResolution: function ()

{Float} The current resolution of the map.

> getUnits: function ()

{Float} The current units of the map.

> getScale: function ()

{Float} The current scale denominator of the map.

> getZoomForExtent: function ( | bounds,
> | closest | )

> getResolutionForZoom: function( | zoom | )

> getZoomForResolution: function( | resolution,
> | closest | )

> zoomTo: function( | zoom,
> | xy | )

Zoom to a specific zoom level.

> zoomIn: function()

> zoomOut: function()

> zoomToExtent: function( | bounds,
> | closest | )

Zoom to the passed in bounds, recenter

> zoomToMaxExtent: function( | options | )

Zoom to the full extent and recenter.

> zoomToScale: function( | scale,
> | closest | )

Zoom to a specified scale

> getLonLatFromViewPortPx: function ( | viewPortPx | )

> getViewPortPxFromLonLat: function ( | lonlat | )

> getZoomTargetCenter: function ( | xy,
> | resolution | )

> getLonLatFromPixel: function ( | px | )

> getPixelFromLonLat: function ( | lonlat | )

Returns a pixel location given a map location.

> getGeodesicPixelSize: function( | px | )

> getViewPortPxFromLayerPx:function( | layerPx | )

> getLayerPxFromViewPortPx:function( | viewPortPx | )

> getLonLatFromLayerPx: function ( | px | )

> getLayerPxFromLonLat: function ( | lonlat | )

> applyTransform: function( | x,
> | y,
> | scale | )

Applies the given transform to the layerContainerDiv.
{HTMLDivElement} The element that contains the layers.
Constructor for a new OpenLayers.Map instance.
This class represents a screen coordinate, in x and y coordinates
{Float} Required if you are not displaying the whole world on a tile with the size specified in tileSize.
{<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top).
The navigation control handles map browsing with mouse events (dragging, double-clicking, and scrolling the wheel).
The navigation control handles map browsing with touch events (dragging, double-tapping, tap with two fingers, and pinch zoom).
The Zoom control is a pair of +/- links for zooming in and out.
The PanZoom is a visible control, composed of a OpenLayers.Control.PanPanel and a OpenLayers.Control.ZoomPanel.
The ArgParser control adds location bar query string parsing functionality to an OpenLayers Map.
The attribution control adds attribution from layers to the map display.
{OpenLayers.Layer} The currently selected base layer.
{<OpenLayers.Bounds>|Array} If provided as an array, the array should consist of four values (left, bottom, right, top).
Provides queueing of image requests and caching of image elements.
{DOMElement|String} The element that contains the map (or an id for that element).
{Array(OpenLayers.Layer)} Ordered list of layers in the map
{OpenLayers.LonLat} The current center of the map
{Integer} The current zoom level of the map
{Boolean} For a base layer that supports it, allow the map resolution to be set to a value between one of the values in the resolutions array.
{Object} Cached object representing the layer container origin (in pixels).
Close