Global

Members

agentmap

Generates an agentmap for the given map.
Source:

Methods

(private) addStreetLayerIntersections(street)

Gets the intersections of all the streets on the map and adds them as properties to the street layers.
Parameters:
Name Type Description
street object A Leaflet polyline representing a street.
Source:

agent(lat_lng, options, agentmap)

Returns an agent object.
Parameters:
Name Type Description
lat_lng LatLng A pair of coordinates to locate the agent at.
options Object An array of options for the agent, namely its layer.
agentmap Agentmap The agentmap instance in which the agent exists.
Source:

(private) checkEndExcess(path)

If the last two points before the goal point share the same street as the goal point, and the first point is closer to the third (goal) point than it is to the second point, remove the second point, as it's a superfluous detour.

Typically happens when the goal point's nearest intersection is beyond it on the street, and so the path would have an agent travel from the first point, then to the intersection (second point), then backwards to the (third) goal point.

Parameters:
Name Type Description
path Array.<LatLng> An array of LatLngs representing a path for an agent to travel along.
Source:

(private) checkStartExcess(path)

If the first two points after the start point share the same street as the start point, and the third point is closer to the first (start) point than it is to the second point, remove the second point, as it's a superfluous detour.

Typically happens when the start point's nearest intersection is beyond it on the street, and so the path would have an agent travel from the start, then to the intersection, then backwards to the third point.
Parameters:
Name Type Description
path Array.<LatLng> An array of LatLngs representing a path for an agent to travel along.
Source:

(private) decodeCoordString(coord_string, place) → {LatLng}

Turn a string containing coordinates (a graph node's ID) into a LatLng object.
Parameters:
Name Type Description
coord_string string A string containing coordinates in the format of "Latitude,Longitude".
place object An object specifying the place of the coordinate string.
Source:
Returns:
- The coordinates encoded by the coord_string.
Type
LatLng

(private) encodeLatLng(lat_lng) → {string}

Turn a LatLng object into a string representing its coordinates (to act as a graph node's ID).
Parameters:
Name Type Description
lat_lng LatLng The coordinates to encode into a string.
Source:
Returns:
- A string containing coordinates in the format of "Latitude,Longitude".
Type
string

(private) generateUnitFeatures(unit_anchors, proposed_unit_features, street_leaflet_id, street_OSM_id, unit_options) → {Array.<Feature>}

Given an array of anchor pairs, for each anchor pair find four nearby points on either side of the street appropriate to build a unit(s) on.
Parameters:
Name Type Description
unit_anchors Array.<Array.<Feature>> Array of pairs of points around which to anchor units along a street.
proposed_unit_features Array.<Feature> Array of features representing building units already proposed for construction.
street_leaflet_id string The Leaflet layer ID of the street feature along which the unit is being constructed.
street_OSM_id string The OSM feature ID of the street feature along which the unit is being constructed.
unit_options object An object containing the AgentMaps styling options for units.
Source:
Returns:
unit_features - Array of features representing units.
Type
Array.<Feature>

getIntersections(arr_a, arr_b, ids) → {Array.<Array.<(number|Object.<number, number>)>>}

Given two coordinate arrays, get their intersections.
Parameters:
Name Type Description
arr_a array.<array.<number>> Array of coordinate pairs.
arr_b array.<array.<number>> Array of coordinate pairs.
ids array.<number> 2-element array whose elements are IDs for arr_a and arr_b respectively.
Source:
Returns:
- Array whose elements are the intersections' cooridinate-pairs if ids is empty, or otherwise whose elements are arrays each of whose first element is an intersection's coordinate-pair and whose second element is an object mapping each array's ID (supplied by ids) to the index of the intersection's coordinate-pair in that array.
Type
Array.<Array.<(number|Object.<number, number>)>>

getPathFinder(graph) → {object}

Given a street network (graph), return a pathfinder that can operate on it. Useful if you modify the street graph during the simulation.
Parameters:
Name Type Description
graph object An ngraph graph representing an OSM street network.
Source:
Returns:
- An A* pathfinder for the graph.
Type
object

(private) getStreetFeatures(OSM_data) → {Array.<Feature>}

Get all streets from the GeoJSON data.
Parameters:
Name Type Description
OSM_data Object A GeoJSON Feature Collection object containing the OSM streets inside the bounding box.
Source:
Returns:
- array of street features.
Type
Array.<Feature>

(private) getUnitAnchors(street_feature, unit_options) → {Array.<Array.<Feature>>}

Find anchors for potential units. chors are the pairs of start and end points along the street from which units may be constructed.
Parameters:
Name Type Description
street_feature Feature A GeoJSON feature object representing a street.
unit_options object An object containing the AgentMaps styling options for units.
Source:
Returns:
- Array of pairs of points around which to anchor units along a street.
Type
Array.<Array.<Feature>>

(private) getUnitFeatures(bounding_box, OSM_data, unit_options) → {Array.<Feature>}

Get all appropriate units within the desired bounding box.
Parameters:
Name Type 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.
unit_options object An object containing the AgentMaps styling options for units.
Source:
Returns:
- Array of features representing real estate units.
Type
Array.<Feature>

(private) getUnitNeighborLayerIDs(neighbors) → {Array.<?number>}

Given an array of pre-layer IDs, check if any of them correspond to the pre-layer IDs of unit layers, and if so return an array of the corresponding layer IDs.
Parameters:
Name Type Description
neighbors Array.<?number> An array of pre-layer feature IDs for a unit's neighbors.
Source:
Returns:
- An array of Leaflet layer IDs corresponding to the unit's neighbors.
Type
Array.<?number>

isPointCoordinates(array) → {boolean}

Given an array, check whether it can represent the coordinates of a point.
Parameters:
Name Type Description
array Array Array to check.
Source:
Returns:
- Whether the array can be the coordinates of a point.
Type
boolean

(private) noOverlaps(reference_polygon_feature, polygon_feature_array) → {boolean}

Check whether a polygon overlaps with any member of an array of polygons.
Parameters:
Name Type Description
reference_polygon_feature Feature A geoJSON polygon feature.
polygon_feature_array Array.<Feature> Array of geoJSON polygon features.
Source:
Returns:
- Whether the polygon_feature overlaps with any one in the array.
Type
boolean

pointToCoordinateArray(point) → {Array.<number>}

Given either a GeoJSON feature, L.latLng, or coordinate array containing the coordinates of a point, return an array of the coordinates.
Parameters:
Name Type Description
point Point | Array.<number> | LatLng The data containing the point's coordinates (latitude & longitude).
Source:
Returns:
- Array of the point's coordinates. I.e.: [lng, lat].
Type
Array.<number>

reversedCoordinates(coordinates) → {Array.<(number|Array.<(number|Array.<number>)>)>}

Given a geoJSON geometry object's coordinates, return the object, but with all the coordinates reversed.
Why? GeoJSON coordinates are in lngLat format by default, while Leaflet uses latLng. L.geoJSON will auto-reverse the order of a GeoJSON object's coordinates, as it expects geoJSON coordinates to be lngLat. However, normal, non-GeoJSON-specific Leaflet methods expect Leaflet's latLng pairs and won't auto-reverse, so we have to do that manually if we're preprocessing the GeoJSON data before passing it to L.geoJSON.
Parameters:
Name Type Description
coordinates Array.<(number|Array.<(number|Array.<number>)>)> GeoJSON coordinates for a point, (multi-)line, or (multi-)polygon.
Source:
Returns:
- Reversed geoJSON coordinates for a point, (multi-)line, or (multi-)polygon.
Type
Array.<(number|Array.<(number|Array.<number>)>)>

setupStreetFeatures(OSM_data, street_options, street_layersopt)

Generate and setup streets based on the provided GeoJSON data.
Parameters:
Name Type Attributes Description
OSM_data object A GeoJSON Feature Collection object containing the OSM street features inside the bounding box.
street_options object An object containing the Leaflet styling options for streets.
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:

setupUnitFeatures(bounding_box, OSM_data, unit_options, unit_layersopt)

Generate and setup building units based on the provided GeoJSON data.
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.
unit_options object An object containing the Leaflet & AgentMaps styling options for units.
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.
Source:

streetsToGraph(streets) → {Object}

Convert a layerGroup of streets into a graph. Useful if you modify the street layers during the simulation and want routing to work with the new street network.
Parameters:
Name Type Description
streets LayerGroup A Leaflet layerGroup of streets, forming a street network.
Source:
Returns:
- A graph representing the street network, operable by the ngraph pathfinder.
Type
Object

streetToGraph(graph, street)

Process a street layer and add it into a graph.
Parameters:
Name Type Description
graph ngraph.graph An ngraph.graph representing a street network.
street L.Polyline A Leaflet Polyline layer for a street.
Source:

(private) unitsOutOfStreets(unit_features, street_layers) → {Array.<Feature>}

Get an array of units excluding units that overlap with streets.
Parameters:
Name Type Description
unit_features Array.<Feature> Array of features representing units.
street_layers Array.<Layer> Array of Leaflet layers representing streets.
Source:
Returns:
- unit_features, but with all units that intersect any streets removed.
Type
Array.<Feature>

Type Definitions

agentFeatureMaker(id) → {Point}

A user-defined callback function that returns a feature with appropriate geometry and properties to represent an agent.
Parameters:
Name Type Description
id number The agent's Leaflet layer ID.
Source:
Returns:
- A GeoJSON Point object with geometry and other properties for the agent, including a "place" property that will set the agent's initial Place and a "layer_options" property that will specify the feature's Leaflet options (like its color, size, etc.). All other provided properties will be transferred to the Agent object once it is created. See https://leafletjs.com/reference-1.3.2.html#circlemarker for all possible layer options.
Type
Point
Example
let point = {					
	"type": "Feature",				 
	"properties": {					
		"layer_options": {			
			"color": "red",			
			"radius": .5,			
		},					
		"place": {				
			"type": "unit",			
			"id": 89			
		},					
							
		age: 72,				
		home_city: "LA"				
	},						
	"geometry" {					
		"type": "Point",			
		"coordinates": [			
			14.54589,			
			57.136239			
		]					
	}						
}							

Feature

A GeoJSON feature object.
Type:
  • object
Properties:
Name Type Description
type string Should be "Feature".
properties object Non-geometric properties of the feature.
geometry object Geometric properties of the feature (a GeoJSON spec of the feature's geometry).
Properties
Name Type Description
type string The feature's GeoJSON geometry type.
coordinates Array The coordinates specifying the feature's geometry.
Source:
See:

LatLng

Represents a latitude/longitude pair. Preferably an instance of L.LatLng: https://leafletjs.com/reference-1.3.2.html#latlng.
Type:
  • object
Properties:
Name Type Attributes Description
lat number A decimal latitude.
lng number A decimal longitude.
new_place Place <optional>
A place (unit or street) associated with this LatLng.
Source:

Place

A object describing a location.
Type:
  • object
Properties:
Name Type Description
type string Either "street", "unit", or "unanchored".
id number The ID of either a street or unit in the appropriate layer group, if the place is "street" or "unit".
Source:

Point

A GeoJSON Feature specifically for individual points.
Type:
Properties:
Name Type Description
geometry.coordinates Array A single array with 2 elements: [longitude, latitude].
Source: