This module provides the functionality for drawing features on the map.
Methods
-
static activate(options) → {Object}
-
This function activates the drawing mode with the provided options. It sets up the necessary properties and event listeners for drawing features on the map.
Parameters:
Name Type Description options
Object The options for activating the drawing mode. Properties
Name Type Attributes Description feature
Object <optional>
The feature to be edited or drawn. type
String <optional>
The type of feature to be drawn. lngLat
Object <optional>
The longitude and latitude coordinates for drawing. id
String <optional>
The unique identifier for the feature. Returns:
Object - Returns the current instance for method chaining. -
static canHandle(modeName) → {boolean}
-
Checks if the given modeName is equal to the constant mode DRAW.
Parameters:
Name Type Description modeName
string The name of the mode to be checked. Returns:
boolean - Returns true if the modeName is equal to DRAW, false otherwise. -
static cancelEdit(standby, feature) → {any}
-
This function cancels the current editing operation by setting the 'cancelled' flag to true. If the 'feature' parameter is not provided or does not have a 'type' property, it sets 'geoflo.hotFeature' to null and finishes the draw process. It then sets the 'standby' property, updates 'geoflo.hotFeature', fires a 'draw.cancel' event with the feature, and returns the result of 'finishDraw()'.
Parameters:
Name Type Description standby
boolean The standby value to set. feature
object The feature being edited. Returns:
any - The result of the 'finishDraw()' function. -
static deactivate(cancel, standby, feature)
-
Deactivates the draw feature by canceling the current edit, cleaning up the draw, setting buttons, and handling events.
Parameters:
Name Type Description cancel
boolean Flag to determine if the edit should be canceled. standby
boolean Flag to indicate if the feature is in standby mode. feature
object The feature to be deactivated. -
static deleteVertex(index) → {void}
-
Deletes a vertex from the current feature being edited on the map.
Parameters:
Name Type Description index
number The index of the vertex to be deleted. Returns:
void -
static getFeature() → {any}
-
Retrieves the hot feature from the context.
Returns:
any - The hot feature stored in the context. -
static handleClick(event) → {Object}
-
This function processes the click event for drawing features on the map. It determines the action based on the event type and context state, such as editing mode, touch input, vertex addition, and gamepad interaction.
Parameters:
Name Type Description event
Object The event object containing information about the click event. Returns:
Object - The updated event object or the result of the drawing action. -
static handleContext(event) → {void}
-
Handles the context of dragging and moving a feature vertex.
Parameters:
Name Type Description event
Event The event triggering the context handling. Returns:
void -
static handleDown(event) → {void}
-
Handles the mouse or touch down event on the map. Updates the mouse/touch position, adds a vertex if allowed, and sets features for pinning.
Parameters:
Name Type Description event
Object The event object containing information about the mouse or touch event. Returns:
void -
static handleDrag(event) → {boolean}
-
This function is responsible for handling the drag event of a vertex on the map. It updates the position of the vertex based on the user's interaction and triggers various actions accordingly.
Parameters:
Name Type Description event
Object The event object containing information about the drag event. Returns:
boolean - Returns false if the drag index is not valid. -
static handleHistory(event) → {void}
-
Handles the history of features in the current mode.
Parameters:
Name Type Description event
Object The event triggering the history update. Returns:
void -
static handleIcon(event, feature)
-
Handles the icon based on the event and feature provided.
Parameters:
Name Type Description event
Event The event triggering the function. feature
Object The feature object to be handled. -
static handleMove(event) → {boolean}
-
This function determines the behavior based on the event type and context state. It handles various actions such as dragging, painting, snapping, routing, and snapping to points.
Parameters:
Name Type Description event
Object The event object containing information about the mouse or touch event. Returns:
boolean - Returns false in certain conditions to prevent default behavior. -
static handleOffMap(event)
-
This function is triggered when an off-map event occurs and clears the data of a specific source on the map.
Parameters:
Name Type Description event
Event The event object triggering the function. -
static handleOnMap(event)
-
This function updates the data of the SNAP source on the map with the snapFeature.
Parameters:
Name Type Description event
Event The event triggering the function. -
static handlePainting(event) → {boolean}
-
This function is triggered when painting on the map. It disables drag pan, sets the map class to 'painting', and updates the feature coordinates.
Parameters:
Name Type Description event
Object The event object triggering the function. Returns:
boolean - Returns false if mouse is not down or no coordinates are available, otherwise updates the feature coordinates. -
static handleRectangle(event) → {void}
-
Handles the creation and manipulation of a rectangle feature on a map.
Parameters:
Name Type Description event
Object The event object triggering the function. Returns:
void -
static handleRedo() → {void}
-
Handles the redo functionality (currently under development).
Returns:
void -
static handleText(event, feature)
-
Handles text input events and logs relevant properties.
Parameters:
Name Type Description event
Event The event object triggering the function. feature
string The feature to be handled. -
static handleTouch(event) → {void}
-
This function is responsible for handling touch events and triggering corresponding actions.
Parameters:
Name Type Description event
Event The touch event object. Returns:
void -
static handleUndo() → {void}
-
This function is responsible for undoing the last action performed in the application. It retrieves the history and undo arrays from the current mode, pops the last feature from the history, sets the undo flag to true for the feature, updates the hotFeature, pushes the feature to the undo array, and updates the map source data with the hotFeature.
Returns:
void -
static handleUp(event) → {void}
-
This function is responsible for handling the mouse up event during drawing and editing operations on the map. It checks various conditions and triggers corresponding actions based on the context and user interactions.
Parameters:
Name Type Description event
Event The mouse up event object. Returns:
void -
static saveEdit(feature) → {boolean}
-
This function saves the edited feature in the map.
Parameters:
Name Type Description feature
Object The feature to be saved. Returns:
boolean - - Returns true if the feature is successfully saved, false otherwise. -
static selectFeature(id) → {boolean}
-
Selects a feature based on the provided ID.
Parameters:
Name Type Description id
string The ID of the feature to be selected. Returns:
boolean - Returns false if no ID is provided, otherwise returns the result of selecting the feature. -
static updateHotSource(feature, properties) → {Object}
-
This function updates the hot source feature with new properties and assigns it to the geoflo.hotFeature. It then updates the data of the VERTEX and HOT sources on the map with the updated feature.
Parameters:
Name Type Description feature
Object The feature object to be updated. properties
Object The new properties to be assigned to the feature. Returns:
Object - The updated hot source feature.