Discord
@hash/gis
Simulation
18
0
Public

GIS

This library includes three behaviors to help in constructing simulations using the Geospatial viewer: Easily convert between lng_lat to position Requests a route between two coordinates Move along a route

This library contains behaviors designed to help build simulations which use the Geospatial view.

Longitude/Latitude to Position

The ll_to_pos.js behavior allows your geospatial agents to easily display in the 3D Viewer. Agents in the geospatial viewer have a lng_lat property defining their location, and this behavior will automatically set their position property as well.

Global Requirements

In addition to adding the ll_to_pos.js behavior to an agent, you'll need to set two properties in globals.json:

{
  // The lng_lat coordinate that will correspond to position [0, 0]
  "center_ll": number[2],
  // The scaling factor from the Geospatial view to the 3D Viewer. 
  // A lng_lat change of 1 equals a change of "scale_ll" in 3D
  "scale_ll": number
}

Request Route

The request_route.js behavior allows your agent to generate a route from its current GIS location (state.lng_lat) to a destination (state.gis.destination). The behavior uses a MapBox API call to determine the route, which is constructed of waypoints along real roads.

Since this behavior must send and then receive a message with the route, it takes 2 simulation steps to complete. Once the route has been received by the agent, it is stored in state.gis.route, and the behavior is removed from the agent.

Follow Route

The follow_route.js behavior allows your agent to follow the route instructions retrieved by the previous behavior. The agent must have a valid route stored in state.gis.route (this is automatically stored by request_route.js).

Each step, the agent will progress along the route a set distance, based on the agent's speed. This must be defined (in lat/long degrees per step) in state.gis.speed. The conversion between units of distance in lat/long degrees to meters is roughly 1:111,139.

The direction the agent faces (state.direction) will be adjusted based on its movement.