Drawing elements
Last updated
Was this helpful?
Last updated
Was this helpful?
The Felt SDK provides two main approaches for creating elements on your maps:
Interactive Drawing: Configure and activate drawing tools for users to create elements manually
Programmatic Creation: Create and modify elements directly through code
Elements created via the SDK are session-specific - they're not persisted to the map and won't be visible to other users.
The methods on the enable you to programmatically activate drawing tools for your users, as well as setting various options for the tools, such as color, line width, etc.
Use the method to activate a particular tool.
Use the method to configure the options for a specific tool.
Use the and to be notified of changes to the above, or read them instantaneously with the and methods.
As the user creates elements with the tools, you can be notified of them being created and updated using the and listeners. See Listening for element creation for more details.
pin
Place
Creates a single point on a map, with a symbol and optional label
line
Line
Creates a sequence of straight lines through the points that the user clicks
route
Line
Creates a line that follows the routing logic depending on the mode of transport selected. For instance, walking, driving and cycling routes follow applicable roads and pathways to reach the waypoints the user provides. Flying routes follow great circle paths.
polygon
Polygon
Creates an enclosed area with straight edges
circle
Circle
A circle is defined by its center and radius.
marker
Marker
Freeform drawing with a pen-like rendering. Different sizes can be set for the pen. The geometry produced is in world-space, so as you zoom the map, the pen strokes remain in place.
highlighter
Highlighter
Represents an area of interest, created by drawing with a thick pen. By default, drawing an enclosed shape fills the interior.
text
Text
A label placed on the map with no background color.
note
Note
A label placed on the map with a rectangular background color and either white or black text.
When elements are created programatically, they also trigger notifications about the corresponding changes to elements, via onElementCreate
, onElementChange
and onElementDelete
.
The geometry is returned in GeoJSON geometry format, which can be quite different to the way the element is specified in Felt. For example, Circle
elements in Felt have their geometry converted into a polygon, representing the area covered by the circle.
Note: Text, Note, and Image elements do not return geometry as they are considered to annotations rather than true "geospatial" elements.
There are two different ways for listening to elements being created, and the one you use depends on how the element is being created, and at what point you want to know about an element's creation.
When the user is creating elements with tools, they are often created in a number of steps, such as drawing a marker stroke or creating a polygon with many vertices.
Here is an example showing the power of the Felt SDK, where in just a few lines of code you can allow your users to draw elements and have them sent to your own backend systems for persistence or analysis.
Assuming you have embedded your Felt map as described in Getting started, and in your own UI you have added a polygon-tool
button and a reset-tool
button, all you need is the following:
If you want to create elements programatically instead of letting your users draw them interactively on the map, use the methods in the .
To create elements, use the method.
To update elements, use the method.
To delete elements, use the method.
Extract the geometric representation of elements using the method.
Every change that is made to the elements on a map results in a call to either , or .
When you want to know when the user has finished creating the element (e.g. the polygon was closed or the marker stroke ended) then you should use the listener.
When elements are created programatically, they do not trigger the event.
Elements created using Tools or will trigger the event, with an extra property stating whether the element is still being created.
ElementsController
setTool