new ol.Map(options)
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Map options.
|
Fires:
-
change
(ol.events.Event) - Generic change event. Triggered when the revision counter is increased. -
change:layerGroup
(ol.Object.Event) -
change:size
(ol.Object.Event) -
change:target
(ol.Object.Event) -
change:view
(ol.Object.Event) -
click
(ol.MapBrowserEvent) - A click with no dragging. A double click will fire two of this. -
dblclick
(ol.MapBrowserEvent) - A true double click, with no dragging. -
moveend
(ol.MapEvent) - Triggered after the map is moved. -
movestart
(ol.MapEvent) - Triggered when the map starts moving. -
pointerdrag
(ol.MapBrowserEvent) - Triggered when a pointer is dragged. -
pointermove
(ol.MapBrowserEvent) - 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) -
postrender
(ol.MapEvent) - Triggered after a map frame is rendered. -
precompose
(ol.render.Event) -
propertychange
(ol.Object.Event) - Triggered when a property is changed. -
singleclick
(ol.MapBrowserEvent) - 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.Object.Event 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 | yes | change:view |
The view that controls this map. |
Methods
-
addControl(control)
src/ol/map.js, line 464 -
Add the given control to the map.
Name Type Description control
ol.control.Control Control.
-
addInteraction(interaction)
src/ol/map.js, line 474 -
Add the given interaction to the map.
Name Type Description interaction
ol.interaction.Interaction Interaction to add.
-
addLayer(layer)
src/ol/map.js, line 486 -
Adds the given layer to the top of this map. If you want to add a layer elsewhere in the stack, use
getLayers()
and the methods available onol.Collection
.Name Type Description layer
ol.layer.Base Layer.
-
addOverlay(overlay)
src/ol/map.js, line 497 -
Add the given overlay to the map.
Name Type Description overlay
ol.Overlay Overlay.
-
Increases the revision counter and dispatches a 'change' event.
-
Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a
type
property.Name Type Description event
Object | ol.events.Event | string Event object.
-
forEachFeatureAtPixel(pixel, callback, opt_options){T|undefined}
src/ol/map.js, line 560 -
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
.Name Type Description pixel
ol.Pixel Pixel.
callback
function Feature callback. The callback will be called with two arguments. The first argument is one
feature
orrender feature
at the pixel, the second is thelayer
of the feature and will be null for unmanaged layers. To stop detection, callback functions can return a truthy value.options
Optional options.
Name Type Description layerFilter
function | undefined Layer filter function. The filter function will receive one argument, the
layer-candidate
and it should return a boolean value. Only layers which are visible and for which this function returnstrue
will be tested for features. By default, all visible layers will be tested.hitTolerance
number | undefined Hit-detection tolerance in pixels. Pixels inside the radius around the given position will be checked for features. This only works for the canvas renderer and not for WebGL. Default is
0
.Returns:
Callback result, i.e. the return value of last callback execution, or the first truthy callback return value.
-
forEachLayerAtPixel(pixel, callback, opt_this, opt_layerFilter, opt_this2){T|undefined}
src/ol/map.js, line 600 -
Detect layers that have a color value at a pixel on the viewport, and execute a callback with each matching layer. Layers included in the detection can be configured through
opt_layerFilter
.Name Type Description pixel
ol.Pixel Pixel.
callback
function Layer callback. This callback will receive two arguments: first is the
layer
, second argument is an array representing [R, G, B, A] pixel values (0 - 255) and will benull
for layer types that do not currently support this argument. To stop detection, callback functions can return a truthy value.this
S Value to use as
this
when executingcallback
.layerFilter
function Layer filter function. The filter function will receive one argument, the
layer-candidate
and it should return a boolean value. Only layers which are visible and for which this function returnstrue
will be tested for features. By default, all visible layers will 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.
-
Gets a value.
Name Type Description key
string Key name.
Returns:
Value.
-
Get the map controls. Modifying this collection changes the controls associated with the map.
Returns:
Controls.
-
Get the coordinate for a given pixel. This returns a coordinate in the map view projection.
Name Type Description pixel
ol.Pixel Pixel position in the map viewport.
Returns:
The coordinate for the pixel position.
-
Returns the coordinate in view projection for a browser event.
Name Type Description event
Event Event.
Returns:
Coordinate.
-
Returns the map pixel position for a browser event relative to the viewport.
Name Type Description event
Event Event.
Returns:
Pixel.
-
Get the map interactions. Modifying this collection changes the interactions associated with the map.
Interactions are used for e.g. pan, zoom and rotate.
Returns:
Interactions.
-
Get a list of object property names.
Returns:
List of property names.
-
Get the layergroup associated with this map.
Returns:
A layer group containing the layers in this map.
-
Get the collection of layers associated with this map.
Returns:
Layers.
-
Get an overlay by its identifier (the value returned by overlay.getId()). Note that the index treats string and numeric identifiers as the same. So
map.getOverlayById(2)
will return an overlay with id'2'
or2
.Name Type Description id
string | number Overlay identifier.
Returns:
Overlay.
-
Get the map overlays. Modifying this collection changes the overlays associated with the map.
Returns:
Overlays.
-
Get the pixel for a coordinate. This takes a coordinate in the map view projection and returns the corresponding pixel.
Name Type Description coordinate
ol.Coordinate A map coordinate.
Returns:
A pixel position in the map viewport.
-
Get an object of all property names and values.
Returns:
Object.
-
Get the version number for this object. Each time the object is modified, its version number will be incremented.
Returns:
Revision.
-
Get the size of this map.
Returns:
The size in pixels of the map in the DOM.
-
getTarget(){Element|string|undefined}
src/ol/map.js, line 674 -
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.
-
getTargetElement(){Element}
src/ol/map.js, line 687 -
Get the DOM element into which this map is rendered. In contrast to
getTarget
this method always return anElement
, ornull
if the map has no target.Returns:
The element that the map is rendered in.
-
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}
src/ol/map.js, line 842 -
Get the element that serves as the map viewport.
Returns:
Viewport.
-
hasFeatureAtPixel(pixel, opt_options){boolean}
src/ol/map.js, line 623 -
Detect if features intersect a pixel on the viewport. Layers included in the detection can be configured through
opt_layerFilter
.Name Type Description pixel
ol.Pixel Pixel.
options
Optional options.
Name Type Description layerFilter
function | undefined Layer filter function. The filter function will receive one argument, the
layer-candidate
and it should return a boolean value. Only layers which are visible and for which this function returnstrue
will be tested for features. By default, all visible layers will be tested.hitTolerance
number | undefined Hit-detection tolerance in pixels. Pixels inside the radius around the given position will be checked for features. This only works for the canvas renderer and not for WebGL. Default is
0
.Returns:
Is there a feature at the given pixel?
-
on(type, listener, opt_this){ol.EventsKey|Array.<ol.EventsKey>} inherited
src/ol/observable.js, line 99 -
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. If called with an array of event types as the first argument, the return will be an array of keys.
-
once(type, listener, opt_this){ol.EventsKey|Array.<ol.EventsKey>} inherited
src/ol/observable.js, line 124 -
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. If called with an array of event types as the first argument, the return will be an array of keys.
-
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).
-
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).
-
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).
-
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()
src/ol/map.js, line 1136 -
Request a map rendering (at the next animation frame).
-
renderSync()
src/ol/map.js, line 1124 -
Requests an immediate render in a synchronous manner.
-
Sets a value.
Name Type Description key
string Key name.
value
* Value.
silent
boolean Update without triggering an event.
-
setLayerGroup(layerGroup)
src/ol/map.js, line 1291 -
Sets the layergroup of this map.
Name Type Description layerGroup
ol.layer.Group A layer group containing the layers in this map.
-
Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).
Name Type Description values
Object.<string, *> Values.
silent
boolean Update without triggering an event.
-
setSize(size)
src/ol/map.js, line 1302 -
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)
src/ol/map.js, line 1314 -
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)
src/ol/map.js, line 1325 -
Set the view for this map.
Name Type Description view
ol.View The view that controls this map.
-
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
. -
Unsets a property.
Name Type Description key
string Key name.
silent
boolean Unset without triggering an event.
-
updateSize()
src/ol/map.js, line 1345 -
Force a recalculation of the map viewport size. This should be called when third-party code changes the size of the map viewport.