This module provides utility functions for the Geoflo application.
Methods
-
static assignDeep(target, source, options) → {Object}
-
Recursively assigns properties of source object to target object deeply.
Parameters:
Name Type Description target
Object The target object to which properties will be assigned. source
Object The source object whose properties will be assigned to the target. options
Object Optional parameters for the assignment process. Properties
Name Type Attributes Default Description isMutatingOk
boolean <optional>
false Flag to allow mutating the target object. isStrictlySafe
boolean <optional>
false Flag to enforce strict safety checks during assignment. Returns:
Object - The target object with assigned properties from the source object. -
static clone(thing, opts) → {Object|Array|Date|RegExp|function|Symbol}
-
This function recursively clones the input object or array, preserving the structure and types of the elements.
Parameters:
Name Type Description thing
Object | Array | Date | RegExp | function | Symbol The object or array to be cloned. opts
Object Optional settings for cloning functions and symbols. Returns:
Object | Array | Date | RegExp | function | Symbol - - A deep clone of the input object or array. -
static cloneDeep(value, instance) → {any}
-
Recursively clones a value, including objects and arrays, preserving the original structure deeply.
Parameters:
Name Type Description value
any The value to be cloned. instance
function A function that can be used to clone custom instances. Returns:
any - - The deeply cloned value. -
static combineSameTypeFeatures(features) → {Array}
-
This function takes an array of line features and combines them by connecting them based on their coordinates. It checks the endpoints of each line feature and connects them accordingly to form a continuous line.
Parameters:
Name Type Description features
Array An array of line features to be combined. Returns:
Array - - An array of coordinates representing the combined line features. -
static compareDeep(x, y) → {boolean}
-
Recursively compares two objects deeply to check if they are equal.
Parameters:
Name Type Description x
Object The first object to compare. y
Object The second object to compare. Returns:
boolean - Returns true if the objects are deeply equal, false otherwise. -
static consumableArray(arr) → {Array}
-
Creates a consumable copy of an array or array-like object.
Parameters:
Name Type Description arr
Array | Array-like The input array or array-like object to be copied. Returns:
Array - A consumable copy of the input array or array-like object. -
static degrees2meters(px) → {Array.<number>}
-
This function takes an array of latitude and longitude in degrees and converts it to meters using the Mercator projection formula.
Parameters:
Name Type Description px
Array.<number> An array containing latitude and longitude in degrees [longitude, latitude]. Returns:
Array.<number> - An array containing the converted x and y coordinates in meters. -
static extend(target, …sources) → {Object}
-
Extends the properties of the first object with the properties of the subsequent objects.
Parameters:
Name Type Attributes Description target
Object The object to be extended. sources
Object <repeatable>
The objects whose properties will be added to the target object. Returns:
Object - The extended object. -
static getLastIndexCoords(f) → {Array}
-
This function returns the last coordinates of a given geometry object.
Parameters:
Name Type Description f
Object The geometry object to extract the last coordinates from. Returns:
Array - The last coordinates of the geometry object. -
static getRandomColor() → {string}
-
This function generates a random color by randomly selecting hexadecimal values for each digit of the color code.
Returns:
string - A random color in hexadecimal format. -
static isEmptyLineString(feature) → {boolean}
-
This function determines if the provided feature is a LineString with only two identical points, making it an empty LineString.
Parameters:
Name Type Description feature
Object The feature object to be checked. Returns:
boolean - Returns true if the feature is an empty LineString, otherwise false. -
static isLastIndex(i, f) → {boolean}
-
This function determines if the provided index is the last index in the coordinates array of a feature.
Parameters:
Name Type Description i
number The index to check. f
object The feature object containing the coordinates array. Returns:
boolean - Returns true if the index is the last index, false otherwise. -
static isLineString(f) → {boolean}
-
This function takes a GeoJSON feature object and determines if it represents a LineString geometry.
Parameters:
Name Type Description f
Object The GeoJSON feature object to be checked. Returns:
boolean - Returns true if the feature is a LineString, false otherwise. -
static isPoint(f) → {boolean}
-
This function takes a feature object and determines if it represents a Point geometry.
Parameters:
Name Type Description f
Object The feature object to be checked. Returns:
boolean - Returns true if the feature is a Point geometry, false otherwise. -
static isPointEqual(coords1, coords2) → {boolean}
-
Checks if two points are equal based on their coordinates.
Parameters:
Name Type Description coords1
Array The coordinates of the first point [x, y]. coords2
Array The coordinates of the second point [x, y]. Returns:
boolean - Returns true if the points have the same coordinates, false otherwise. -
static isPolygon(feature) → {boolean}
-
This function determines if a feature represents a polygon by comparing its first and last coordinates.
Parameters:
Name Type Description feature
Object The feature object to be checked. Returns:
boolean - Returns true if the feature is a polygon, false otherwise. -
static isValidLineString(f) → {boolean}
-
Checks if the input feature is a valid LineString by verifying its geometry coordinates.
Parameters:
Name Type Description f
Object The input feature to be validated. Returns:
boolean - Returns true if the input feature is a valid LineString, false otherwise. -
static meters2degrees(px) → {Array}
-
This function takes a pixel value and converts it to longitude and latitude in degrees.
Parameters:
Name Type Description px
Array The pixel value to be converted, in the format [x, y]. Returns:
Array - An array containing the longitude and latitude in degrees, [lon, lat]. -
static reducePrecision(coords) → {Array}
-
This function reduces the precision of the coordinates to 7 decimal places.
Parameters:
Name Type Description coords
Array An array containing the coordinates to be processed. Returns:
Array - The coordinates with reduced precision to 7 decimal places. -
static setProperties(feature, newProps)
-
Updates the properties of a given feature object with new properties.
Parameters:
Name Type Description feature
Object The feature object whose properties will be updated. newProps
Object The new properties to be merged with the existing properties of the feature. -
static setProperty(feature, name, value)
-
This function sets a property value for a given feature. If the feature does not have properties, it creates a new properties object. If the property name includes a dot (.), it creates nested objects to set the value.
Parameters:
Name Type Description feature
Object The feature object to set the property for. name
string The name of the property to set. value
any The value to set for the property. -
static stringToDOM(str) → {Document}
-
Converts a string to a DOM object using DOMParser.
Parameters:
Name Type Description str
string The input string to be converted to a DOM object. Returns:
Document - - The DOM object created from the input string.