This module provides the features functionality for the Geoflo application. It allows users to add, remove, update, and retrieve features from the map.
Methods
-
static addFeature(feature, propertiesopt) → {Object}
-
This function adds a feature to the map with the given properties. It cleans the coordinates, truncates them, assigns deep properties, sets the source, and removes unnecessary properties before adding the feature to the map.
Parameters:
Name Type Attributes Default Description feature
Object The feature object to be added to the map. properties
Object <optional>
{} Additional properties to be assigned to the feature. Returns:
Object - The feature object that was added to the map. -
static addFeatures(features, unselect) → {Array}
-
This function takes an array of features and adds them to the map. It also updates the source if any changes are made.
Parameters:
Name Type Description features
Array An array of features to be added to the map. unselect
boolean A flag indicating whether to unselect the features. Returns:
Array - The array of features that were added to the map. -
static addUnits(feature, convertTo) → {Object}
-
Adds units to a feature's geometry based on the specified conversion or default unit.
Parameters:
Name Type Description feature
Object The feature object to which units will be added. convertTo
String The unit to which the feature's units will be converted. If not provided, the default unit will be used. Returns:
Object - The feature object with added units. -
static convertUnits(feature, units, convertTo) → {number}
-
Converts the given units of a feature to the specified target units based on the feature type (Polyline, Polygon, or Rectangle).
Parameters:
Name Type Description feature
Object The feature object containing properties like type. units
number The units to be converted. convertTo
string The target units to convert to (optional). Returns:
number - The converted units in the target unit format. -
static deleteFeatures() → {void}
-
Deletes all features from the coldFeatures array and updates the source.
Returns:
void -
static getFeatureById(id) → {Object|Array}
-
Retrieves a feature by its ID from a given source. If the ID is an array with multiple IDs, it retrieves multiple features. If the ID is an object, it tries to extract the ID from the object's parent, properties, or id fields.
Parameters:
Name Type Description id
string | number | Array The ID or array of IDs of the feature(s) to retrieve. Returns:
Object | Array - The feature or array of features corresponding to the provided ID(s). -
static getFeatures() → {Array}
-
This function returns an array of cold features.
Returns:
Array - An array of cold features. -
static getFeaturesById(ids) → {Array}
-
Retrieves features by their IDs.
Parameters:
Name Type Description ids
Array An array of feature IDs to retrieve. Returns:
Array - - An array of features corresponding to the provided IDs. -
static getType(feature) → {string}
-
This function returns the type of the input feature.
Parameters:
Name Type Description feature
any The feature whose type needs to be determined. Returns:
string - The type of the input feature. -
static getUnits(feature) → {number}
-
Parameters:
Name Type Description feature
Object The feature for which units need to be calculated. Returns:
number - - The calculated units (length or area) of the feature. -
static removeFeatures(id) → {Array.<Object>}
-
This function permenantly removes a feature from the map based on the provided ID. It updates the map source after removing the features.
Parameters:
Name Type Description id
string | Array.<string> The ID of the features to be removed. Returns:
Array.<Object> - An array containing the removed feature. -
static removeLayers(layerSources, options) → {void}
-
Removes layers from the map based on the provided layer IDs. It updates the map source after removing the layers.
Parameters:
Name Type Description layerSources
Array.<string> An array of layer source IDs to be removed. options
Object Additional options to be passed to the removeLayers function. Properties
Name Type Description reset
boolean A flag indicating whether to reset. This will delete all features and layers from the map. Returns:
void -
static setFeatureState(id, state) → {array}
-
This function sets the state of a feature and its children in the map by updating their feature state.
Parameters:
Name Type Description id
string The ID of the parent feature. state
object The state object to set for the features. Returns:
array - - An array of features whose state was updated. -
static setFeaturesState(features, state) → {Array}
-
Sets the state of multiple features in a map.
Parameters:
Name Type Description features
Array An array of features to set the state for. state
boolean The state to set for the features. Returns:
Array - - The updated array of features with the new state. -
static setText(features) → {boolean}
-
Sets text features on the map based on the provided features.
Parameters:
Name Type Description features
Object The features to set text on. Returns:
boolean - Returns false if no features are provided or if the features array is empty. -
static updateFeatures(features, coords)
-
This function updates the coordinates of features in a map based on the provided coordinates. It iterates through the features array, retrieves the original feature by ID, and updates its geometry coordinates based on the feature type. It then adds units to the updated feature and updates the source of the map.
Parameters:
Name Type Description features
Array An array of features to update. coords
Array The new coordinates to set for the features. -
static updateSource(sources) → {any}
-
Updates the source of the current object with the provided sources.
Parameters:
Name Type Description sources
Array An array of sources to update the current object with. Returns:
any - The result of calling the updateSource function with the provided sources.