geoflo.Locate

This module provides the geolocation functionality for the Geoflo application. It allows users to locate their current position on the map and track their location.

Methods

static bearing() → {number}

This function retrieves the current bearing of the map.
Returns:
number - The bearing of the map.

static build() → {void}

This function hides the user location dot marker and the associated button.
Returns:
void

static follow() → {boolean}

Enables the follow functionality for the geolocate control. When activated, adds a specific class to the button, disables drag panning on the map, and sets the follow state to true.
Returns:
boolean - - Returns true to indicate that the follow functionality has been enabled.

static getButton() → {Element}

Returns the geolocate button element from the control.
Returns:
Element - The geolocate button element.

static heading() → {string}

Retrieves the heading value from the control object.
Returns:
string - The heading value from the control object.

static init(options) → {Object}

This function initializes the geolocation control on the map with the specified options.
Parameters:
Name Type Description
options Object The options for configuring the geolocation control.
Properties
Name Type Attributes Default Description
enableHighAccuracy boolean <optional>
true Whether to enable high accuracy for geolocation.
trackUserLocation boolean <optional>
true Whether to track the user's location.
showUserHeading boolean <optional>
true Whether to show the user's heading.
showAccuracyCircle boolean <optional>
false Whether to show the accuracy circle.
Returns:
Object - The current instance of the map with the geolocation control added.

static locate() → {void}

Initiates the process of locating the user's current position on the map.
Returns:
void

static onAdd(event) → {void}

Logs the event object to the console.
Parameters:
Name Type Description
event Event The event object that is triggered when an action occurs.
Returns:
void - This function does not return a value.
Author:
  • Solutegrate

static onControlEvent(event) → {void}

Handles control events, updating the marker and managing the state based on the event details.
Parameters:
Name Type Description
event Object The event object containing details about the control event.
Properties
Name Type Description
coords Object The coordinates associated with the event, if available.
target HTMLElement The target element that triggered the event.
Returns:
void - This function does not return a value.
Author:
  • Solutegrate

static onLocate(event) → {void}

Handles the location update event, updating the current location and firing an event with the new state.
Parameters:
Name Type Description
event Object The event object containing location data.
Properties
Name Type Description
coords Object The coordinates of the current location.
Returns:
void - This function does not return a value.
Author:
  • Solutegrate

static onMapMove(event) → {void}

Handles the map movement event, updating the button classes based on the current state and conditions.
Parameters:
Name Type Description
event Object The event object representing the map movement.
Returns:
void - This function does not return a value.
Author:
  • Solutegrate

static ready() → {void}

This function checks if the geolocate button is available in the control and then calls the build function.
Returns:
void

static relocate() → {void}

Relocates the geolocation control to the user's current location. If the control is set to follow the user's location, it changes the state to 'ACTIVE_LOCK'. Adds the 'mapboxgl-ctrl-geolocate-active' class to the button element. Triggers the control
Returns:
void

static removeClasses()

This function removes classes related to geolocation control from a button element.

static state(state) → {boolean}

This function is used to get or set the state of the control. If a state parameter is provided, it sets the control's watch state to that value. If no state parameter is provided, it returns the current watch state of the control.
Parameters:
Name Type Description
state boolean The state to set for the control.
Returns:
boolean - - The current watch state of the control.

static unlocate() → {Object}

Sets the state to 'ACTIVE_LOCK', disables following, enables drag pan on the map, and triggers the control.
Returns:
Object - The result of triggering the control.

static update(options) → {void}

This function updates the map bearing and center based on the provided options.
Parameters:
Name Type Description
options Object The options object.
Properties
Name Type Description
alpha number The alpha value.
Returns:
void