Class: Marker

cercaliagl.Marker


Javascript ES5

const map = new cercaliagl.Marker({ ... });

Create a marker component. Marker will draw a feature on map with an icon Icon. Marker optionally can have a Label, SimpleLabel and Popup
There are many events which marker can handle.
These events can defined in constructor or in runtime modifing attribute as onClick, onMouseOver, etc.

Example usage:

const map = new cercaliagl.Map({
  target: 'map'
});

const marker = new cercaliagl.Marker({
  position: new cercaliagl.LonLat(1.241, 41.431),
  label: new cercaliagl.Label({text: 'Label text'}),
  simpleLabel: new cercaliagl.SimpleLabel({text: 'Simple label text'}),
  popup: new cercaliagl.Popup({
    title: 'Title popup',
    content: '<b>Content</b> popup',
  }),
  draggable: true,
  onClick: () => map.setCenter(marker.getPosition()),
});
map.addMarker(marker);

new Marker(options)

Name Type Description
options

Options

Name Type Description
id string

Id

icon module:cercaliagl/Icon~Icon

Icon

position maplibregl.LngLat

Position

encodedGooglePosition string

Position encoded on google polyline format.

draggable boolean

Draggable. Default false.

onClick function

Function to execute on marker click.

onDoubleClick function

Function to execute on marker double click.

onMouseOut function

Function to execute on Mouse Out.

onMouseOver function

Function to execute on Mouse Over.

onRightClick function

Function to execute on marker right click.

onDragEnd function

Function to execute when ends marker dragging.

onDragMove function

Function to execute during marker dragging.

onDragStart function

Function to execute on marker dragging start.

onDragStart function

Function to be executed when marker visibility changes.

onDrop function

Function to obtain markers on dragged marker extent when drag ends.

simpleLabel module:cercaliagl/SimpleLabel~SimpleLabel

Marker Simple Label object.

visible boolean

Marker visible or not. Default true.

label module:cercaliagl/Label~Label

Label

zIndex number

Z-Index. Default 0.

extraProperties Object.<string, string>

Extra properties to put inside geojson. Default {}.

Extends

Methods

addPopup(popup)

Name Type Description
popup module:cercaliagl/Popup~Popup

PPopup

closePopup()

Close popup

Gets a value.

Name Type Description
key string

Key name.

Returns:
Value.

getExtraProperties(){Object.<string, string>}

Get extra properties

Returns:
Extra properties

getGeoJSON(){GeoJSON} inherited

Returns:
GeoJSON

getGeometryType(){string} inherited

Returns:
GeoJSON

Get marker icon

Returns:
Icon

getId(){String} inherited

Returns:
Id

Get label

Returns:
label Label assigned to th marker.
Returns:
Layer
Returns:
Map

getPopup(){maplibregl.Popup}

Returns:
Popup

getVisible(){boolean}

Returns:
visible Visible

getZIndex(){number}

Get zIndex

Returns:
zIndex zIndex

hideLabel()

Hide marker label

isDraggable(){boolean}

Returns:
draggable Draggable

openPopup()

Open popup

removeLabel()

Remove label

set(key, value, silent) inherited

Sets a value.

Name Type Description
key string

Key name.

value *

Value.

silent boolean

Update without triggering an event.

setDraggable(draggable)

Set marker as draggable

Name Type Description
draggable boolean

Draggable

setExtraProperties(properties)

Set extra properties

Name Type Description
properties Object.<string, string>

Extra properties

setIcon(icon)

Set marker icon.

Name Type Description
icon module:cercaliagl/Icon~Icon

Icon

setLabel(label)

Assign/change marker label text

Name Type Description
label module:cercaliagl/Label~Label

Label content

Name Type Description
map module:cercaliagl/Map~Map

Map

setOnDragEnd(onDragEnd)

Sets the function to be called when the marker is dragged and released.

Name Type Description
onDragEnd function

The function to be called when the marker is dragged and released.

setOnDragMove(onDragMove)

Sets the function to be called when the marker is moved.

Name Type Description
onDragMove function

The function to be called when the marker is moved

setOnDragStart(onDragStart)

Sets the function to be called when the marker has started to be dragged.

Name Type Description
onDragStart function

The function to be called when the marker has started to be dragged.

setOnVisibilityChange(onVisibilityChange)

Sets the function to be called when the marker has changed his visibility.

Name Type Description
onVisibilityChange function

The function to be called when the marker has changed his visibility.

setPopup(popup)

Name Type Description
popup maplibregl.Popup

Popup

setPosition(position, avoidRefresh)

Set position

Name Type Description
position module:cercaliagl/LonLat~LonLat | module:maplibre-gl~LngLat

Position

avoidRefresh boolean (defaults to false)

Avoid refresh

setSimpleLabel(simpleLabel)

Set simpel label. If null simple label will be removed

Name Type Description
simpleLabel module:cercaliagl/SimpleLabel~SimpleLabel | null

Simple Label

setVisible(visible)

Hide or show marker.

Name Type Description
visible boolean

Visible

setZIndex(zIndex)

Set zIndex and update it.

Name Type Description
zIndex number

zIndex

showLabel()

Show marker label