Class: Agentmap

Agentmap(map, animation_intervalopt)

new Agentmap(map, animation_intervalopt)

The main class for building, storing, simulating, and manipulating agent-based models on Leaflet maps.
Parameters:
Name Type Attributes Default Description
map object A Leaflet Map instance.
animation_interval number <optional>
1 The number of steps agents must move before being redrawn. Given 1, they will be redrawn after every step. Given 0, the animation will not update at all. 1 by default. Must be a nonnegative integer.
Properties:
Name Type Attributes Description
map object A Leaflet Map instance.
agents FeatureGroup A featureGroup containing all agents.
units FeatureGroup A featureGroup containing all units.
streets FeatureGroup A featureGroup containing all streets.
state object Properties detailing the state of the simulation process.
Properties
Name Type Attributes Description
running boolean Whether the simulation is running or not.
paused boolean Whether the simulation is paused.
animation_frame_id number <nullable>
The id of the agentmap's update function in the queue of functions to call for the coming animation frame.
ticks number <nullable>
The number of ticks elapsed since the start of the simulation.
animation_interval number The number of steps agents must move before being redrawn. Given 1, they will be redrawn after every step. Given 0, the animation will not update at all. 1 by default. Will be a nonnegative integer.
controller function <nullable>
User-defined function to be called on each update.
Source:

Methods

agentify(count, agentFeatureMaker)

Generate some number of agents and place them on the map.
Parameters:
Name Type Description
count number The desired number of agents.
agentFeatureMaker agentFeatureMaker A callback that determines an agent i's feature properties and geometry (always a Point).
Source:

buildingify(bounding_box, OSM_data, street_optionsopt, unit_optionsopt, unit_layersopt, street_layersopt)

Generate and setup the desired map features (e.g. streets, houses).
Parameters:
Name Type Attributes Description
bounding_box Array.<Array.<number>> The map's top-left and bottom-right coordinates.
OSM_data object A GeoJSON Feature Collection object containing the OSM street features inside the bounding box.
street_options object <optional>
An object containing the Leaflet styling options for streets. See available options here: https://leafletjs.com/reference-1.3.2.html#polyline-l-polyline.
unit_options object <optional>
An object containing the Leaflet & AgentMaps styling options for units.
See available Leaflet options here: https://leafletjs.com/reference-1.3.2.html#polygon-l-polygon
Additional AgentMaps-specific options are described below.
Properties
Name Type Attributes Default Description
front_buffer number <optional>
6 The number of meters beetween the front of unit and its street.
side_buffer number <optional>
3 The number of meters between two units on the same street.
length number <optional>
14 The length of the unit in meters along the street.
depth number <optional>
18 The depth of the unit in meters out from its front.
unit_layers object <optional>
If you want to load a previously generated AgentMaps.units object instead of generating one from scratch: A GeoJSON Feature Collection of an AgentMaps.units featureGroup.
street_layers object <optional>
If you want to load a previously generated AgentMaps.streets object instead of generating one from scratch: A GeoJSON Feature Collection of an AgentMaps.streets featureGroup.
Source:

clear()

Stop the animation, reset the animation state properties, and delete the features.
Source:

downloadStreets()

Since street layers may take a noticeably long time to generate while typically staying the same over simulations, downloadStreets makes it easy to get a JS file containing the streets object, so it can be included with an AgentMaps app and imported into Agentmap.buildingify so they will not need to be regenerated.
Source:

downloadUnits()

Since units may take a noticeably long time to generate while typically staying the same over simulations, downloadUnits makes it easy to get a JS file containing the units object, so it can be included with an AgentMaps app and imported into Agentmap.buildingify so they will not need to be regenerated.
Source:

getNearestIntersection(lat_lng, place) → {LatLng}

Given a point on a street, find the nearest intersection on that street (with any other street).
Parameters:
Name Type Description
lat_lng LatLng The coordinates of the point on the street to search from.
place Place A place object corresponding to the street.
Source:
Returns:
- The coordinates of the nearest intersection.
Type
LatLng

getStreetNearDoor(unit_id) → {LatLng}

Get the point on the adjacent street in front of the unit's door.
Parameters:
Name Type Description
unit_id number The unique ID of the unit whose door's corresponding point on the street you want.
Source:
Returns:
- The coordinates point of the adjacent street directly in front of unit's door.
Type
LatLng

getUnitDoor(unit_id) → {LatLng}

Get a point through which an agent can exit/enter a unit.
Parameters:
Name Type Description
unit_id number The unique ID of the unit whose door you want.
Source:
Returns:
- The coordinates of the center point of the segment of the unit parallel to the street.
Type
LatLng

getUnitPoint(unit_id, x, y) → {LatLng}

Given a unit and a pair of coordinates between 0 and 1, return a corresponding point inside the unit, offset from its first corner along the street.
Parameters:
Name Type Description
unit_id number The unique ID of the unit whose interior point you want.
x number A point between 0 and 1 representing a position along the width of a unit.
y number A point between 0 and 1 representing a position along the depth of a unit.
Source:
Returns:
- The global coordinates of the specified position within the unit.
Type
LatLng

pause()

Stop the animation, stop updating the agents.
Source:

run()

Get an animation frame, have the agents update & get ready to be drawn, and keep doing that until paused or reset.
Source:

seqUnitAgentMaker()

A standard agentFeatureMaker, which sets an agent's location to be the point near the center of the iᵗʰ unit of the map, its place property to be that unit's, and its layer_options to be red and of radius .5 meters.
Source:

setAnimationInterval(animation_interval)

Change the animation interval of the simulation & redraw the agents.
Parameters:
Name Type Description
animation_interval number The desired animation interval to give the simulation. Must be a nonnegative integer.
Source: