This module provides the gamepad functionality for the Geoflo application. It allows users to interact with the map using a gamepad controller.
Methods
-
static init(gamepad, options) → {Object}
-
This function initializes the gamepad with the specified options. It fires an event to notify the gamepad initialization, sets the gamepad, adds event listeners, and requests animation frame.
Parameters:
Name Type Description gamepad
Object The gamepad object to be initialized. options
Object The options for gamepad initialization. Returns:
Object - The current object instance. -
static refresh() → {void}
-
Refreshes the gamepad state by checking button presses, axes values, and triggers.
Returns:
void -
static remove(gamepad) → {void}
-
Disconnects and removes the gamepad object.
Parameters:
Name Type Description gamepad
Object The gamepad object to be disconnected and removed. Returns:
void -
static setBearing(value, left, dpad) → {boolean}
-
This function updates the bearing of the map by adjusting it with the specified value and direction.
Parameters:
Name Type Description value
number | Array.<number> The value to adjust the bearing by. If dpad is false, it should be an array of numbers, otherwise a single number. left
boolean Indicates the direction of adjustment. If true, the bearing is decreased; otherwise, it is increased. dpad
boolean Specifies whether the value is coming from a dpad input. Returns:
boolean - Returns the result of calling the setMap function after updating the bearing. -
static setCenter(value, free, dpad) → {boolean}
-
This function calculates the new center of the map based on the input values and gamepad controls. It handles both joystick and D-pad inputs to adjust the map center accordingly.
Parameters:
Name Type Description value
Object The value used to calculate the new center of the map. free
boolean A boolean flag indicating if the map center should be set freely. dpad
boolean A boolean flag indicating if the D-pad controls are used for setting the map center. Returns:
boolean - Returns true after setting the map center. -
static setContainer(tagName, className, container) → {HTMLElement}
-
Creates a new HTML element with the specified tag name and class name, appends it to a container if provided, and sets it as the container property of the current object.
Parameters:
Name Type Description tagName
string The tag name of the HTML element to create. className
string The class name to assign to the created element (optional). container
HTMLElement The container element to append the created element to (optional). Returns:
HTMLElement - The created HTML element. -
static setGamepad(gamepad) → {Object}
-
Initializes a gamepad object with specific properties based on the provided gamepad input.
Parameters:
Name Type Description gamepad
Object The gamepad object to be processed. Returns:
Object - - The processed gamepad object with defined properties. -
static setLocation(value) → {DOMRect}
-
This function updates the visibility, left, and top properties of the container element based on the provided value.
Parameters:
Name Type Description value
Array.<number> An array containing the x and y coordinates for the new location. Returns:
DOMRect - The bounding rectangle of the container element after the location is set. -
static setMap(handleMove) → {Object}
-
This function updates the map properties using the handleMove function and sets the center, zoom, pitch, and bearing accordingly.
Parameters:
Name Type Description handleMove
function The function used to handle map movement. Returns:
Object - The updated map object with new properties. -
static setMarker() → {Object}
-
Sets a marker on the map using the center coordinates provided by the context.
Returns:
Object - Returns the marker object created on the map. -
static setPitch(value, up, dpad) → {boolean}
-
This function adjusts the pitch of the map by a specified amount in the given direction.
Parameters:
Name Type Description value
number | Array.<number> The value or array of values to adjust the pitch by. up
boolean A boolean indicating whether the pitch should be increased (true) or decreased (false). dpad
boolean A boolean flag to determine if the value is coming from a D-pad input. Returns:
boolean - Returns true if the map is successfully updated with the new pitch. -
static setSpeed(value, down) → {number}
-
This function calculates the speed of panning based on the provided value and direction. It ensures that the speed falls within the specified minimum and maximum values.
Parameters:
Name Type Description value
number The value that influences the speed of panning. down
boolean A boolean flag indicating the direction of panning (true for down, false for up). Returns:
number - The updated speed of panning after applying the calculations. -
static setZoom(value, out, dpad) → {boolean}
-
This function adjusts the zoom level of a map based on the provided value and direction.
Parameters:
Name Type Description value
number The amount by which to change the zoom level. out
boolean A flag indicating whether to zoom out (true) or zoom in (false). dpad
boolean A flag indicating the direction of the zoom change. Returns:
boolean - - Returns the result of setting the map with the new zoom level. -
static trigger(id, triggered, index, value)
-
This function handles triggering actions based on gamepad input. It checks if a specific button or axis is triggered and performs corresponding actions.
Parameters:
Name Type Description id
string The identifier of the gamepad input. triggered
boolean Indicates if the input is triggered. index
number The index of the input. value
Array.<number> The value of the input.