Class: Map

module:map.Map

The map is the core component of the Geoportail V3 API. This constructor instantiates and render a lux.Map object.

Constructor

new Map(options)

Parameters:
Name Type Description
options

Map options.

Name Type Description
mouseWheelZoom boolean (defaults to true)

Allows the user to zoom the map by scrolling the mouse wheel.

popupContentTransformer function | undefined

Function called to transform the result of the information popup.

popupAutoPan boolean (defaults to false)

If the popup should automatically pan or not.

callback function | undefined

Function called when the objects are initialized.

layerInfoCallback function | undefined

Function called when an info layer is return.

bgLayer string (defaults to 'basemap_2015_global')

Identifier of background layer.

bgLayerStyle string | undefined

Style to apply to vector tile background layer.

bgLayerStyleXYZ string | undefined

XYZ layer to apply to vector tile background layer when printing. Ex: 'https://vectortiles.geoportail.lu/styles/roadmap/{z}/{x}/{y}.png'.

bgSelector module:map~BgSelectorOptions | undefined

Set the presence of a background selector control in the map.

controls ol.Collection.<ol.control.Control> | Array.<ol.control.Control> | undefined

Controls initially added to the map.

interactions ol.Collection.<ol.interaction.Interaction> | Array.<ol.interaction.Interaction> | undefined

Interactions initially added to the map.

features module:map~FeaturesOptions | undefined

Set the presence of features to recenter on & to show markers for.

layerManager LayerManagerOptions | undefined

Set the presence of a layer manager control. (not included by default)

layerOpacities Array.<number> | undefined

Array of opacities for the layers.

layerVisibilities Array.<boolean> | undefined

Array of visibilities for the layers.

layers Array.<(string|number)> | undefined

Array of overlay layer identifiers.

zoomToExtent boolean | undefined

Set the presence of a ZoomToExtent control in the map. (not included by default).

mousePosition Element | string | undefined

The container for map popups, either the element itself or the id of the element.

popupTarget Element | string | undefined

The container for map popups, either the element itself or the id of the element.

popupClassPrefix string | undefined

The css class of the element that contains each row.

position ol.Coordinate | undefined

The initial position of the center for the map view. The coordinate system for the center is specified with the positionSrs option. If a center is defined in the view, then this parameter will override the center defined in the view.

positionSrs string | number (defaults to 2169)

The projection of the position coordinates.

queryableLayers Array.<(string|number)> | undefined

Array of queryable layers.

search module:map~SearchOptions | undefined

The search configuration.

showLayerInfoPopup boolean | undefined

If set to true, it displays the feature information in a popup or in popupTarget element.

target Element | string

The container for the map, either the element itself or the id of the element.

view ol.View | undefined

The map's view.

zoom number | undefined

Zoom level used to calculate the initial resolution for the view. If zoom are defined here and in the view, this parameter will override the view one.

Source:
Example
// To render a map, the API needs to know the element where to display the map (target),
// the predefined background layer (bgLayer) to display,
// the predefined layers (layers),
// the starting zoom level (zoom),
// the central position of the map (position)
var map = new lux.Map({
  target: 'map1',
  bgLayer: 'basemap_2015_global',
  zoom: 18,
  position: [76771, 72205]
});

Members

fit experimental

Fit the map to an extent. The default extent is content of a vector layer.

Source:

Methods

activateModifyDrawing(enabled)

Draw a polygon on the map.

Parameters:
Name Type Description
enabled boolean

the callback function.

Source:

addBgSelector(target, bglayers)

It adds a simple background selector control into a specific html element.

Parameters:
Name Type Description
target Element | string

Dom element or id of the element to render bgSelector in.

bglayers Array.<(string|number)> | undefined

Array of overlay layer identifiers. 'blank' acts as blank layer.

Source:
See:

addGeoJSON(url, opt_optionsopt) → {Promise}

It displays a GeoJSON file on the map.

Parameters:
Name Type Description
url string

Url to the GeoJSON file.

options

Options.

Name Type Description
onFeatureAdd function | undefined

Callback function called when a feature is added.

fit boolean | undefined

True if map should fit to the vector. Default and undefined are true.

reloadInterval number | undefined

Interval after which to reload the vector layer (in seconds).

style ol.StyleFunction | undefined

The style function.

name string | undefined

The layer name.

click boolean | undefined

If set, the popup is displayed when clicking the feature.

onClick function | undefined

If set, and if click is true then the function is called with the feature as parameter.

target Element | string | undefined

The container for the feature popup, either the element itself or the id of the element.

Source:
Returns:

The vector layer promise.

Type
Promise

addGeoJSONObject(geojson, opt_optionsopt) → {Promise}

It displays a GeoJSON object on the map. The default data projection is EPSG:4326.

Parameters:
Name Type Description
geojson Object

The GeoJSON object.

options

Options.

Name Type Description
onFeatureAdd function | undefined

Callback function called when a feature is added.

fit boolean | undefined

True if map should fit to the vector. Default and undefined are true.

reloadInterval number | undefined

Interval after which to reload the vector layer (in seconds).

style ol.StyleFunction | undefined

The style function.

name string | undefined

The layer name.

click boolean | undefined

If set, the popup is displayed when clicking the feature.

onClick function | undefined

If set, and if click is true then the function is called with the feature as parameter.

target Element | string | undefined

The container for the feature popup, either the element itself or the id of the element.

Source:
Returns:

The vector layer promise.

Type
Promise

addGPX(url, opt_optionsopt) → {Promise}

It displays a GPX file on the map.

Parameters:
Name Type Description
url string

Url to the GPX file.

options

Options.

Name Type Description
onFeatureAdd function | undefined

Callback function called when a feature is added.

fit boolean | undefined

True if map should fit to the vector. Default and undefined are true.

reloadInterval number | undefined

Interval after which to reload the vector layer (in seconds).

style ol.StyleFunction | undefined

The style function.

name string | undefined

The layer name.

click boolean | undefined

If set, the popup is displayed when clicking the feature.

onClick function | undefined

If set, and if click is true then the function is called with the feature as parameter.

target Element | string | undefined

The container for the feature popup, either the element itself or the id of the element.

Source:
See:
Returns:

The vector layer promise.

Type
Promise

addKML(url, opt_optionsopt)

It displays a KML file on the map.

Parameters:
Name Type Description
url string

Url to the KML file.

options

Options.

Name Type Description
onFeatureAdd function | undefined

Callback function called when a feature is added.

fit boolean | undefined

True if map should fit to the vector. Default and undefined are true.

reloadInterval number | undefined

Interval after which to reload the vector layer (in seconds).

style ol.StyleFunction | undefined

The style function.

name string | undefined

The layer name.

click boolean | undefined

If set, the popup is displayed when clicking the feature.

onClick function | undefined

If set, and if click is true then the function is called with the feature as parameter.

target Element | string | undefined

The container for the feature popup, either the element itself or the id of the element.

Source:
See:

addLayer(layer)

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

Parameters:
Name Type Description
layer ol.layer.Base

Layer.

Source:
See:

addLayerById(layer, opt_opacityopt, opt_visibilityopt)

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

Parameters:
Name Type Description
layer string | number

The layer id.

opacity number | undefined

The layer opacity. Default is 1.

visibility boolean | undefined

The layer visibility. Default is true.

Source:
See:

addMyMapLayer(options) → {Promise}

It loads a MyMaps layer.

Parameters:
Name Type Description
options

The options.

Name Type Description
fitToExtent boolean (defaults to true)

Fit to the mymaps extent.

mapId string | undefined

The map identifier.

mapIds Array.<string> | undefined

An array of map identifiers.

name string | undefined

The name of the mymaps layer.

profileTarget string | undefined

The id of the element in which to put the profile (without #). Optional. It is recommended to set the display style to none at first. The display will then be set to block adequately.

onload function | undefined

The function called once the map is loaded.

layerVisibility boolean | undefined

The layer visibility. Default is visible.

showPopup boolean | undefined

If true, the popup is displayed on click. Default is True.

onClick function | undefined

If set, the function is called when clicking on the object and the popup is not displayed.

Source:
See:
Returns:

Promise of the mymaps object.

Type
Promise
Example
var map8 = new lux.Map({
  target: 'map8',
  bgLayer: 'topo_bw_jpeg',
  zoom: 12,
  position: [76825, 75133]
});
map8.addMyMapLayer({
  mapId: '0416ef680fbe4cdaa2d8009262d1127c'
});

addSearch(target, dataSetsopt, onSelectopt, selectFirstopt)

It adds the search control into an html element.

Parameters:
Name Type Description
target Element | string

Dom element or id of the element to render search widget in.

dataSets Array.<string> (defaults to ['Adresse')

Array of layer used as search sources.

onSelect function | undefined

Optional function called when result is selected.

selectFirst boolean | undefined

Optional True select the first result element on enter.

Source:
See:

createVectorLayer(style) → {VectorLayer}

Create a new empty vector layer.

Parameters:
Name Type Description
style Style | Array.<Style> | ol.StyleFunction | undefined

The style to apply to the layer.

Source:
Returns:

The created layer.

Type
VectorLayer

destroyMap()

Destroy the map.

Source:

disableDrawTool()

Disable the current drawing tool.

Source:

enableDrawLine(onDrawEnd)

Draw a polygon on the map.

Parameters:
Name Type Description
onDrawEnd function | undefined

the callback function.

queryLayer. boolean | undefined
Source:

enableDrawPoint(onDrawEnd)

Draw a point on the map.

Parameters:
Name Type Description
onDrawEnd function | undefined

the callback function.

Source:

enableDrawPolygon(onDrawEnd)

Draw a polygon on the map.

Parameters:
Name Type Description
onDrawEnd function | undefined

the callback function.

Source:

enableQueryOnClick()

Enable query layer after clicking on the map.

Parameters:
Name Type Description
queryOnClick. boolean
Source:

enableQueryOnDrawEnd()

Enable query layer after finishing to draw on the map.

Parameters:
Name Type Description
queryOnDrawEnd. boolean
Source:

enableShowSelectedFeature(showSelectedFeature)

If set to true, then it allows to display the clicked feature.

Parameters:
Name Type Description
showSelectedFeature boolean
Source:

exportGeoJSON(fArray, opt_optionsopt, exportMeasuresopt) → {string}

Transforms features into geojson

Parameters:
Name Type Description
fArray Array.<ol.Feature>

features array.

options olx.format.GeoJSONOptions | undefined

Options.

exportMeasures boolean | undefined

True if length and area should be added to attributes.

Source:
Returns:

The geojson string.

Type
string

getDrawingLayer() → {VectorLayer}

Get the layer containing drawn features.

Source:
Returns:

The show layer.

Type
VectorLayer

getGeometryArea(geometry, srs) → {number}

Get the area of a geometry in square meters.

Parameters:
Name Type Description
geometry ol.geom.Geometry

The geometry the get the area.

srs string

the geometry's srs. Default is EPSG:3857.

Source:
Returns:

The spherical area (in square meters).

Type
number

getGeometryLength(geometry, srs) → {number}

Get the length of a geometry in meters.

Parameters:
Name Type Description
geometry ol.geom.Geometry

The geometry the get the area.

srs string

the geometry's srs. Default is EPSG:3857.

Source:
Returns:

The spherical length (in meters).

Type
number

getMapReadyPromise() → {Promise}

Get the promise to have a map in a ready state.

Source:
Returns:

Promise of a configured map.

Type
Promise

getPrintSpec()

Get the print spec.

Source:

getShowLayer() → {VectorLayer}

Get the layer containing highlighted features.

Source:
Returns:

The show layer.

Type
VectorLayer

print(nameopt, layoutopt, scaleopt, firstPagesUrlsopt, callbackopt, formatopt)

Prints the current map.

Parameters:
Name Type Description
name string | undefined

The title of the map.

layout string | undefined

The layout of the map. Default is A4 landscape or A4 portrait depending on the map size. Available values are : A4 landscape, A4 portrait, A3 landscape, A3 portrait, A2 landscape, A2 portrait, A1 landscape, A1 portrait, A0 landscape, A0 portrait

scale number | undefined

The scale to use.

firstPagesUrls Array.<Object> | undefined

An array containing urls and type of pages that will be introduced at the beginning of the pdf. Only html and pdf are supported. [{'url': 'http://url1', 'html'},{'url': 'http://url2' 'pdf'}]

callback function | undefined

Optional callback function.

format String | undefined

the output format. Default value is pdf.

Source:
Example
map.print();

removeDrawings()

Remove the drawings.

Source:

setCenter(coordinate, zoom, positionSrs)

Set the center of the current view in EPSG:2169.

Parameters:
Name Type Description
coordinate ol.Coordinate

The coordinate of the center.

zoom number | undefined

The zoom numer.

positionSrs string | number | undefined

The projection of the position coordinates. Default is 2169.

Source:

setLanguage(lang)

Parameters:
Name Type Description
lang string

Set the language.

Source:

setLayerInfoCb(layerInfoCb)

Set the information callback function.

Parameters:
Name Type Description
layerInfoCb function | undefined

The callback function.

Source:

setPopupTarget(optPopupTarget, optPopupClass)

Sets the popup target or undefined to let the api create popup.

Parameters:
Name Type Description
optPopupTarget Element | string | undefined

The container for map popups, either the element itself or the id of the element. Undefined lets the popup be created by the api.

optPopupClass string | undefined

The css class of the row.

Source:

setQueryableLayers(queryableLayers)

Set the queryable layers. If undefined then use the default value from metadata.

Parameters:
Name Type Description
queryableLayers Array.<(string|number)> | undefined

An array of queryable layers

Source:

setShowlayerStyle(style)

Parameters:
Name Type Description
style Style | Array.<Style> | ol.StyleFunction | null | undefined

The style of the show layer.

Source:

showFeatures(layer, ids, opt_clicknullable, opt_target, isShowMarker, maxZoom, callback)

Parameters:
Name Type Description
layer string | number

The layer identifier

ids Array.<(string|number)>

Array of features identifiers

click boolean

True if click is needed to show popup

target Element | string | undefined

Element to render popup content in

isShowMarker boolean | undefined

True if a marker has to be displayed.

maxZoom number | undefined

The maximum zoom to fit.

callback function | undefined

Optional callback function called for each id.

Source:

showLayerInfoPopup(show)

Show a marker on the map at the given location.

Parameters:
Name Type Description
show boolean

Set to true will allow to display the feature information popup when clicking on an object.

Source:

showMarker(opt_optionsopt) → {Overlay}

Show a marker on the map at the given location.

Parameters:
Name Type Description
options

Config options

Name Type Description
id string | number | undefined

Set the overlay id. The overlay id can be used with the ol.Map#getOverlayById method.

noPopupOnTransparency boolean | undefined

Allow to deactivate popup when clicking on a transparent part of the marker. This property is experimental. The marker should come from the same source as the page, or the image server has to set the following header Access-Control-Allow-Origin "*"

position ol.Coordinate | undefined

Position of the marker. If not set, the marker is displayed at the center of the map.

positionSrs string | number (defaults to 2169)

The projection of the position coordinates.

autoCenter boolean | undefined

Tells whether the map should be recentered to the marker position.

iconURL string (defaults to 'https://apiv4.geoportail.lu/proj/1.0/build/apidoc/examples/icon.png')

URL to an image.

positioning string | undefined

Positioning of the icon. See https://openlayers.org/en/latest/apidoc/ol.html#.OverlayPositioning

html string | undefined

If set, HTML code or simple text that will be displayed when clicking on the marker.

click boolean | undefined

If set, the popup is displayed when clicking the marker.

target Element | string

The container for the map, either the element itself or the id of the element.

onClick function | undefined

If set, the function is called when clicking on the marker.

Source:
Returns:

The overlay containing the marker or null if the marker target is not conform.

Type
Overlay

showPopup(position, title, content) → {Overlay}

It shows a popup.

Parameters:
Name Type Description
position ol.Coordinate

The position of the popup.

title string

The popup title.

content string

The popup content.

Source:
Returns:

The popup overlay.

Type
Overlay