new ol.Map(options)
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Map options.
|
Fires:
-
beforepropertychange
(ol.ObjectEvent) experimental - Triggered before a property is changed. -
change:layergroup
(ol.ObjectEvent) -
change:size
(ol.ObjectEvent) -
change:target
(ol.ObjectEvent) -
change:view
(ol.ObjectEvent) -
click
(ol.MapBrowserEvent) experimental - A click with no dragging. A double click will fire two of this. -
dblclick
(ol.MapBrowserEvent) experimental - A true double click, with no dragging. -
moveend
(ol.MapEvent) experimental - Triggered after the map is moved. -
pointerdrag
(ol.MapBrowserEvent) experimental - Triggered when a pointer is dragged. -
pointermove
(ol.MapBrowserEvent) experimental - Triggered when a pointer is moved. Note that on touch devices this is triggered when the map is panned, so is not the same as mousemove. -
postcompose
(ol.render.Event) experimental -
postrender
(ol.MapEvent) experimental - Triggered after a map frame is rendered. -
precompose
(ol.render.Event) experimental -
propertychange
(ol.ObjectEvent) experimental - Triggered when a property is changed. -
singleclick
(ol.MapBrowserEvent) experimental - A true single click with no dragging and no double click. Note that this event is delayed by 250 ms to ensure that it is not a double click.
Extends
Observable Properties
Name | Type | Settable | ol.ObjectEvent type | Description |
---|---|---|---|---|
layerGroup |
ol.layer.Group | yes | change:layergroup |
A layer group containing the layers in this map. |
size |
ol.Size | undefined | yes | change:size |
The size in pixels of the map in the DOM. |
target |
Element | string | undefined | yes | change:target |
The Element or id of the Element that the map is rendered in. |
view |
ol.View | undefined | yes | change:view |
The view that controls this map. |
Methods
-
addControl(control)
-
Add the given control to the map.
Name Type Description control
ol.control.Control Control.
-
addInteraction(interaction)
-
Add the given interaction to the map.
Name Type Description interaction
ol.interaction.Interaction Interaction to add.
-
addLayer(layer)
-
Adds the given layer to the top of this map.
Name Type Description layer
ol.layer.Base Layer.
-
addOverlay(overlay)
-
Add the given overlay to the map.
Name Type Description overlay
ol.Overlay Overlay.
-
beforeRender(var_args) experimental
-
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.Name Type Description var_args
ol.PreRenderFunction Any number of pre-render functions.
-
bindTo(key, target, opt_targetKey){ol.ObjectAccessor} inherited experimental
-
The bindTo method allows you to set up a two-way binding between a
source
andtarget
object. The method returns an object with atransform
method that you can use to providefrom
andto
functions to transform values on the way from the source to the target and on the way back.For example, if you had two map views (sourceView and targetView) and you wanted the target view to have double the resolution of the source view, you could transform the resolution on the way to and from the target with the following:
sourceView.bindTo('resolution', targetView) .transform( function(sourceResolution) { // from sourceView.resolution to targetView.resolution return 2 * sourceResolution; }, function(targetResolution) { // from targetView.resolution to sourceView.resolution return targetResolution / 2; } );
Name Type Description key
string Key name.
target
ol.Object Target.
targetKey
string Target key.
-
dispatchChangeEvent() inherited experimental
-
Dispatches a
change
event.Fires:
-
change
experimental
-
-
forEachFeatureAtPixel(pixel, callback, opt_this, opt_layerFilter, opt_this2){T|undefined}
-
Detect features that intersect a pixel on the viewport, and execute a callback with each intersecting feature. Layers included in the detection can be configured through
opt_layerFilter
. Feature overlays will always be included in the detection.Name Type Description pixel
ol.Pixel Pixel.
callback
function Feature callback. If the detected feature is not on a layer, but on a
ol.FeatureOverlay
, then the 2nd argument to this function will benull
. To stop detection, callback functions can return a truthy value.this
S Value to use as
this
when executingcallback
.layerFilter
function Layer filter function, only layers which are visible and for which this function returns
true
will be tested for features. By default, all visible layers will be tested. Feature overlays will always be tested.this2
U Value to use as
this
when executinglayerFilter
.Returns:
Callback result, i.e. the return value of last callback execution, or the first truthy callback return value.
-
get(key){*} inherited experimental
-
Gets a value.
Name Type Description key
string Key name.
Returns:
Value.
-
getControls(){ol.Collection.<ol.control.Control>}
-
Returns:
Controls.
-
getCoordinateFromPixel(pixel){ol.Coordinate}
-
Name Type Description pixel
ol.Pixel Pixel.
Returns:
Coordinate.
-
getEventCoordinate(event){ol.Coordinate}
-
Returns the geographical coordinate for a browser event.
Name Type Description event
Event Event.
Returns:
Coordinate.
-
getEventPixel(event){ol.Pixel}
-
Returns the map pixel position for a browser event.
Name Type Description event
Event Event.
Returns:
Pixel.
-
getInteractions(){ol.Collection.<ol.interaction.Interaction>}
-
Gets the collection of
ol.interaction.Interaction
instances associated with this map. Modifying this collection changes the interactions associated with the map.Interactions are used for e.g. pan, zoom and rotate.
Returns:
Interactions.
-
getKeys(){Array.<string>} inherited experimental
-
Get a list of object property names.
Returns:
List of property names.
-
getLayerGroup(){ol.layer.Group}
-
Get the layergroup associated with this map.
Returns:
A layer group containing the layers in this map.
-
getLayers(){ol.Collection.<ol.layer.Base>|undefined}
-
Get the collection of layers associated with this map.
Returns:
Layers.
-
getOverlays(){ol.Collection.<ol.Overlay>}
-
Returns:
Overlays.
-
getPixelFromCoordinate(coordinate){ol.Pixel}
-
Name Type Description coordinate
ol.Coordinate Coordinate.
Returns:
Pixel.
-
getProperties(){Object.<string, *>} inherited experimental
-
Get an object of all property names and values.
Returns:
Object.
-
getRevision(){number} inherited experimental
-
Returns:
Revision.
-
getSize(){ol.Size|undefined}
-
Get the size of this map.
Returns:
The size in pixels of the map in the DOM.
-
getTarget(){Element|string|undefined}
-
Get the target in which this map is rendered. Note that this returns what is entered as an option or in setTarget: if that was an element, it returns an element; if a string, it returns that.
Returns:
The Element or id of the Element that the map is rendered in.
-
getView(){ol.View|undefined}
-
Get the view associated with this map. A view manages properties such as center and resolution.
Returns:
The view that controls this map.
-
getViewport(){Element}
-
Returns:
Viewport.
-
on(type, listener, opt_this){goog.events.Key} inherited
-
Listen for a certain type of event.
Name Type Description type
string | Array.<string> The event type or array of event types.
listener
function The listener function.
this
Object The object to use as
this
inlistener
.Returns:
Unique key for the listener.
-
once(type, listener, opt_this){goog.events.Key} inherited
-
Listen once for a certain type of event.
Name Type Description type
string | Array.<string> The event type or array of event types.
listener
function The listener function.
this
Object The object to use as
this
inlistener
.Returns:
Unique key for the listener.
-
removeControl(control){ol.control.Control|undefined}
-
Remove the given control from the map.
Name Type Description control
ol.control.Control Control.
Returns:
The removed control (or undefined if the control was not found).
-
removeInteraction(interaction){ol.interaction.Interaction|undefined}
-
Remove the given interaction from the map.
Name Type Description interaction
ol.interaction.Interaction Interaction to remove.
Returns:
The removed interaction (or undefined if the interaction was not found).
-
removeLayer(layer){ol.layer.Base|undefined}
-
Removes the given layer from the map.
Name Type Description layer
ol.layer.Base Layer.
Returns:
The removed layer (or undefined if the layer was not found).
-
removeOverlay(overlay){ol.Overlay|undefined}
-
Remove the given overlay from the map.
Name Type Description overlay
ol.Overlay Overlay.
Returns:
The removed overlay (or undefined if the overlay was not found).
-
render()
-
Requests a render frame; rendering will effectively occur at the next browser animation frame.
-
renderSync()
-
Requests an immediate render in a synchronous manner.
-
set(key, value) inherited experimental
-
Sets a value.
Name Type Description key
string Key name.
value
* Value.
-
setLayerGroup(layerGroup)
-
Sets the layergroup of this map.
Name Type Description layerGroup
ol.layer.Group A layer group containing the layers in this map.
-
setProperties(values) inherited experimental
-
Sets a collection of key-value pairs.
Name Type Description values
Object.<string, *> Values.
-
setSize(size) experimental
-
Set the size of this map.
Name Type Description size
ol.Size | undefined The size in pixels of the map in the DOM.
-
setTarget(target)
-
Set the target element to render this map into.
Name Type Description target
Element | string | undefined The Element or id of the Element that the map is rendered in.
-
setView(view)
-
Set the view for this map.
Name Type Description view
ol.View The view that controls this map.
-
un(type, listener, opt_this) inherited
-
Unlisten for a certain type of event.
Name Type Description type
string | Array.<string> The event type or array of event types.
listener
function The listener function.
this
Object The object which was used as
this
by thelistener
. -
unbind(key) inherited experimental
-
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.
Name Type Description key
string Key name.
-
unbindAll() inherited experimental
-
Removes all bindings.
-
unByKey(key) inherited
-
Removes an event listener using the key returned by
on()
oronce()
.Name Type Description key
goog.events.Key Key.
-
updateSize()
-
Force a recalculation of the map viewport size. This should be called when third-party code changes the size of the map viewport.