This module provides the layer functionality for the Geoflo application. It allows users to add, remove, and manipulate layers on the map.
Methods
-
static addEventListeners(options) → {Object}
-
Attaches event listeners based on the provided options.
Parameters:
Name Type Description options
Object An object containing configuration options for event listeners. Returns:
Object - - The result of the buildEvents function with the provided options. -
static addLayer(layer, optionsopt) → {Object}
-
This function adds a layer to the map with the provided options. It also updates the layer's metadata, adds the layer to the map, and pushes the layer to the layers array. It triggers a 'layer.add' event and returns the added layer.
Parameters:
Name Type Attributes Default Description layer
Object The layer object to be added to the map. options
Object <optional>
{} Additional options for the layer. Returns:
Object - The added layer. -
static addLayers(layers, options) → {Array}
-
Adds multiple layers to the map.
Parameters:
Name Type Description layers
Array An array of layers to be added to the map. options
Object Additional options for adding the layers. Returns:
Array - - An array of layers that have been added to the map. -
static addSource(id, type, optionsopt) → {Object}
-
This function adds a new source to the map using the provided ID and type. It also accepts optional configuration options for the source.
Parameters:
Name Type Attributes Default Description id
string The unique identifier for the source. type
string The type of the source (e.g., 'geojson', 'vector', 'raster', etc.). options
Object <optional>
{} Additional configuration options for the source (e.g., features, promoteId, clusterMaxZoom, clusterRadius). Returns:
Object - The newly added source object. -
static addSources(sources, options) → {Array}
-
Adds multiple sources to the context with the given options.
Parameters:
Name Type Description sources
Array An array of sources to be added. options
Object Additional options for adding the sources. Returns:
Array - - An array of all the added sources. -
static getCustomLayers() → {Array}
-
Retrieves the custom layers stored in the object.
Returns:
Array - An array containing the custom layers. -
static getFeatures(id) → {Array}
-
Retrieves the features from a source based on the provided ID.
Parameters:
Name Type Description id
string The ID of the source to retrieve features from. Returns:
Array - An array of features from the specified source, or an empty array if the source or features are not found. -
static getLayer(id) → {object|boolean}
-
Retrieves a layer based on the provided ID or source ID.
Parameters:
Name Type Description id
string The ID of the layer to retrieve. Returns:
object | boolean - The layer object if found, or false if not found. -
static getLayerIds(layers) → {Array}
-
Retrieves the IDs of the layers provided or the default layers if none are provided.
Parameters:
Name Type Description layers
Array An array of layer objects. Returns:
Array - An array of layer IDs. -
static getLayers() → {Array}
-
Retrieves the layers array from the object.
Returns:
Array - The layers array. -
static getSelection(features, coords) → {boolean}
-
This function determines the selected feature based on the provided features array and coordinates.
Parameters:
Name Type Description features
Array An array of features to select from. coords
Object The coordinates of the selected feature. Returns:
boolean - Returns true if a feature is selected, false otherwise. -
static getSource(id) → {object|boolean}
-
Retrieves a specific source object by its ID from the list of sources.
Parameters:
Name Type Description id
string The ID of the source to retrieve. Returns:
object | boolean - The source object with the specified ID if found, otherwise false. -
static getSourceIds() → {Array}
-
Retrieves the IDs of all sources.
Returns:
Array - An array of source IDs. -
static getSources() → {Array}
-
Retrieves the sources stored in the object.
Returns:
Array - An array containing the sources. -
static getType(type) → {string|boolean}
-
This function takes a geometry type as input and returns the corresponding general type (Polygon, Polyline, or Point).
Parameters:
Name Type Description type
string The type of geometry to be evaluated. Returns:
string | boolean - Returns the general type of the geometry (Polygon, Polyline, Point) or false if the type is not recognized. -
static hasCustomLayers() → {number}
-
This function determines if there are any custom layers present in the application.
Returns:
number - The number of custom layers available. -
static init(options) → {Object}
-
Initializes the object with the provided options and refreshes it.
Parameters:
Name Type Description options
Object The options object to configure the object. Returns:
Object - The refreshed object with the updated options. -
static moveLayers(layers) → {void}
-
Moves the specified layers on the map.
Parameters:
Name Type Description layers
Array An array of layer objects to be moved on the map. Returns:
void -
static onClusterClick(feature) → {boolean}
-
Handles the click event on a cluster feature, expanding the cluster if applicable.
Parameters:
Name Type Description feature
Object The cluster feature that was clicked. Returns:
boolean - Returns false if the feature does not have a source; otherwise, it performs an action without returning a value. -
static onLayerMouseout(event) → {boolean}
-
Handles the mouseout event for a layer, removing highlights if certain conditions are met.
Parameters:
Name Type Description event
Object The event object associated with the mouseout event. Returns:
boolean - Returns false if the map is in editing, drawing, or viewing mode, or if the layer is being imported; otherwise, it returns undefined. -
static onLayerMouseover(event) → {boolean}
-
Handles the mouseover event on a layer, highlighting the features if certain conditions are met.
Parameters:
Name Type Description event
Object The event object containing information about the mouseover event. Returns:
boolean - Returns false if editing, drawing, or viewing actions are active, if the layer is importing, or if there are no features; otherwise, it highlights the features. -
static refresh(options) → {Array}
-
This function refreshes the map by removing existing layers and sources, adding default layers and sources, and rebuilding the layers.
Parameters:
Name Type Description options
Object Optional parameter for additional options. Returns:
Array - - An array of layers after the refresh operation. -
static removeEventListeners(options) → {void}
-
Removes event listeners from the element.
Parameters:
Name Type Description options
Object An object containing options for removing event listeners. Properties
Name Type Description off
boolean A boolean flag to indicate whether to turn off event listeners. Returns:
void -
static removeLayer(id) → {string}
-
This function removes a layer from the map and the layers array based on the provided id.
Parameters:
Name Type Description id
string The id of the layer to be removed. Returns:
string - The id of the removed layer. -
static removeLayers(layers) → {Array}
-
Removes multiple layers from the context.
Parameters:
Name Type Description layers
Array An array of layer objects to be removed. Returns:
Array - - An array of IDs of the removed layers. -
static removeSource(id) → {string}
-
This function removes a source from the map and the internal sources array based on the provided id.
Parameters:
Name Type Description id
string The id of the source to be removed. Returns:
string - The id of the removed source. -
static removeSources(sources) → {void}
-
Removes sources from the map.
Parameters:
Name Type Description sources
Array An array of source IDs to be removed. If not provided, it defaults to all source IDs. Returns:
void -
static setCustomLayers(layers, options) → {Promise.<Array>}
-
This function takes an array of custom layers and options, builds the layers using the buildLayers function, and returns the resulting layers.
Parameters:
Name Type Description layers
Array An array of custom layers to be processed. options
Object Additional options for building the layers. Returns:
Promise.<Array> - The processed custom layers.