ElementsController
The Elements controller allows you to get information about the elements on the map, and make changes to their visibility.
Extended by
Methods
getElement()
getElement(
id
:string
):Promise
<null
|Element
>
Get a single element from the map by its id.
Parameters
id
string
The id of the element you want to get.
Returns
Promise
<null
| Element
>
The requested element.
Example
getElementGeometry()
getElementGeometry(
id
:string
):Promise
<null
|GeoJsonGeometry
>
Get the geometry of an element in GeoJSON geometry format.
For most element types, the geometry returned is based on the coordinates
property of the element, with some differences:
For Circle elements, the geometry is a Polygon drawn from the
center
andradius
properties.Path elements become MultiLineString geometries.
Marker elements return a MultiLineString of the path traced by the user as they drew the marker. Note that this is not the polygon formed by filled-in "pen" stroke, which doesn't exactly follow the path traced by the user as it is smoothed and interpolated to create a continuous line.
Text, Note and Image elements do not return geometry, so will return
null
.
Parameters
id
string
The id of the element you want to get the geometry of.
Returns
Promise
<null
| GeoJsonGeometry
>
Example
getElements()
getElements(
constraint
?:GetElementsConstraint
):Promise
<(null
|Element
)[]>
Gets elements from the map, according to the constraints supplied. If no constraints are supplied, all elements will be returned.
Parameters
constraint
?
The constraints to apply to the elements returned from the map.
Returns
Promise
<(null
| Element
)[]>
All elements on the map.
Remarks
The elements in the map, ordered by the order specified in Felt. This is not necessarily the order that they are drawn in, as Felt draws points above lines and lines above polygons, for instance.
Example
getElementGroup()
getElementGroup(
id
:string
):Promise
<null
|ElementGroup
>
Get an element group from the map by its id.
Parameters
id
string
Returns
Promise
<null
| ElementGroup
>
The requested element group.
Example
getElementGroups()
getElementGroups(
constraint
?:GetElementGroupsConstraint
):Promise
<(null
|ElementGroup
)[]>
Gets element groups from the map, according to the filters supplied. If no constraints are supplied, all element groups will be returned in rendering order.
Parameters
constraint
?
The constraints to apply to the element groups returned from the map.
Returns
Promise
<(null
| ElementGroup
)[]>
The requested element groups.
Example
setElementGroupVisibility()
setElementGroupVisibility(
visibility
:SetVisibilityRequest
):Promise
<void
>
Hide or show element groups with the given ids.
Parameters
visibility
Returns
Promise
<void
>
Example
createElement()
createElement(
element
:ElementCreate
):Promise
<Element
>
Create a new element on the map.
Parameters
element
Returns
Promise
<Element
>
Example
updateElement()
updateElement(
element
:ElementUpdate
):Promise
<Element
>
Update an element on the map.
Parameters
element
Returns
Promise
<Element
>
Example
deleteElement()
deleteElement(
id
:string
):Promise
<void
>
Delete an element from the map.
Parameters
id
string
Returns
Promise
<void
>
Example
Events
onElementCreate()
onElementCreate(
args
: {handler
: (change
:ElementChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when an element is created.
Parameters
args
-
args.handler
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onElementCreateEnd()
onElementCreateEnd(
args
: {handler
: (params
: {element
:Element
; }) =>void
; }):VoidFunction
Listens for when a new element is finished being created by a drawing tool.
This differs from the `onElementCreate` listener, which fires whenever an element is first created. This fires when the user finishes creating an element which could be after a series of interactions.
For example, when creating a polygon, the user places a series of points then finishes by pressing Enter or Escape. Or when creating a Place element, they add the marker, type a label, then finally deselect the element.
Parameters
args
-
args.handler
The handler to call whenever this event fires.
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onElementChange()
onElementChange(
args
: {options
: {id
:string
; };handler
: (change
:ElementChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when an element changes.
This will fire when an element is being edited, either on the map by the user or programatically.
Like the `onElementCreate` listener, this will fire when an element is still being created by a drawing tool.
You can check the `isBeingCreated` property to determine if the element is still being created by a drawing tool.
Parameters
args
-
args.options
{ id
: string
; }
-
args.options.id
string
The id of the element to listen for changes to.
args.handler
The handler that is called when the element changes.
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onElementDelete()
onElementDelete(
args
: {options
: {id
:string
; };handler
: () =>void
; }):VoidFunction
Adds a listener for when an element is deleted.
Parameters
args
{ options
: { id
: string
; }; handler
: () => void
; }
-
args.options
{ id
: string
; }
-
args.options.id
string
The id of the element to listen for deletions of.
args.handler
() => void
The handler that is called when the element is deleted.
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onElementGroupChange()
onElementGroupChange(
args
: {options
: {id
:string
; };handler
: (change
:ElementGroupChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when an element group changes.
Parameters
args
args.options
{ id
: string
; }
args.options.id
string
args.handler
Returns
VoidFunction
A function to unsubscribe from the listener
Example
Last updated
Was this helpful?