This module provides the snapping functionality for the Geoflo application. It allows users to snap features to the map by creating a buffer around the feature and snapping to nearby features.
Methods
-
static activate()
-
This function enables the object and sets the snapping option to true.
-
static addFeature(feature, propertiesopt, dontAddopt) → {boolean}
-
This function adds a feature to the map by setting the data of the specified source with the provided feature. It also updates the properties of the feature if properties are provided.
Parameters:
Name Type Attributes Default Description feature
Object The feature to be added to the map. properties
Object <optional>
{} Additional properties to be assigned to the feature. dontAdd
boolean <optional>
Flag to prevent adding the feature if set to true. Returns:
boolean - Returns false if the feature is not provided or if dontAdd flag is set. -
static deactivate() → {void}
-
This function sets the 'enabled' property to false, disables snapping, and updates the mesh data.
Returns:
void -
static getClosest(coords, features) → {Object}
-
Finds the closest point to the given coordinates within a specified radius or pixel distance.
Parameters:
Name Type Description coords
Array.<number> The coordinates [longitude, latitude] to find the closest point to. features
Array.<Object> An array of features to search for the closest point within. Returns:
Object - An object containing the closest point and its coordinates. -
static setClosest(coords, isPoint, isVertex) → {Object}
-
This function calculates the closest feature to the given coordinates within a specified radius and snapping parameters. It determines if the closest feature is a point or a vertex and returns the snapped feature accordingly.
Parameters:
Name Type Description coords
Array.<number> The coordinates [longitude, latitude] to find the closest feature to. isPoint
boolean Indicates if the feature is a point. isVertex
boolean Indicates if the feature is a vertex. Returns:
Object - The snapped feature based on the calculated closest point or line. -
static setFeature(feature, coords) → {Object}
-
This function sets a feature on the map using the provided feature and coordinates. It handles different scenarios such as creating a point, line, or polygon feature based on the input parameters.
Parameters:
Name Type Description feature
Object The feature to be set on the map. coords
Array The coordinates for the feature. Returns:
Object - The feature that was set on the map. -
static setVertex(geoflo) → {boolean}
-
This function determines the vertex based on snapping and routing settings. It sets the closest feature when snapping is enabled and calculates the route if routing is enabled. It updates the map sources accordingly and triggers events related to vertex dragging and snapping.
Parameters:
Name Type Description geoflo
Object The context object containing various settings and data. Returns:
boolean - Returns false if snapping is disabled or no snapped vertex is available. -
static updateFeature(evtCoords) → {Object}
-
This function updates a feature based on the event coordinates provided. It determines the type of feature, calculates the necessary coordinates, creates a line feature with hint properties, and converts units if needed.
Parameters:
Name Type Description evtCoords
Array The event coordinates to update the feature. Returns:
Object - The updated feature based on the event coordinates.