OpenLayers.Map

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

Summary
Instances of OpenLayers.Map are interactive maps embedded in a web page.
{Integer} 256
{Integer} 256
{Object} Base z-indexes for different classes of thing
{Array} supported application event types
{String} Unique identifier for the map
{OpenLayers.Events} An events object that handles all events on the map
Function that is called to destroy the map on page unload.
{DOMElement} The element that contains the map
{OpenLayers.Size} Size of the main div (this.div)
{HTMLDivElement} The element that represents the map viewport
{OpenLayers.LonLat} The lonlat at which the later container was re-initialized (on-zoom)
{HTMLDivElement} The element that contains the layers.
{Array(OpenLayers.Layer)} Ordered list of layers in the map
{Array(OpenLayers.Control)} List of controls associated with the map
{Array(OpenLayers.Popup)} List of popups associated with the map
{OpenLayers.LonLat} The current center of the map
{Integer} The current zoom level of the map
{String} Used to store a unique identifier that changes when the map view changes.
{OpenLayers.Size} Set in the map options to override the default tile size for this map.
{String} Set in the map options to override the default projection string this map - also set maxExtent, maxResolution, and units if appropriate.
{String} The map units.
{Number} Default max is 360 deg / 256 px, which corresponds to zoom level 0 on gmaps.
{Number}
{Number}
{OpenLayers.Bounds} The maximum extent for the map.
{Integer} Number of zoom levels for the map.
{String} Relative path to a CSS file from which to load theme styles.
{Boolean} Should OpenLayers allow events on the map to fall through to other elements on the page, or should it swallow them? 
Constructor for a new OpenLayers.Map instance.
Destroy this map
Change the map options
Get the tile size for the map
Get a layer based on its id
Private.
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.
Return: {Int} The number of layers attached to the map.
@param {OpenLayers.Layer} layer
Move the given layer to the specified (zero-based) index in the layer list, changing its z-index in the map display.
Change the index of the given layer by delta.
{String} OpenLayers.Map

Constants

TILE_WIDTH

{Integer} 256

TILE_HEIGHT

{Integer} 256

Z_INDEX_BASE

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

EVENT_TYPES

{Array} supported application event types

Properties and Functions

id

{String} Unique identifier for the map

events

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

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.

div

{DOMElement} The element that contains the map

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 layerthis determines min/max zoom level, projection, etc.

center

{OpenLayers.LonLat} The current center of the map

zoom

{Integer} The current zoom level of the map

viewRequestID

{String} Used to store a unique identifier that changes when the map view changes. viewRequestID should be used when adding data asynchronously to the map: viewRequestID is incremented when you initiate your request (right now during changing of baselayers and changing of zooms).  It is stored here in the map and also in the data that will be coming back asynchronously.  Before displaying this data on request completion, we check that the viewRequestID of the data is still the same as that of the map.  Fix for #480

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 override the default projection string this map - also set maxExtent, maxResolution, and units if appropriate.

units

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

maxResolution

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

minResolution

{Number}

maxScale

{Number}

minScale

maxExtent

{OpenLayers.Bounds} The maximum extent for the map.  Defaults to the whole world in decimal degrees (-180, -90, 180, 90).  Specify a different extent in the map options if you are not using a geographic projection and displaying the whole world.

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.

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

OpenLayers.Map

Constructor for a new OpenLayers.Map instance.

Parameters

div{String} The id of an element in your page that will contain the map
options{Object} An optional object with properties to tag onto the map

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 = {
maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000),
maxResolution: 156543,
units: 'meters',
projection: "EPSG:41001"
};
var map = new OpenLayers.Map("map2", options);

Return

A new OpenLayers.Map instance

destroy

destroy:function()

Destroy this map

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

Return

{OpenLayers.Size}

getLayer

getLayer: function(id)

Get a layer based on its id

Parameter

id{String} A layer id

Return

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

setLayerZIndex

setLayerZIndex: function (layer,
zIdx)

Private.

Parameters

layer{OpenLayers.Layer}
zIdx{int}

addLayer

addLayer: function (layer)

Parameters

layer{OpenLayers.Layer}

addLayers

addLayers: function (layers)

Parameters

layersArray({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 ()

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

getLayerIndex

getLayerIndex: function (layer)

Parameters

@param {OpenLayers.Layer} layer

Return

{Int} 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}
idx{int}

Constants

CLASS_NAME

{String} OpenLayers.Map

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.
Instances of this class represent bounding boxes.
destroy:function()
Destroy this map
setOptions: function(options)
Change the map options
getTileSize: function()
Get the tile size for the map
getLayer: function(id)
Get a layer based on its id
setLayerZIndex: function (layer,
zIdx)
Private.
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 ()
Return: {Int} The number of layers attached to the map.
getLayerIndex: function (layer)
@param {OpenLayers.Layer} 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.
Constructor for a new OpenLayers.Map instance.