Maps SDK for Web

tt.Marker

Creates a marker component

Constructor

tt.Marker([options])

Example
var marker = new tt.Marker()
.setLngLat([30.5, 50.5])
.addTo(map);
Parameters
Name Description
options
Object | HTMLElement
default:None
Object with options or HTMLElement
element
HTMLElement
default:None
DOM element to use as a marker.
anchor
String
default: bottom
A string indicating the part of the Marker that should be positioned closest to the coordinate set via Marker.setLngLat . Options are 'center', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', and 'bottom-right' .
offset
Maps.Point
default:None
The offset in pixels as a Point object to apply relative to the element's center. Negatives indicate left and up.
rotation
Number
default:0
The rotation angle of the marker in degrees, relative to its respective rotationAlignment setting. A positive value will rotate the marker clockwise.
pitchAlignment
String
default:'auto'
map aligns the Marker to the plane of the map. viewport aligns the Marker to the plane of the viewport. auto automatically matches the value of rotationAlignment.
rotationAlignment
String
default:'auto'
map aligns the Marker's rotation relative to the map, maintaining a bearing as the map rotates. viewport aligns the Marker's rotation relative to the viewport, agnostic to map rotations. auto is equivalent to viewport.
color
String
default: #000000
The color to use for the default marker if options.element is not provided.
scale
Number
default:1
The scale to use for the default marker if options.element is not provided. The default scale corresponds to a height of 36px and a width of 30px.
width
String
default: 30
The width of the default marker if options.element is not provided.
height
String
default: 36
The height of the default marker if options.element is not provided.
draggable
Boolean
default:None
A boolean indicating whether or not a marker is able to be dragged to a new position on the map.
clickTolerance
Number
default:3
The max number of pixels a user can shift the mouse pointer during a click on the marker for it to be considered a valid click (as opposed to a marker drag). The default is to inherit map's clickTolerance.

Methods

addTo(map): Maps.Marker

Attaches the marker to a map

Parameters
Name Description
map
Map
default:None
Instance of a map
Returns

this

getLngLat( ): Maps.LngLat

Get the marker's geographical location. The longitude of the result may differ by a multiple of 360 degrees from the longitude previously set by setLngLat because Marker wraps the anchor longitude across copies of the world to keep the marker on screen.

Returns

getPopup( ): Maps.Popup

Returns the Popup instance that is bound to the Marker

Returns

popup

isDraggable( ): Boolean

Returns true if the marker can be dragged

Returns

off(type, listener): Object

Removes a previously registered event listener.

Parameters
Name Description
type
String
default:None
The event type to remove listeners.
listener
Function
default:None
The listener function to remove.
Returns

this

on(type, listener): Object

Adds a listener to a specified event type.

Parameters
Name Description
type
String
default:None
The event type to add a listen for.
listener
Function
default:None
The function to be called when the event is fired. The listener function is called with the data object passed to fire, extended with the target and type properties.
Returns

this

once(type, listener): Object

Adds a listener that will be called only once to a specified event type. The listener will be called the first time the event fires after the listener is registered.

Parameters
Name Description
type
String
default:None
The event type to listen for.
listener
Function
default:None
The function to be called when the event is fired the first time.
Returns

this

setDraggable([shouldBeDraggable=false]): Maps.Marker

Sets the draggable property and functionality of the marker

Parameters
Name Description
shouldBeDraggable
Boolean
default:false
Turns drag functionality on/off
Returns

this

setLngLat(lnglat): Maps.Marker

Set the marker's geographical position and move it.

Parameters
Name Description
lnglat
Maps.LngLat
default:None
Returns

this

setOffset(offset): Maps.Marker

Sets the offset of the marker

Parameters
Name Description
offset
Maps.PontLike
default:None
The offset in pixels as a Point object to apply relative to the element's center. Negatives indicate left and up.
Returns

this

setPopup(popup): Maps.Marker

Binds a Popup to the Marker

Parameters
Name Description
popup
Maps.Popup
default:None
an instance of the Popup class. If undefined or null, any popup set on this Marker instance is unset
Returns

this

togglePopup( ): Maps.Marker

Opens or closes the bound popup, depending on the current state

Returns

this

Events

All the class events are keys of the Events static member.

To learn more about how to listen events please refer to the Evented class.

dragend : Maps.Marker

Fired when the marker is finished being dragged