Class: Map

cercalia.Map

The map is the main API component. You can use it for painting markers, features, etc...
Uses ol.Map 'core' OpenLayers3 .
For access to OpenLayers object, use the getMap() function

Example for creating the map:

    var map = new cercalia.Map({
        target:'divMap',
        controls: []
    });

We offer several basemaps: cercalia.MapTypes.CERCALIA, cercalia.MapTypes.OSM, cercalia.MapTypes.SATELLITE or cercalia.MapTypes.HYBRID. It's also possible to add or change a base map using WMS requests.

Name Type Description
options

Map options

Name Type Description
altRotation string | undefined optional

Enable or disable the ALT (keyboard) rotation map.

bounds cercalia.Bounds | undefined optional

Initial map bounding box. Default: null.

center cercalia.LonLat | undefined optional

Center map coordinates. Default values x=-2.530985346701069, y=40.14298996438731

controls Array.<string> | string | undefined optional

Map controls to include. Values:

  • cercalia.MapControls.CleanControl
  • cercalia.MapControls.CustomControl
  • cercalia.MapControls.CustomSwitcher
  • cercalia.MapControls.DragControl
  • cercalia.MapControls.FullScreen
  • cercalia.MapControls.LayerSwitcher
  • cercalia.MapControls.Logistics
  • cercalia.MapControls.MeasureControl
  • cercalia.MapControls.MeteoControl
  • cercalia.MapControls.RotateNorth
  • cercalia.MapControls.ScaleLine
  • cercalia.MapControls.Traffic
  • cercalia.MapControls.Zoom
  • cercalia.MapControls.ZoomSlider

    If you want a map without controls put value 'none'.
    Default [cercalia.MapControls.Zoom,cercalia.MapControls.FullScreen].
centerOnGeolocation boolean | undefined optional

Use the user location to center the map. Default: false.

defaultClick function | undefined optional

Assign function to click on map. Function parameters: (1->pixel, 2->cercalia.LonLat).
1) Pixel where clicked with mouse right click.
2) Map coordinate.

disableMouseOverEvents boolean | undefined optional

Disables mouse over events. Recommended for better performance when there are a lot of markers drawn in map. And if marker/feature mouseOver/mouseOut events aren't needed.

mapLayers Array.<string> | string | undefined optional

List of maps to add to LayerSwitcher control. Possible values in array: cercalia.MapTypes.CERCALIA, cercalia.MapTypes.OSM,cercalia.MapTypes.OPENSTREETMAP, cercalia.MapTypes.SATELLITE, cercalia.MapTypes.HYBRID.

mapType string | undefined optional

Default base map, possible values: cercalia.MapTypes.CERCALIA, cercalia.MapTypes.OSM,cercalia.MapTypes.OPENSTREETMAP, cercalia.MapTypes.SATELLITE, cercalia.MapTypes.HYBRID.
Default value cercalia.MapTypes.CERCALIA

minZoom number | undefined optional

Minimum zoom. Default value 2

maxZoom number | undefined optional

Maximum zoom. Default value 19

onRotationEnd function | undefined optional

Function is called when the rotation of the map changes (called at the event's end).

onZoomEnd function | undefined optional

Function is called when the zoom of the map changes (called at the event's end).

onOverlapMarkersEnd function | undefined optional

Function called after overlap markers.

projectionCode string | undefined optional

The projection. Default is EPSG:3857 (Spherical Mercator).

restrictedBounds cercalia.Bounds | undefined optional

Bounding box limits for map navigation. Default null.

rightClickMenu boolean | undefined optional

Enable/Disable menu on mouse right click. Default true.

rightClickFunction function | undefined optional

Assign function to mouse right click. For apply this option it's necessary to disable contextmenu on map initialization with option (rightClickMenu:false).
The function parameters are: (1->pixel, 2->cercalia.LonLat).
1) Pixel where clicked with mouse right click.
2) Map coordinate.

Default: null.

hideRightClickMenuOptions boolean | undefined optional

deprecated Hide default options. (Obtain address, Route from here, Route to here). Default: false.

rightClickMenuOptions Array.<string> | undefined optional

Map rightClick menu options to include. Values:

  • cercalia.ContextMenuOptions.Location
  • cercalia.ContextMenuOptions.Routing

    If you want a map without rightClick menu options put value [].
    Default [cercalia.ContextMenuOptions.Location, cercalia.ContextMenuOptions.Routing].
restrictedBounds cercalia.Bounds | undefined optional

Extension bounds. Navigation will be restricted to this bounds. Default false.

rotation number | undefined optional

Initial map rotation (degrees). Default value 0.

separateOverlapMarkersOnZoom number

Separate overlapped markers from zoom level. Default is disabled

scaleUnits string | undefined optional

Change units for the scale line. Supported values are 'metric', 'imperial'. Default metric.

target string

HTML element ID map container. Mandatory field.

zoom number | undefined optional

Initial zoom level [0-19]. Default value 6

Members

"Loading" overlay, blocks the map use

Methods

Add a control in the map, by parameter

Name Type Description
control cercalia.Control

Paint cercalia.Feature on the map.

Name Type Description
feature cercalia.Feature
layer ol.Layer | undefined optional

addFeatures(features, layer)

Paint several cercalia.Feature on the map. Must send an Array.

Name Type Description
features Array.<cercalia.Feature>

Array de cercalia.Feature

layer ol.layer

Adds a layer ol.layer.Layer specifying the position (optional). The layers are declarated in an array and the Z value works from less to more. The Layer basemap (map), is fixed in the first position 0.
If you need to change the baseLayer, change it to position 1 or remove the baseLayer.

Name Type Description
layer ol.layer
position number

Paint cercalia.Linestring on the map

Name Type Description
linestring cercalia.Linestring

addLinestrings(linestrings)

Paint on the map the cercalia.Linestring list. In this function must send an Array.

Name Type Description
linestrings Array.<cercalia.Linestring>

Paint cercalia.Marker list on the map.

Name Type Description
marker cercalia.Marker

Paint on the map the cercalia.Marker list. In this function must send an Array.

Name Type Description
markers Array.<cercalia.Marker>

addWMSLayer(wmsLayer, position)

Adds a WMS layer cercalia.WMS to the map

Name Type Description
wmsLayer cercalia.WMS
position number

WMSLayer position. If not declared, it's included just one level over the basemap.

centerToFeatures(features, changeZoom, animation)

Center the map

Name Type Description
features Array.<cercalia.Feature> | cercalia.Feature

Features list or object.

changeZoom number

Change zoom on features center. Default: true

animation boolean

Animation. Default: true

centerToMarkers(markers, changeZoom, animation)

Centers the map with animation (or not) to the markers list. Optionally it's possible to change the zoom for including all the markers. If markers array is not specified, by default centers to all markers

Name Type Description
markers Array.<cercalia.Marker> | undefined optional
changeZoom boolean

Default: true

animation boolean

Default: true

Resets services

Close all popups opened

coordToPixel(lonLat){ol.Pixel}

Returns the pixel value from a coordinate

Name Type Description
lonLat cercalia.LonLat

createContextMenuOption(buttonName, clickFunction, id)

Add a new option in context menu, adding a function on click to this option.

Name Type Description
buttonName string

Text to show in the neu context menu option

clickFunction function

Function to call linked to new button

id string

Option's identifier.

Create topbar

Create a WMS POIs layer, specifying the categories to be painted.
Contact with Nexus Geografics for additional information and use.

Name Type Description
categories Array.<string> | string

Disable the active controls

Destroy function

Disable markers clustering. Every marker will be painted singly, with its icon.

Disable the painting status

enableClustering(distance, clickFunction, mouseOverFunction, doubleClickFunction, mouseOutFunction)

Enable markers clustering. Note: When clustering is enabled drag markers won't work.

Name Type Default Description
distance number | undefined 40 optional

Distance, in pixels, to group markers with clusters. Default value: 40.

clickFunction function | undefined optional

Call function on cluster click.
Parameters avaliable (clusterFeature, features).
First parameter it's an object ol.Feature visible on map as a cluster,
Second parameter it's a cercalia.Marker array objects with the features contained in a cluster.

mouseOverFunction function | undefined optional

Call function on cluster mouseover. Same parameters used in 'clickFunction' event

doubleClickFunction function | undefined optional

Call function on double click on cluster.
Parameters avaliable (clusterFeature, features).

mouseOutFunction function | undefined optional

Call function on cluster mouseout. Same parameters used in 'clickFunction' event

enableDrawInteraction(type, dragFeatures, styles, drawEndFunction)

Enable the painting status. The features can be draggables, changing the features styles.

Name Type Description
type string

Type [Point|LineString|Polygon|Circle]

dragFeatures boolean | undefined optional

Boolean. true or false.

styles Object | undefined optional

JS object with the style values: [strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity, radius]. For example: {strokeColor:'#ff0000',fillColor:'#00ff00',radius:5,fillOpacity:0.5}

drawEndFunction function | undefined optional

Call function when user finish drawing the feature. Send the same feature painted

enableFeatureEditable(enable)

Set the features as editables if it isn't, or change to not editable if it's editable.

Name Type Description
enable boolean

Set on/off the editable mode.

Export PNG image

Name Type Description
filename string | undefined optional

fitBounds(bounds, animation)

Fit the bounds: change the current map bounds to new bounds. By default applies animation effect

Name Type Description
bounds cercalia.Bounds

New bounds

animation boolean

True/False, if want to apply animation or not. Default: true

Obtains the geocode at the API access point It is possible to declare a callback function, to be executed when obtains the geocode. When callback function is not avaliable, the map is centered to API access point.

Name Type Description
callbackFn function

getBaseLayer(){ol.layer.Tile}

Returns the layer (ol.layer.Tile) used as basemap

Returns the current bounds

Returns:
Current bounds, according to the zoom level, position and widht-height

Returns the map center.

Returns:
Coordinates.
Returns:
Object ClassName. Value: cercaila.Map.
Name Type Description
position cercalia.LonLat
Returns:
Nearest feature to coordinate
Name Type Description
position cercalia.LonLat
Returns:
Nearest marker to coordinate

getContextMenuOverlay(){ol.Overlay}

getControlsByName(controlName){ol.Control}

Obtains the map control from its name. Complete controls list (if are created):

  • cercalia.MapControls.CleanControl
  • cercalia.MapControls.DragControl
  • cercalia.MapControls.DrawControl
  • cercalia.MapControls.FullScreen
  • cercalia.MapControls.LayerSwitcher
  • cercalia.MapControls.Logistics
  • cercalia.MapControls.MeasureControl
  • cercalia.MapControls.MeteoControl
  • cercalia.MapControls.RotateNorth
  • cercalia.MapControls.ScaleLine
  • cercalia.MapControls.StreetView
  • cercalia.MapControls.Traffic
  • cercalia.MapControls.Zoom
  • cercalia.MapControls.ZoomSlider
Name Type Description
controlName string

getDragInteraction(){ol.interaction.DragInteraction}

Returns the drag interaction.

getDrawInteraction(){ol.interaction.DrawInteraction}

Returns the draw interaction.

getDrawLayer(){ol.layer.Vector}

Returns the layer (ol.layer.Vector) used for painting on the map.

Returns:
layer
Name Type Description
evt event

Obtains pixel

Name Type Description
evt event

Obtain all the cercalia.Feature painted on the map

Returns:
Linestring list painted on the map

Returns the map internal ID.

Returns:
map internal ID.
Returns:
dragInteraction

getLayerByName(layerName){ol.layer}

Name Type Description
layerName string
Returns:
Layer objeto ol3

getLayerIndexByName(layerName){number}

Obtains the layer position (Z value). The layers are painted respecting Z position: 0 is the base map.

Name Type Description
layerName string
Returns:
Layer position

Obtain all the cercalia.Linestring painted on the map

Returns:
Linestrings list painted on the map
Returns:
Returns the reference to cercalia.widget.MainMenu

Returns the OpenLayers3 object ol.Map

Returns:
Map
Returns:
marker

Obtain all the cercalia.Marker painted on the map

Returns:
Marker list painted on the map

getOverlappedMarkers(currentExtentView, tolerance){Array.<Array.<cercalia.Marker>>}

Get Overlapped markers

Name Type Description
currentExtentView boolean | undefined optional

If true returns only visible markers at the moment, if not null or false it returns all markers

tolerance boolean | undefined optional

Tolerance in meters.

getProjectionCode(){string}

Obtains the map projection code

Returns:
EPSG code. For example: EPSG:3857.

getRightClickMenuOptions(){array.<string>}

Returns:
return rightClick menu options.
Returns:
routeMap
Returns:
scale units. Values metric or imperial
Returns:
View options from cercalia map.
Returns:
Current zoom level of map.

Hide all controls

Hide all labels cercalia.Label from markers painted on the map

Hide "Loading..."

Open the context menu at the coordinates specified by parameters. If not specified, opens the context menu in the map center according to the current position.

Name Type Description
lonLat cercalia.LonLat | undefined optional

Coordinate

Show all markers popups. Only for markers with popup created

Separate overlapped markers when its have same position.

panTo(lonLat, animation, duration)

Moves the map to the new center. Optional: animation effect-

Name Type Description
lonLat cercalia.LonLat

Coordinate

animation string

Boolean animation effect. Values true or false, specifying the type of animation: cercalia.MapAnimation.ROTATE_LEFT, cercalia.MapAnimation.ROTATE_RIGHT, cercalia.MapAnimation.PAN, cercalia.MapAnimation.ELASTIC, cercalia.MapAnimation.BOUNCE, cercalia.MapAnimation.FLY, cercalia.MapAnimation.SPIRAL

duration number

Animation duration (in miliseconds). Defaulf 2000.

panToBounds(bounds, animation, duration)

Map center maintaining the zoom level

Name Type Description
bounds cercalia.Bounds

Mapbounds.

animation boolean

Boolean for apply or not animation effect. Values: true or false.

duration number

Animation duration (in miliseconds). Default 2000.

pixelsToMeters(pixels){number}

Calculate the real distance in meters, from pixels values.

Name Type Description
pixels number
Returns:
meters

Returns the coordinate from a pixel value

Name Type Description
pixel ol.Pixel
Returns:
Coordinate

Clean all features

Clean all linestrings

Clean all markers and popups

Clean all overlays painted on the map

Remove API markers list from map

Name Type Description
markers cercalia.Marker | Array.<cercalia.Marker>
Deprecated
  • deprecated function, equivalent: map.getRouteMap().removeRoute();

    Clean all the features painted on the map with draw tool. Layer 'DrawLayer'

    removeFeatures(features, layer)

    Remove features list from map

    Name Type Description
    features cercalia.Feature | Array.<cercalia.Feature>
    layer ol.Layer | undefined optional

    If not defined it will remove features in internal Cercalia layer.

    Clean the layer specified by parameter

    Name Type Description
    layer ol.layer

    removeLinestrings(linestrings)

    Remove linestring list from map

    Name Type Description
    linestrings cercalia.Linestring | Array.<cercalia.Linestring>

    Remove markers list from map

    Name Type Description
    markers cercalia.Marker | Array.cercalia.Marker

    Remove a WMS layer cercalia.WMS from the map

    Name Type Description
    wmsLayer cercalia.WMS

    Clean POIs layers, if painted

    Rotates the map degrees, by parameter

    Name Type Description
    angle number

    Angle (degrees).

    Name Type Description
    mapType string | cercalia.WMS | ol.layer.Layer | ol.layer.Group

    Change base map.
    Maps avaliable by default. String:

    • cercalia.MapTypes.CERCALIA Cercalia
    • cercalia.MapTypes.OSM Cercalia
    • cercalia.MapTypes.SATELLITE
    • cercalia.MapTypes.HYBRID

      Also can use a WMS layer (object cercalia.WMS), that will be set as base Layer. Also can add layers using OpenLayers classes ol.layer.Layer y ol.layer.Group.

    setCenter(lonLat, zoom, animation)

    Set the map center

    Name Type Description
    lonLat cercalia.LonLat

    Coordinates

    zoom number

    Zoom

    animation boolean | undefined optional

    Animation, activated by default

    Name Type Description
    func function | undefined optional

    Function

    setFeatureEditable(feature, edit)

    Set feature editable.

    Name Type Description
    feature cercalia.Feature

    Feature to be edited.

    edit boolean

    Set the feature as editable or not.

    Changes the projection to basemap and all the layers painted over it (markers, features, WMS, etc).

    Name Type Description
    projection ol.Projection

    Projection.

    setRestrictedView(minZoom, maxZoom, bounds)

    Fixes the minimum and maximum zoom level

    Name Type Description
    minZoom number | boolean

    Min zoom, false if don't want this limit

    maxZoom number | boolean

    Max zoom, false if don't want this limit

    bounds cercalia.Bounds

    Map bounds limits

    setRightClickMenuOptions(Set)

    Name Type Description
    Set array.<string>

    rightClick menu options.

    Sets the map rotation

    Name Type Description
    angle number
    Name Type Description
    routeMap cercalia.RouteMap

    Set the zoom level of map. If second parameter is specified (boolean, optional), can apply animation effect

    Name Type Description
    zoom number

    Zoom level to adjust

    animation boolean

    True/False if want to apply animation effect. Defaulf: true

    Show all controls

    Returns boolean showing if all labels are showing or hidden.

    Show all labels cercalia.Label from markers painted on the map

    Shows "Loading..."

    Show the markers painted on the map. This function is usefull when some or all markers are hidden.

    Name Type Description
    markers cercalia.Marker | Array.<cercalia.Marker>
    show boolean