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.TileLayer({
      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 147

Extends

Methods

addControl

Add the given control to the map.

Parameters:
Name Type Description
control ol.control.Control

Control.

Source:
  • map.js, line 345

addLayer

Adds the given layer to the top of this map.

Parameters:
Name Type Description
layer ol.layer.Layer

Layer.

Source:
  • map.js, line 357

addPreRenderFunction

Add a prerender function. This can be used for attaching animations to be performed before setting the map's center.

Parameters:
Name Type Description
preRenderFunction ol.PreRenderFunction

Pre-render function.

Source:
  • map.js, line 369

addPreRenderFunctions

Add prerender functions. This can be used for attaching animations to be performed before setting the map's center.

Parameters:
Name Type Description
preRenderFunctions Array.<ol.PreRenderFunction>

Pre-render functions.

Source:
  • map.js, line 381

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
*

getFeatureInfo

Get feature information for a pixel on the map.

Parameters:
Name Type Description
options ol.GetFeatureInfoOptions

Options.

Source:
  • map.js, line 466

getFeatures

Get features for a pixel on the map.

Parameters:
Name Type Description
options ol.GetFeaturesOptions

Options.

Source:
  • map.js, line 479

getInteractions

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

Source:
  • map.js, line 492
Returns:

Interactions.

Type
ol.Collection

getLayers

Get the collection of layers associated with this map.

Source:
  • map.js, line 501
Returns:

Layers.

Type
ol.Collection

getRenderer

Get the map's renderer.

Source:
  • map.js, line 420
Returns:

Renderer.

Type
ol.renderer.Map

getSize

Get the size of this map.

Source:
  • map.js, line 529
Returns:

Size.

Type
ol.Size | undefined

getTarget

Get the element in which this map is rendered.

Source:
  • map.js, line 429
Returns:

Target.

Type
Element | 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 543
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 835
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.Layer

Layer.

Source:
  • map.js, line 852
Returns:

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

Type
ol.layer.Layer | undefined

set

Sets a value.

Parameters:
Name Type Description
key string

Key.

value *

Value.

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

setLayers

Sets the whole collection of layers for this map.

Parameters:
Name Type Description
layers ol.Collection

Layers.

Source:
  • map.js, line 953

setSize

Set the size of this map.

Parameters:
Name Type Description
size ol.Size | undefined

Size.

Source:
  • map.js, line 966

setTarget

Set the target element to render this map into.

Parameters:
Name Type Description
target Element | string | undefined

Target.

Source:
  • map.js, line 979

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 995

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 1019