Map options.
The map is the core component of OpenLayers. For a map to render, a view, one or more layers, and a target container are needed:
var map = new ol.Map({
view: new ol.View({
center: [0, 0],
zoom: 1
}),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map'
});
The above snippet creates a map using a ol.layer.Tile to display
ol.source.OSM OSM data and render it to a DOM element with the
id map
.
The constructor places a viewport container (with CSS class name
ol-viewport
) in the target element (see getViewport()
), and then two
further elements within the viewport: one with CSS class name
ol-overlaycontainer-stopevent
for controls and some overlays, and one with
CSS class name ol-overlaycontainer
for other overlays (see the stopEvent
option of ol.Overlay for the difference). The map itself is placed in
a further element within the viewport, either DOM or Canvas, depending on the
renderer.
Layers are stored as a ol.Collection
in layerGroups. A top-level group is
provided by the library. This is what is accessed by getLayerGroup
and
setLayerGroup
. Layers entered in the options are added to this group, and
addLayer
and removeLayer
change the layer collection in the group.
getLayers
is a convenience function for getLayerGroup().getLayers()
.
Note that ol.layer.Group
is a subclass of ol.layer.Base
, so layers
entered in the options or added with addLayer
can be groups, which can
contain further groups, and so on.
ol.MapBrowserEvent
ol.MapEvent
ol.render.Event#postcompose
ol.render.Event#precompose
stable
Add the given control to the map.
Control.
stable
Add the given interaction to the map.
Interaction to add.
stable
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 on
ol.Collection.
Layer.
stable
Add the given overlay to the map.
Overlay.
stable
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.
Rest
...var_args: PreRenderFunction[]Any number of pre-render functions.
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
.
Pixel.
Feature callback. The callback will be called with two arguments. The first argument is one feature or render feature at the pixel, the second is the layer of the feature and will be null for unmanaged layers. To stop detection, callback functions can return a truthy value.
Optional
opt_layerFilter: ((layer) => boolean)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 returns
true
will be tested for features. By default, all visible layers will
be tested.
Callback result, i.e. the return value of last callback execution, or the first truthy callback return value.
stable
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
.
Pixel.
Layer callback. This callback will recieve two arguments: first is the layer, second argument is ol.Color and will be null for layer types that do not currently support this argument. To stop detection callback functions can return a truthy value.
Optional
opt_this: SValue to use as this
when executing callback
.
Optional
opt_layerFilter: ((layer) => boolean)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 returns
true
will be tested for features. By default, all visible layers will
be tested.
Optional
opt_this2: UValue to use as this
when executing layerFilter
.
Callback result, i.e. the return value of last callback execution, or the first truthy callback return value.
stable
Get the map controls. Modifying this collection changes the controls associated with the map.
Controls.
stable
Get the coordinate for a given pixel. This returns a coordinate in the map view projection.
Pixel position in the map viewport.
The coordinate for the pixel position.
stable
Returns the geographical coordinate for a browser event.
Event.
Coordinate.
stable
Get the map interactions. Modifying this collection changes the interactions associated with the map.
Interactions are used for e.g. pan, zoom and rotate.
Interactions.
stable
Get the collection of layers associated with this map.
Layers.
stable
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'
or 2
.
Overlay identifier.
Overlay.
Get the map overlays. Modifying this collection changes the overlays associated with the map.
Overlays.
stable
Get the pixel for a coordinate. This takes a coordinate in the map view projection and returns the corresponding pixel.
A map coordinate.
A pixel position in the map viewport.
stable
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.
The Element or id of the Element that the map is rendered in.
stable
Detect if features intersect a pixel on the viewport. Layers included in the
detection can be configured through opt_layerFilter
.
Pixel.
Optional
opt_layerFilter: ((layer) => boolean)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 returns
true
will be tested for features. By default, all visible layers will
be tested.
Is there a feature at the given pixel?
Listen for a certain type of event.
The event type or array of event types.
The listener function.
Optional
opt_this: ObjectThe object to use as this
in listener
.
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.
stable
Listen once for a certain type of event.
The event type or array of event types.
The listener function.
Optional
opt_this: ObjectThe object to use as this
in listener
.
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.
stable
Remove the given interaction from the map.
Interaction to remove.
The removed interaction (or undefined if the interaction was not found).
stable
Sets the layergroup of this map.
A layer group containing the layers in this map.
stable
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).
Values.
Optional
opt_silent: booleanUpdate without triggering an event.
stable
Set the size of this map.
The size in pixels of the map in the DOM.
Set the view for this map.
The view that controls this map.
stable
Static
unRemoves an event listener using the key returned by on()
or once()
.
Note that using the ol.Observable.unByKey static function is to
be preferred.
stable
Generated using TypeDoc
Classdesc
The map is the core component of OpenLayers. For a map to render, a view, one or more layers, and a target container are needed:
The above snippet creates a map using a ol.layer.Tile to display ol.source.OSM OSM data and render it to a DOM element with the id
map
.The constructor places a viewport container (with CSS class name
ol-viewport
) in the target element (seegetViewport()
), and then two further elements within the viewport: one with CSS class nameol-overlaycontainer-stopevent
for controls and some overlays, and one with CSS class nameol-overlaycontainer
for other overlays (see thestopEvent
option of ol.Overlay for the difference). The map itself is placed in a further element within the viewport, either DOM or Canvas, depending on the renderer.Layers are stored as a
ol.Collection
in layerGroups. A top-level group is provided by the library. This is what is accessed bygetLayerGroup
andsetLayerGroup
. Layers entered in the options are added to this group, andaddLayer
andremoveLayer
change the layer collection in the group.getLayers
is a convenience function forgetLayerGroup().getLayers()
. Note thatol.layer.Group
is a subclass ofol.layer.Base
, so layers entered in the options or added withaddLayer
can be groups, which can contain further groups, and so on.Param: options
Map options.
Fires
ol.MapBrowserEvent
Fires
ol.MapEvent
Fires
ol.render.Event#postcompose
Fires
ol.render.Event#precompose
Api
stable