Class: Map

ga.Map

The map is the core component of the GeoAdmin API. In its minimal configuration it needs a view, one or more geoadmin layers, and a target container:

var map = new ga.Map({
  view: new ol.View({
    center: [600000, 200000]
  }),
  layers: [
    ga.layer.create('ch.swisstopo.pixelkarte-farbe')
  ],
  target: 'map'
});

The above snippet creates a map with a GeoAdmin layer on a 2D view and renders it to a DOM element with the id 'map'. The coordinate system EPSG:21781 is automatically set.

new ga.Map(options)

src/ga/map.js, line 59
Name Type Description
options gax.MapOptions

Map options.

Fires:

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 yes change:view

The view that controls this map.

Methods

addControl(control) inherited

src/ol/map.js, line 494

Add the given control to the map.

Name Type Description
control ol.control.Control

Control.

addInteraction(interaction) inherited

src/ol/map.js, line 506

Add the given interaction to the map.

Name Type Description
interaction ol.interaction.Interaction

Interaction to add.

addLayer(layer) inherited

src/ol/map.js, line 521

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.

Name Type Description
layer ol.layer.Base

Layer.

addOverlay(overlay) inherited

src/ol/map.js, line 532

Add the given overlay to the map.

Name Type Description
overlay ol.Overlay

Overlay.

beforeRender(var_args) inherited experimental

src/ol/map.js, line 546

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.

changed() inherited experimental

src/ol/observable.js, line 52

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

Fires:
  • change experimental

disableTooltip()

src/ga/map.js, line 350

Disable the ga.Tooltip

enableTooltip()

src/ga/map.js, line 340

Disable the ga.Tooltip

forEachFeatureAtPixel(pixel, callback, opt_this, opt_layerFilter, opt_this2){T|undefined} inherited

src/ol/map.js, line 597

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. The callback will be called with two arguments. The first argument is one feature at the pixel, the second is the layer of the feature. If the detected feature is not on a layer, but on a ol.FeatureOverlay, then the second argument to this function will be null. To stop detection, callback functions can return a truthy value.

this S

Value to use as this when executing callback.

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 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 executing layerFilter.

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} inherited

src/ol/map.js, line 638

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. Feature overlays will always be included in the detection.

Name Type Description
pixel ol.Pixel

Pixel.

callback function

Layer callback. Will receive one argument, the layer that contains the color pixel. If the detected color value is not from a layer, but from a ol.FeatureOverlay, then the argument to this function will be null. To stop detection, callback functions can return a truthy value.

this S

Value to use as this when executing callback.

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 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 executing layerFilter.

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

geocode(text)

src/ga/map.js, line 141

Geocode using api.geo.admin.ch

Name Type Description
text String

text to geocode.

get(key){*} inherited

src/ol/object.js, line 150

Gets a value.

Name Type Description
key string

Key name.

Returns:
Value.

getControls(){ol.Collection.<ol.control.Control>} inherited

src/ol/map.js, line 772

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

Returns:
Controls.

getCoordinateFromPixel(pixel){ol.Coordinate} inherited

src/ol/map.js, line 755

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.

getEventCoordinate(event){ol.Coordinate} inherited

src/ol/map.js, line 689

Returns the geographical coordinate for a browser event.

Name Type Description
event Event

Event.

Returns:
Coordinate.

getEventPixel(event){ol.Pixel} inherited

src/ol/map.js, line 700

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

Name Type Description
event Event

Event.

Returns:
Pixel.

getInteractions(){ol.Collection.<ol.interaction.Interaction>} inherited

src/ol/map.js, line 796

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.

getKeys(){Array.<string>} inherited

src/ol/object.js, line 164

Get a list of object property names.

Returns:
List of property names.

getLayerGroup(){ol.layer.Group} inherited

src/ol/map.js, line 807

Get the layergroup associated with this map.

Returns:
A layer group containing the layers in this map.

getLayers(){ol.Collection.<ol.layer.Base>} inherited

src/ol/map.js, line 817

Get the collection of layers associated with this map.

Returns:
Layers.

getOverlays(){ol.Collection.<ol.Overlay>} inherited

src/ol/map.js, line 783

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

Returns:
Overlays.

getPixelFromCoordinate(coordinate){ol.Pixel} inherited

src/ol/map.js, line 830

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.

getProperties(){Object.<string, *>} inherited

src/ol/object.js, line 174

Get an object of all property names and values.

Returns:
Object.

getRevision(){number} inherited experimental

src/ol/observable.js, line 62
Returns:
Revision.

getSize(){ol.Size|undefined} inherited

src/ol/map.js, line 856

Get the size of this map.

Returns:
The size in pixels of the map in the DOM.

getTarget(){Element|string|undefined} inherited

src/ol/map.js, line 729

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} inherited experimental

src/ol/map.js, line 742

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:
The element that the map is rendered in.

getView(){ol.View} inherited

src/ol/map.js, line 868

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} inherited

src/ol/map.js, line 878

Get the element that serves as the map viewport.

Returns:
Viewport.

hasFeatureAtPixel(pixel, opt_layerFilter, opt_this){boolean} inherited experimental

src/ol/map.js, line 669

Detect if features intersect a pixel on the viewport. 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.

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 returns true will be tested for features. By default, all visible layers will be tested. Feature overlays will always be tested.

this U

Value to use as this when executing layerFilter.

Returns:
Is there a feature at the given pixel?

highlightFeature(layerId, featureId)

src/ga/map.js, line 209

Highlight feature using api.geo.admin.ch

Name Type Description
layerId String

GeoAdmin id of the layer.

featureId String

id of the feature.

on(type, listener, opt_this){goog.events.Key} inherited

src/ol/observable.js, line 75

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 in listener.

Returns:
Unique key for the listener.

once(type, listener, opt_this){goog.events.Key} inherited

src/ol/observable.js, line 88

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 in listener.

Returns:
Unique key for the listener.

recenterFeature(layerId, featureId)

src/ga/map.js, line 176

Recenter feature using api.geo.admin.ch

Name Type Description
layerId String

GeoAdmin id of the layer.

featureId String

id of the feature.

removeControl(control){ol.control.Control|undefined} inherited

src/ol/map.js, line 1220

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} inherited

src/ol/map.js, line 1237

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} inherited

src/ol/map.js, line 1256

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} inherited

src/ol/map.js, line 1269

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() inherited

src/ol/map.js, line 1206

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

renderSync() inherited

src/ol/map.js, line 1197

Requests an immediate render in a synchronous manner.

set(key, value) inherited

src/ol/object.js, line 203

Sets a value.

Name Type Description
key string

Key name.

value *

Value.

setLayerGroup(layerGroup) inherited

src/ol/map.js, line 1376

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

src/ol/object.js, line 216

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.

setSize(size) inherited experimental

src/ol/map.js, line 1387

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

src/ol/map.js, line 1399

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

src/ol/map.js, line 1410

Set the view for this map.

Name Type Description
view ol.View

The view that controls this map.

un(type, listener, opt_this) inherited

src/ol/observable.js, line 101

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 the listener.

unByKey(key) inherited

src/ol/observable.js, line 114

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.

Name Type Description
key goog.events.Key

The key returned by on() or once().

unset(key) inherited

src/ol/object.js, line 229

Unsets a property.

Name Type Description
key string

Key name.

updateSize() inherited

src/ol/map.js, line 1430

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