Class: Map

cercalia.Map


The map is the main API component. You can use it for painting markers, features, etc...
Uses ol.Map 'core' ol.Map .
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 or cercalia.MapTypes.SATELLITE. It's also possible to add or change a base map using WMS requests.

new cercalia.Map(options)

src/cercalia/map.js, line 89
Name Type Description
options

Map options

Name Type Description
altRotation boolean | undefined

Enable or disable the ALT (keyboard) rotation map.

bounds cercalia.Bounds | undefined

Initial map bounding box. Default: null.

center cercalia.LonLat | undefined

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

controls Array.<string> | undefined

Map controls to include. Values:

  • cercalia.control.MapControls.SCALELINE
  • cercalia.control.MapControls.CLEAN
  • cercalia.control.MapControls.GAS_STATIONS
  • cercalia.control.MapControls.LAYER_SWITCHER
  • cercalia.control.MapControls.METEO
  • cercalia.control.MapControls.NAVBAR
  • cercalia.control.MapControls.MOBILEBAR
  • cercalia.control.MapControls.TRAFFIC
  • cercalia.control.MapControls.ZOOM
  • cercalia.control.MapControls.LOGISTICS_RESTRICTIONS
  • cercalia.control.MapControls.ISOCHRONES
  • cercalia.control.MapControls.STREET_VIEW

    If you want a map without controls put value [].
centerOnGeolocation boolean | undefined

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

defaultClick function | undefined

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

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.

geolocationEnabled boolean | undefined

Enable automatically geolocation. Your position will be drawn to map.

greyscale boolean | undefined

Base layer colors in greyscale. Default false.

Extends

Members

cercalia.Map.DefaultMapControls{}

Methods

addBaseLayer(baseLayer)

src/cercalia/map.js, line 1583

Add base layer. Only when layer switcher control is available.

Name Type Description
baseLayer cercalia.BaseLayer

Base layer.

addControl(control, opt_position)

src/cercalia/map.js, line 2899

Add the given control to the map.

Name Type Description
control cercalia.control.Control | ol.control.Control

Control.

position number

Position.

addCustomControl(control, opt_position)

src/cercalia/map.js, line 2937

Add custom control. You can specify children position inside control container. Default append to last child.

Name Type Description
control cercalia.control.Custom

Custom control.

position number

Position.

addFeature(feature, opt_layer)

src/cercalia/map.js, line 2077

Paint cercalia.Feature list on the map.

Name Type Description
feature cercalia.Feature

Feature

layer ol.layer.Layer

Layer.

addFeatures(features, opt_layer)

src/cercalia/map.js, line 2088

Paint cercalia.Feature on the map.

Name Type Description
features

List of features.

layer ol.layer.Layer

Layer.

addLayer(layer, opt_position, opt_draggable)

src/cercalia/map.js, line 1286

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.Layer | ol.layer.Group | cercalia.Heatmap | cercalia.KML | cercalia.WMS

Layer to add.

position number

Position in array (like zIndex)

draggable boolean

If layer object is instanceof ol.layer.Vector. Optionally can disable drag events for performance. Default true.

addMarker(marker, opt_layer)

src/cercalia/map.js, line 2032

Paint cercalia.Marker list on the map.

Name Type Description
marker cercalia.Marker

Marker to add.

layer ol.layer.Layer

Layer

addMarkers(markers, opt_layer)

src/cercalia/map.js, line 2043

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

Name Type Description
markers

List of markers.

layer ol.layer.Layer

Lyaer

addWMSLayer(wmsLayer, position)

src/cercalia/map.js, line 1994

Adds a WMS layer cercalia.WMS to the map

Name Type Description
wmsLayer cercalia.WMS

WMS Layer.

position number

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

centerToFeatures(features, opt_changeZoom, opt_animation)

src/cercalia/map.js, line 1714

Center the map

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

Features list or object.

changeZoom boolean

Change zoom on features center. Default: true.

animation boolean

Enable or disable animation. Default true.

centerToMarkers(opt_markers, opt_changeZoom, opt_animation)

src/cercalia/map.js, line 1657

Centers the map 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

List Markers, if not specified center to all markers.

changeZoom boolean

Default true.

animation boolean

Enable or disable animation. Default true.

changeLogo(opt_content)

src/cercalia/map.js, line 1264

Change page logo. If content is null, then it restores default logo.

Name Type Description
content string

HTML content

closeAll()

src/cercalia/map.js, line 2979

Close all menus and reset nav bar menu view.

closePopups()

src/cercalia/map.js, line 2388

Close all open popups

coordToPixel(lonLat){ol.Pixel}

src/cercalia/map.js, line 1442

Returns the pixel value from a coordinate

Name Type Description
lonLat cercalia.LonLat

Coordinate.

Returns:
Return pixel of map.

createStaticMap(callbackFn)

src/cercalia/map.js, line 3121
Name Type Description
callbackFn function

Callback function

disableClustering()

src/cercalia/map.js, line 2646

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

disableDrawInteraction()

src/cercalia/map.js, line 2886

Disable the painting status

disableSnapping()

src/cercalia/map.js, line 2778

enableClustering(opt_distance, opt_clickFunction, opt_mouseOverFunction, opt_doubleClickFunction, opt_mouseOutFunction)

src/cercalia/map.js, line 2540

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

Name Type Default Description
distance number 40

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

clickFunction function

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

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

doubleClickFunction function

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

mouseOutFunction function

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

enableDrawInteraction(type, opt_dragFeatures, opt_styles, opt_drawEndFunction, opt_freehand)

src/cercalia/map.js, line 2795

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

Name Type Description
type string

Type [Point|LineString|Polygon|Circle|Square|Rectangle]

dragFeatures boolean

Boolean. true or false.

styles Object

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

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

freehand boolean

Operate in freehand mode for lines, polygons, and circles. This makes the interaction always operate in freehand mode

enableMouseOverEvents(enable)

src/cercalia/map.js, line 762

Enable or disable mouse over/out events. When there are thousands markers drawn then map has poor performance, so its recommended to disable

Name Type Description
enable boolean

Enable or disable

enableSnapping()

src/cercalia/map.js, line 2767

exportPNG(opt_filename)

src/cercalia/map.js, line 2947

Export PNG image

Name Type Description
filename string | undefined

Filename.

fitBounds(bounds, opt_animation, opt_size)

src/cercalia/map.js, line 1776

Fit the bounds: change the current map bounds to new bounds.

Name Type Description
bounds cercalia.Bounds

New bounds

animation boolean

Enable or disable animation. Default true.

size ol.Size

Size in pixel of the box to fit the extent into.

getBaseLayer(){ol.layer.Tile}

src/cercalia/map.js, line 1378

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

Returns:
Return baselayer

getBounds(){cercalia.Bounds|undefined}

src/cercalia/map.js, line 1760

Returns the current bounds

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

getCenter(){cercalia.LonLat|undefined}

src/cercalia/map.js, line 1389

Returns the map center.

Returns:
Return center coordinates cercalia.LonLat. Undefined if map is not setted.

getClass(){string} inherited

src/cercalia/object.js, line 41
Returns:
Get Class name of object

getClosestFeature(position, opt_layer){cercalia.Feature}

src/cercalia/map.js, line 2318
Name Type Description
position cercalia.LonLat

Position

layer ol.layer.Layer

Layer

Returns:
Nearest feature to coordinate

getClosestMarker(position, opt_layer){cercalia.Marker}

src/cercalia/map.js, line 2328
Name Type Description
position cercalia.LonLat

Position

layer ol.layer.Layer

Layer

Returns:
Nearest marker to coordinate

getContainerId(){string}

src/cercalia/map.js, line 1352

Returns the container ID

Returns:
id Map container Id

getContextMenu(){cercalia.ContextMenu}

src/cercalia/map.js, line 3089
Returns:
Get contextmenu.

getControlByName(name){ol.control.Control|undefined|null}

src/cercalia/map.js, line 1608

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

  • cercalia.control.MapControls.ADDRESS
  • cercalia.control.MapControls.CLEAN
  • cercalia.control.MapControls.GAS_STATIONS
  • cercalia.control.MapControls.LAYER_SWITCHER
  • cercalia.control.MapControls.ISOCHRONES
  • cercalia.control.MapControls.LOGISTICS_RESTRICTIONS
  • cercalia.control.MapControls.LAYER_REGIONS
  • cercalia.control.MapControls.METEO
  • cercalia.control.MapControls.NAVBAR
  • cercalia.control.MapControls.TRAFFIC
  • cercalia.control.MapControls.ZOOM
Name Type Description
name string

Name of control

Returns:
Control.

getControlsByClassName(className){}

src/cercalia/map.js, line 1629

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

  • `cercalia.control.Address
  • `cercalia.control.Clean
  • `cercalia.control.GasStations
  • `cercalia.control.LayerSwitcher
  • `cercalia.control.Meteo
  • `cercalia.control.NavBar
  • `cercalia.control.Traffic
  • cercalia.control.Zoom
Name Type Description
className string

Classname of control

Returns:
Control.

getEventCoordinate(evt){cercalia.LonLat}

src/cercalia/map.js, line 1474
Name Type Description
evt ol.MapEvent

Event

Returns:
Position

getEventPixel(evt){ol.Pixel}

src/cercalia/map.js, line 1465

Obtains pixel

Name Type Description
evt ol.MapEvent

Event

Returns:
pixel Pixel

getFeatures(){Array.<cercalia.Feature>|null}

src/cercalia/map.js, line 2124

Obtain all the cercalia.Feature painted on the map

Returns:
Feature list painted on the map

getFeaturesByLayer(layer){Array.<cercalia.Marker>|Array.<cercalia.Feature>}

src/cercalia/map.js, line 2149

Get Cercalia Markers and Features (ignoring features created directly by ol.Feature)

Name Type Description
layer ol.layer.Layer

Layer

Returns:
list of markers or features.

getGeolocation(){ol.Geolocation|undefined}

src/cercalia/map.js, line 1118
Returns:
Geolocation

getId(){string} inherited

src/cercalia/object.js, line 33
Returns:
Unique Id.

getLayerByName(layerName){ol.layer.Layer}

src/cercalia/map.js, line 1564
Name Type Description
layerName string

Name of layer.

Returns:
OpenLayers layer.

getLayerIndexByName(layerName){number|null}

src/cercalia/map.js, line 2013

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

Name Type Description
layerName string

Name of layer.

Returns:
Layer position

getMap(){ol.Map}

src/cercalia/map.js, line 1369

Returns the OpenLayers3 object ol.Map

Returns:
Map

getMapDistance(){cercalia.MapDistance}

src/cercalia/map.js, line 3081
Returns:
Map routing object.

getMapRouting(){cercalia.MapRouting}

src/cercalia/map.js, line 3073
Returns:
Map routing object.

getMarkerById(id, opt_layer){cercalia.Marker|null}

src/cercalia/map.js, line 2135

Get marker by ID. It returns null if it is not found.

Name Type Description
id string

Id.

layer ol.layer.Layer

Optional layer. Default uses MarkerLayer.

Returns:
marker Marker or null if not found.

getMarkers(){Array.<cercalia.Marker>|null}

src/cercalia/map.js, line 2114

Obtain all the cercalia.Marker painted on the map

Returns:
Marker list painted on the map

getOverlappedMarkers(currentExtentView, opt_tolerance){}

src/cercalia/map.js, line 2419

Get Overlapped markers

Name Type Description
currentExtentView boolean | undefined

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

tolerance number

Tolerance in meters.

Returns:
Array of group (array) of features.

getProjectionCode(){string}

src/cercalia/map.js, line 1850

Obtains the map projection code

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

getRotation(){number}

src/cercalia/map.js, line 1830
Returns:
Rotation in degrees.

getScaleUnits(){string}

src/cercalia/map.js, line 1360
Returns:
Scale units

getViewportSize(){}

src/cercalia/map.js, line 3106

Get viewport size

Returns:
Return {w: width, h: height}

getZoom(){number|undefined}

src/cercalia/map.js, line 1423
Returns:
Current zoom level of map.

hideControls()

src/cercalia/map.js, line 1637

Hide all map controls.

hideLabels()

src/cercalia/map.js, line 2353

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

metersToPixels(meters){number|undefined}

src/cercalia/map.js, line 1502

Calculate in pixels, from distance in meters on current map bounds (no geodesic distance).

Name Type Description
meters number

Meters

Returns:
meters Return measure in meters.

openContextMenu(opt_lonLat)

src/cercalia/map.js, line 983

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

Coordinate

openPopups()

src/cercalia/map.js, line 2402

Show all markers popups. Only for markers with popup created

panTo(lonLat, opt_animation)

src/cercalia/map.js, line 1794

Moves the map to the new center

Name Type Description
lonLat cercalia.LonLat

Coordinates.

animation boolean

Enable or disable animation. Default true.

panToBounds(bounds, opt_animation)

src/cercalia/map.js, line 1810

Map center maintaining the zoom level

Name Type Description
bounds cercalia.Bounds

Mapbounds.

animation boolean

Enable or disable animation. Default true.

pixelsToMeters(pixels){number|undefined}

src/cercalia/map.js, line 1486

Calculate the real distance in meters, from pixels values.

Name Type Description
pixels number

Pixels to measure

Returns:
meters Return measure in meters.

pixelToCoord(pixel){cercalia.LonLat}

src/cercalia/map.js, line 1453

Returns the coordinate from a pixel value

Name Type Description
pixel ol.Pixel

Pixel

Returns:
Coordinate

removeAllFeatures()

src/cercalia/map.js, line 2279

Clean all features

removeAllMarkers()

src/cercalia/map.js, line 2268

Clean all markers and popups

removeAllOverlays()

src/cercalia/map.js, line 2306

Clean all overlays painted on the map

removeDrawFeatures()

src/cercalia/map.js, line 2292

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

removeFeatures(features, opt_layer)

src/cercalia/map.js, line 2218

Remove features list from map

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

Feature or list of features.

layer ol.layer.Layer

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

removeLayer(layer)

src/cercalia/map.js, line 1318

Clean the layer specified by parameter

Name Type Description
layer ol.layer.Layer | ol.layer.Vector | cercalia.KML | cercalia.WMS | cercalia.Heatmap

Layer to remove.

removeMarkers(markers, opt_layer)

src/cercalia/map.js, line 2184

Remove markers list from map

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

Marker or list of markers to remove.

layer ol.layer.Layer

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

removeWMSLayer(wmsLayer)

src/cercalia/map.js, line 2003

Remove a WMS layer cercalia.WMS from the map

Name Type Description
wmsLayer cercalia.WMS

WMS Layer to remove.

rotate(angle)

src/cercalia/map.js, line 1840

Rotates the map degrees, by parameter

Name Type Description
angle number

Angle (degrees).

setBaseLayer(mapType)

src/cercalia/map.js, line 1183
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

    Also can use your own custom base layers. 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, opt_zoom, opt_animation)

src/cercalia/map.js, line 1404

Set the map center

Name Type Description
lonLat cercalia.LonLat

Coordinates

zoom number

Zoom

animation boolean

Enable or disable animation. Default true.

setDefaultClick(func)

src/cercalia/map.js, line 2750

Set default click function. When map is clicked parameter function is triggered.

Name Type Description
func function | undefined

Function

setFeatureDrawingStyles(styles)

src/cercalia/map.js, line 2863
Name Type Description
styles Object

Styles.

setGreyScale(enable)

src/cercalia/map.js, line 3027

Change base map colors to grey ssacle

Name Type Description
enable boolean

Enable

setProjection(projection, opt_layer)

src/cercalia/map.js, line 1887

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

Name Type Description
projection ol.proj.Projection

Projection.

layer ol.layer.Layer

Layer. Optional.

setRestrictedView(minZoom, maxZoom, bounds)

src/cercalia/map.js, line 1862

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

setRotation(angle)

src/cercalia/map.js, line 1822

Sets the map rotation

Name Type Description
angle number

Angle in degrees.

setZoom(zoom)

src/cercalia/map.js, line 1432

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

Name Type Description
zoom number

Zoom level to adjust

showControls()

src/cercalia/map.js, line 1645

Show all map controls.

showInfoMap(infoMap)

src/cercalia/map.js, line 2968
Name Type Description
infoMap cercalia.InfoMap

Info map.

showingLabels(){boolean}

src/cercalia/map.js, line 2380

Returns boolean showing if all labels are showing or hidden.

Returns:
Return wheter labels are visible.

showLabels()

src/cercalia/map.js, line 2367

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

showMarkers(markers, show)

src/cercalia/map.js, line 2168

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>

Marker or list of markesrs.

show boolean

Show markers. (true or false).

updateSize()

src/cercalia/map.js, line 3097

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