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:

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.

Param: options

Map options.

Fires

ol.MapBrowserEvent

Fires

ol.MapEvent

Fires

ol.render.Event#postcompose

Fires

ol.render.Event#precompose

Api

stable

Hierarchy

Constructors

  • Parameters

    Returns Map

    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:

    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.

    Fires

    ol.MapBrowserEvent

    Fires

    ol.MapEvent

    Fires

    ol.render.Event#postcompose

    Fires

    ol.render.Event#precompose

    Api

    stable

Methods

  • Add the given control to the map.

    Parameters

    Returns void

    Api

    stable

  • Add the given interaction to the map.

    Parameters

    Returns void

    Api

    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.

    Parameters

    Returns void

    Api

    stable

  • Add the given overlay to the map.

    Parameters

    Returns void

    Api

    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.

    Parameters

    Returns void

    Api

  • Increases the revision counter and dispatches a 'change' event.

    Returns void

    Api

  • 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.

    Parameters

    Returns void

    Function

    Api

  • 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.

    Type Parameters

    • T

    Parameters

    • pixel: Pixel

      Pixel.

    • callback: ((feature, layer) => T)

      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.

        • (layer): boolean
        • Parameters

          Returns boolean

    Returns T

    Callback result, i.e. the return value of last callback execution, or the first truthy callback return value.

    Api

    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.

    Type Parameters

    • S

    • T

    • U

    Parameters

    • pixel: Pixel

      Pixel.

    • callback: ((layer, color) => T)

      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.

        • (layer, color): T
        • Parameters

          Returns T

    • Optional opt_this: S

      Value 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.

        • (layer): boolean
        • Parameters

          Returns boolean

    • Optional opt_this2: U

      Value to use as this when executing layerFilter.

    Returns T

    Callback result, i.e. the return value of last callback execution, or the first truthy callback return value.

    Api

    stable

  • Gets a value.

    Parameters

    • key: string

      Key name.

    Returns any

    Value.

    Api

    stable

  • Get the map controls. Modifying this collection changes the controls associated with the map.

    Returns Collection<Control>

    Controls.

    Api

    stable

  • Get the coordinate for a given pixel. This returns a coordinate in the map view projection.

    Parameters

    • pixel: Pixel

      Pixel position in the map viewport.

    Returns Coordinate

    The coordinate for the pixel position.

    Api

    stable

  • Returns the geographical coordinate for a browser event.

    Parameters

    • event: Event

      Event.

    Returns Coordinate

    Coordinate.

    Api

    stable

  • Returns the map pixel position for a browser event relative to the viewport.

    Parameters

    • event: Event

      Event.

    Returns Pixel

    Pixel.

    Api

    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.

    Returns Collection<Interaction>

    Interactions.

    Api

    stable

  • Get a list of object property names.

    Returns string[]

    List of property names.

    Api

    stable

  • Get the layergroup associated with this map.

    Returns Group

    A layer group containing the layers in this map.

    Observable

    Api

    stable

  • Get the collection of layers associated with this map.

    Returns Collection<Base>

    Layers.

    Api

    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.

    Parameters

    • id: string | number

      Overlay identifier.

    Returns Overlay

    Overlay.

    Api

  • Get the map overlays. Modifying this collection changes the overlays associated with the map.

    Returns Collection<Overlay>

    Overlays.

    Api

    stable

  • Get the pixel for a coordinate. This takes a coordinate in the map view projection and returns the corresponding pixel.

    Parameters

    Returns Pixel

    A pixel position in the map viewport.

    Api

    stable

  • Get an object of all property names and values.

    Returns {
        [k: string]: any;
    }

    Object.

    • [k: string]: any

    Api

    stable

  • Get the version number for this object. Each time the object is modified, its version number will be incremented.

    Returns number

    Revision.

    Api

  • Get the size of this map.

    Returns Size

    The size in pixels of the map in the DOM.

    Observable

    Api

    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.

    Returns string | Element

    The Element or id of the Element that the map is rendered in.

    Observable

    Api

    stable

  • Get the DOM element into which this map is rendered. In contrast to getTarget this method always return an Element, or null if the map has no target.

    Returns Element

    The element that the map is rendered in.

    Api

  • Get the view associated with this map. A view manages properties such as center and resolution.

    Returns View

    The view that controls this map.

    Observable

    Api

    stable

  • Get the element that serves as the map viewport.

    Returns Element

    Viewport.

    Api

    stable

  • Detect if features intersect a pixel on the viewport. Layers included in the detection can be configured through opt_layerFilter.

    Parameters

    • pixel: Pixel

      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.

        • (layer): boolean
        • Parameters

          Returns boolean

    Returns boolean

    Is there a feature at the given pixel?

    Api

  • Listen for a certain type of event.

    Parameters

    • type: string | string[]

      The event type or array of event types.

    • listener: Function

      The listener function.

    • Optional opt_this: Object

      The object to use as this in listener.

    Returns Object | Object[]

    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.

    Api

    stable

  • Listen once for a certain type of event.

    Parameters

    • type: string | string[]

      The event type or array of event types.

    • listener: Function

      The listener function.

    • Optional opt_this: Object

      The object to use as this in listener.

    Returns Object | Object[]

    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.

    Api

    stable

  • Remove the given control from the map.

    Parameters

    Returns Control

    The removed control (or undefined if the control was not found).

    Api

    stable

  • Remove the given interaction from the map.

    Parameters

    Returns Interaction

    The removed interaction (or undefined if the interaction was not found).

    Api

    stable

  • Removes the given layer from the map.

    Parameters

    Returns Base

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

    Api

    stable

  • Remove the given overlay from the map.

    Parameters

    Returns Overlay

    The removed overlay (or undefined if the overlay was not found).

    Api

    stable

  • Request a map rendering (at the next animation frame).

    Returns void

    Api

    stable

  • Requests an immediate render in a synchronous manner.

    Returns void

    Api

    stable

  • Sets a value.

    Parameters

    • key: string

      Key name.

    • value: any

      Value.

    • Optional opt_silent: boolean

      Update without triggering an event.

    Returns void

    Api

    stable

  • Sets the layergroup of this map.

    Parameters

    • layerGroup: Group

      A layer group containing the layers in this map.

    Returns void

    Observable

    Api

    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).

    Parameters

    • values: {
          [k: string]: any;
      }

      Values.

      • [k: string]: any
    • Optional opt_silent: boolean

      Update without triggering an event.

    Returns void

    Api

    stable

  • Set the size of this map.

    Parameters

    • size: Size

      The size in pixels of the map in the DOM.

    Returns void

    Observable

    Api

  • Set the target element to render this map into.

    Parameters

    • target: string | Element

      The Element or id of the Element that the map is rendered in.

    Returns void

    Observable

    Api

    stable

  • Set the view for this map.

    Parameters

    • view: View

      The view that controls this map.

    Returns void

    Observable

    Api

    stable

  • Unlisten for a certain type of event.

    Parameters

    • type: string | string[]

      The event type or array of event types.

    • listener: Function

      The listener function.

    • Optional opt_this: Object

      The object which was used as this by the listener.

    Returns void

    Api

    stable

  • Removes an event listener using the key returned by on() or once(). Note that using the ol.Observable.unByKey static function is to be preferred.

    Parameters

    • key: Object | Object[]

      The key returned by on() or once() (or an array of keys).

    Returns void

    Function

    Api

    stable

  • Unsets a property.

    Parameters

    • key: string

      Key name.

    • Optional opt_silent: boolean

      Unset without triggering an event.

    Returns void

    Api

    stable

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

    Returns void

    Api

    stable

  • Removes an event listener using the key returned by on() or once().

    Parameters

    • key: Object | Object[]

      The key returned by on() or once() (or an array of keys).

    Returns void

    Api

    stable

Generated using TypeDoc