ol. ol.Map

The map is the core component of OpenLayers. In its minimal configuration it needs a view, one or more layers, and a target container:

var map = new ol.Map({
  view: new ol.View2D({
    center: [0, 0],
    zoom: 1
  }),
  layers: [
    new ol.layer.Tile({
      source: new ol.source.MapQuestOSM()
    })
  ],
  target: 'map'
});

The above snippet creates a map with a MapQuest OSM layer on a 2D view and renders it to a DOM element with the id 'map'.

new Map

Parameters:
Name Type Description
options ol.MapOptions

Map options.

Source:
  • map.js, line 146

Extends

Methods

addControl

Add the given control to the map.

Parameters:
Name Type Description
control ol.control.Control

Control.

Source:
  • map.js, line 359

addLayer

Adds the given layer to the top of this map.

Parameters:
Name Type Description
layer ol.layer.Base

Layer.

Source:
  • map.js, line 371

addOverlay

Add the given overlay to the map.

Parameters:
Name Type Description
overlay ol.Overlay

Overlay.

Source:
  • map.js, line 382

beforeRender

Add functions to be called before rendering. This can be used for attaching animations before updating the map's view. The ol.animation namespace provides several static methods for creating prerender functions.

Parameters:
Name Type Description
var_args ol.PreRenderFunction

Any number of pre-render functions.

Source:
  • map.js, line 396

bindTo

Binds a View to a Model.

Parameters:
Name Type Argument Description
key string

Key.

target ol.Object

Target.

targetKey string <optional>
(Optional)

Target key.

noNotify boolean <optional>
(Optional)

No notify.

Inherited From:
Source:
  • object.js, line 147

get

Gets a value.

Parameters:
Name Type Description
key string

Key.

Inherited From:
Source:
  • object.js, line 170
Returns:

Value.

Type
*

getControls

Source:
  • map.js, line 471
Returns:

Controls.

Type
ol.Collection

getFeatureInfo

Get feature information for a pixel on the map.

Parameters:
Name Type Description
options ol.GetFeatureInfoOptions

Options.

Source:
  • map.js, line 489

getFeatures

Get features for a pixel on the map.

Parameters:
Name Type Description
options ol.GetFeaturesOptions

Options.

Source:
  • map.js, line 502

getInteractions

Gets the collection on interactions associated with this map. Interactions are used for e.g. pan, zoom and rotate.

Source:
  • map.js, line 515
Returns:

Interactions.

Type
ol.Collection

getLayerGroup

Get the layergroup associated with this map.

Source:
  • map.js, line 524
Returns:

LayerGroup.

Type
ol.layer.Group

getLayers

Get the collection of layers associated with this map.

Source:
  • map.js, line 538
Returns:

Layers.

Type
ol.Collection

getOverlays

Source:
  • map.js, line 479
Returns:

Overlays.

Type
ol.Collection

getRenderer

Get the map's renderer.

Source:
  • map.js, line 434
Returns:

Renderer.

Type
ol.renderer.Map

getSize

Get the size of this map.

Source:
  • map.js, line 562
Returns:

Size.

Type
ol.Size | undefined

getTarget

Get the element in which this map is rendered.

Source:
  • map.js, line 443
Returns:

Target.

Type
Element | string | undefined

getView

Get the view associated with this map. This can be a 2D or 3D view. A 2D view manages properties such as center and resolution.

Source:
  • map.js, line 576
Returns:

View.

Type
ol.View

notify

Notify all observers of a change on this property. This notifies both objects that are bound to the object's property as well as the object that it is bound to.

Parameters:
Name Type Description
key string

Key.

Inherited From:
Source:
  • object.js, line 208

on

Listen for a certain type of event.

Parameters:
Name Type Argument Description
type string | Array.<string>

The event type or array of event types.

listener Function

The listener function.

scope Object <optional>
(Optional)

Object is whose scope to call the listener.

Inherited From:
Source:
  • object.js, line 240
Returns:

Unique key for the listener.

Type
goog.events.Key

once

Listen once for a certain type of event.

Parameters:
Name Type Argument Description
type string | Array.<string>

The event type or array of event types.

listener Function

The listener function.

scope Object <optional>
(Optional)

Object is whose scope to call the listener.

Inherited From:
Source:
  • object.js, line 253
Returns:

Unique key for the listener.

Type
goog.events.Key

removeControl

Remove the given control from the map.

Parameters:
Name Type Description
control ol.control.Control

Control.

Source:
  • map.js, line 864
Returns:

The removed control of undefined if the control was not found.

Type
ol.control.Control | undefined

removeLayer

Removes the given layer from the map.

Parameters:
Name Type Description
layer ol.layer.Base

Layer.

Source:
  • map.js, line 881
Returns:

The removed layer or undefined if the layer was not found.

Type
ol.layer.Base | undefined

removeOverlay

Remove the given overlay from the map.

Parameters:
Name Type Description
overlay ol.Overlay

Overlay.

Source:
  • map.js, line 894
Returns:

The removed overlay of undefined if the overlay was not found.

Type
ol.Overlay | undefined

set

Sets a value.

Parameters:
Name Type Description
key string

Key.

value *

Value.

Inherited From:
Source:
  • object.js, line 263

setLayerGroup

Sets the layergroup of this map.

Parameters:
Name Type Description
layerGroup ol.layer.Group

Layergroup.

Source:
  • map.js, line 1007

setSize

Set the size of this map.

Parameters:
Name Type Description
size ol.Size | undefined

Size.

Source:
  • map.js, line 1020

setTarget

Set the target element to render this map into.

Parameters:
Name Type Description
target Element | string | undefined

Target.

Source:
  • map.js, line 1033

setValues

Sets a collection of key-value pairs.

Parameters:
Name Type Description
values Object.<string, *>

Values.

Inherited From:
Source:
  • object.js, line 286

setView

Set the view for this map.

Parameters:
Name Type Description
view ol.IView

View.

Source:
  • map.js, line 1046

un

Unlisten for a certain type of event.

Parameters:
Name Type Argument Description
type string | Array.<string>

The event type or array of event types.

listener Function

The listener function.

scope Object <optional>
(Optional)

Object is whose scope to call the listener.

Inherited From:
Source:
  • object.js, line 326

unbind

Removes a binding. Unbinding will set the unbound property to the current value. The object will not be notified, as the value has not changed.

Parameters:
Name Type Description
key string

Key.

Inherited From:
Source:
  • object.js, line 305

unbindAll

Removes all bindings.

Inherited From:
Source:
  • object.js, line 344

unByKey

Removes an event listener which was added with listen() by the key returned by on().

Parameters:
Name Type Argument Description
key number <nullable>

Key.

Inherited From:
Source:
  • object.js, line 336

updateSize

Force a recalculation of the map viewport size. This should be called when third-party code changes the size of the map viewport.

Source:
  • map.js, line 1070