The Elements controller allows you to get information about the elements on the map, and make changes to their visibility.
getElement(
id
:string
):Promise
<null
|Element
>
Get a single element from the map by its id.
Parameter | Type | Description |
---|---|---|
id |
string |
The id of the element you want to get. |
Promise
<null
| Element
>
The requested element.
const element = await felt.getElement("element-1");
getElementGeometry(
id
:string
):Promise
<null
|Geometry
>
Get the geometry of an element.
Parameter | Type | Description |
---|---|---|
id |
string |
The id of the element you want to get the geometry of. |
Promise
<null
| Geometry
>
const geometry = await felt.getElementGeometry("element-1");
console.log(geometry?.type, geometry?.coordinates);
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.
Parameter | Type | Description |
---|---|---|
constraint ? |
GetElementsConstraint |
The constraints to apply to the elements returned from the map. |
Promise
<(null
| Element
)[]>
All elements on the map.
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.
const elements = await felt.getElements();
getElementGroup(
id
:string
):Promise
<null
|ElementGroup
>
Get an element group from the map by its id.
Parameter | Type |
---|---|
id |
string |
Promise
<null
| ElementGroup
>
The requested element group.
const elementGroup = await felt.getElementGroup("element-group-1");
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.
Parameter | Type | Description |
---|---|---|
constraint ? |
GetElementGroupsConstraint |
The constraints to apply to the element groups returned from the map. |
Promise
<(null
| ElementGroup
)[]>
The requested element groups.
const elementGroups = await felt.getElementGroups({ ids: ["element-group-1", "element-group-2"] });
setElementGroupVisibility(
visibility
:SetVisibilityRequest
):Promise
<void
>
Hide or show element groups with the given ids.
Parameter | Type |
---|---|
visibility |
SetVisibilityRequest |
Promise
<void
>
felt.setElementGroupVisibility({ show: ["element-group-1", "element-group-2"], hide: ["element-group-3"] });
createElement(
element
:ElementCreate
):Promise
<Element
>
Create a new element on the map.
Parameter | Type |
---|---|
element |
ElementCreate |
Promise
<Element
>
const element = await felt.createElement({ type: "Place", coordinates: [10, 10] });
updateElement(
element
:ElementUpdate
):Promise
<Element
>
Update an element on the map.
Parameter | Type |
---|---|
element |
ElementUpdate |
Promise
<Element
>
deleteElement(
id
:string
):Promise
<void
>
Delete an element from the map.
Parameter | Type |
---|---|
id |
string |
Promise
<void
>
onElementCreate(
args
: {handler
: (change
:ElementChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when an element is created.
Parameter | Type | Description |
---|---|---|
args |
{ handler : (change : ElementChangeCallbackParams ) => void ; } |
- |
args.handler |
(change : ElementChangeCallbackParams ) => void |
The handler that is called when an element is created. |
VoidFunction
A function to unsubscribe from the listener
const unsubscribe = felt.onElementCreate({
handler: (element) => console.log(element.id),
});
// later on...
unsubscribe();
onElementChange(
args
: {options
: {id
:string
; };handler
: (change
:ElementChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when an element changes.
Parameter | Type | Description |
---|---|---|
args |
{ options : { id : string ; }; handler : (change : ElementChangeCallbackParams ) => void ; } |
- |
args.options |
{ id : string ; } |
- |
args.options.id |
string |
The id of the element to listen for changes to. |
args.handler |
(change : ElementChangeCallbackParams ) => void |
The handler that is called when the element changes. |
VoidFunction
A function to unsubscribe from the listener
const unsubscribe = felt.onElementChange({
options: { id: "element-1" },
handler: ({element}) => console.log(element.id),
});
// later on...
unsubscribe();
onElementDelete(
args
: {options
: {id
:string
; };handler
: () =>void
; }):VoidFunction
Adds a listener for when an element is deleted.
Parameter | Type | Description |
---|---|---|
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. |
VoidFunction
A function to unsubscribe from the listener
const unsubscribe = felt.onElementDelete({
options: { id: "element-1" },
handler: (element) => console.log(element.id),
});
// later on...
unsubscribe();
onElementGroupChange(
args
: {options
: {id
:string
; };handler
: (change
:ElementGroupChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when an element group changes.
Parameter | Type |
---|---|
args |
{ options : { id : string ; }; handler : (change : ElementGroupChangeCallbackParams ) => void ; } |
args.options |
{ id : string ; } |
args.options.id |
string |
args.handler |
(change : ElementGroupChangeCallbackParams ) => void |
VoidFunction
A function to unsubscribe from the listener
const unsubscribe = felt.onElementGroupChange({
options: { id: "element-group-1" },
handler: elementGroup => console.log(elementGroup.id),
});
// later on...
unsubscribe();