靜態unAdds 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.
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.
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.
可選opt_layerFilter: (layer: Layer) => booleanLayer
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.
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.
可選opt_this: SValue to use as this when executing callback.
可選opt_layerFilter: (layer: Layer) => booleanLayer
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.
可選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.
Detect if features intersect a pixel on the viewport. Layers included in the
detection can be configured through opt_layerFilter.
Pixel.
可選opt_layerFilter: (layer: Layer) => booleanLayer
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?
Returns the geographical coordinate for a browser event.
Event.
Coordinate.
Returns the map pixel position for a browser event relative to the viewport.
Event.
Pixel.
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.
Get the map controls. Modifying this collection changes the controls associated with the map.
Controls.
Get the map overlays. Modifying this collection changes the overlays associated with the map.
Overlays.
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 interactions. Modifying this collection changes the interactions associated with the map.
Interactions are used for e.g. pan, zoom and rotate.
Interactions.
Get the layergroup associated with this map.
A layer group containing the layers in this map.
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.
Get the view associated with this map. A view manages properties such as center and resolution.
The view that controls this map.
Remove the given interaction from the map.
Interaction to remove.
The removed interaction (or undefined if the interaction was not found).
Sets the layergroup of this map.
A layer group containing the layers in this map.
Listen for a certain type of event.
The event type or array of event types.
The listener function.
可選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.
Listen once for a certain type of event.
The event type or array of event types.
The listener function.
可選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.
函數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.
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.
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-stopeventfor controls and some overlays, and one with CSS class nameol-overlaycontainerfor other overlays (see thestopEventoption 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.Collectionin layerGroups. A top-level group is provided by the library. This is what is accessed bygetLayerGroupandsetLayerGroup. Layers entered in the options are added to this group, andaddLayerandremoveLayerchange the layer collection in the group.getLayersis a convenience function forgetLayerGroup().getLayers(). Note thatol.layer.Groupis a subclass ofol.layer.Base, so layers entered in the options or added withaddLayercan be groups, which can contain further groups, and so on.參數: options
Map options.
Fires
ol.MapBrowserEvent
Fires
ol.MapEvent
Fires
ol.render.Event#postcompose
Fires
ol.render.Event#precompose
Api
stable