# Global

##

### Members

#### agentmap

Generates an agentmap for the given map.

Source:
  - agentmap.js, line 278

### 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:
  - buildings.js, line 104

#### 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:
  - agents.js, line 665

#### (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:
  - routing.js, line 222

#### (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:
  - routing.js, line 187

#### (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:
  - routing.js, line 264

##### 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:
  - routing.js, line 252

##### 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:
  - buildings.js, line 254

##### 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 intersection.

##### 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:
  - utils.js, line 84

##### Returns:

- Array whose elements are the intersections' cooridinates if ids is empty, or otherwise whose elements are arrays each of whose first element is an intersection's coordinates and whose second element is an object mapping each array's ID (supplied by ids) to the index of the intersecting coordinate-pair in that array.

Type
  Array.<Array.<(number|Object.<number, number>)>>

#### (private) getPathFinder(graph) → {object}

Given an OSM street network (graph), return an A* pathfinder that can operate on it.

##### Parameters:

Name | Type | Description
--- | --- | ---
`graph` | object | An ngraph graph representing an OSM street network.

Source:
  - routing.js, line 92

##### Returns:

- An A* pathfinder for the graph.

Type
  object

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

Get all streets from the GeoJSON data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`streets_data` | Object | A GeoJSON Feature Collection object containing the OSM streets inside the bounding box.

Source:
  - buildings.js, line 82

##### 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:
  - buildings.js, line 347

##### Returns:

- Array of pairs of points around which to anchor units along a street.

Type
  Array.<Array.<Feature>>

#### (private) getUnitFeatures(bounding_box, streets_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.
`streets_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:
  - buildings.js, line 225

##### 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:
  - buildings.js, line 195

##### 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:
  - utils.js, line 36

##### 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:
  - buildings.js, line 410

##### Returns:

- Whether the polygon_feature overlaps with any one in the array.

Type
  boolean

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

Given either a GeoJSON feature, L.latLng, or coordinate array containing the coordinates of a point, return an array of the coordinates.

Source:
  - utils.js, line 53

##### 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:
  - utils.js, line 16

##### Returns:

- Reversed geoJSON coordinates for a point, (multi-)line, or (multi-)polygon.

Type
  Array.<(number|Array.<(number|Array.<number>)>)>

#### setupStreetFeatures(streets_data, street_options)

Generate and setup streets based on the provided GeoJSON data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`streets_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.

Source:
  - buildings.js, line 38

#### setupUnitFeatures(bounding_box, streets_data, unit_options, units_dataopt)

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.
`streets_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.
`units_data` | object | <optional> | If you want to load a previously generated AgentMaps.units object instead of generating one from scarch: A GeoJSON Feature Collection of an AgentMaps.units featureGroup.

Source:
  - buildings.js, line 138

#### (private) streetsToGraph(streets) → {Object}

Convert a layerGroup of streets into a graph.

##### Parameters:

Name | Type | Description
--- | --- | ---
`streets` | LayerGroup | A Leaflet layerGroup of streets, forming a street network.

Source:
  - routing.js, line 16

##### Returns:

- A graph representing the street network, operable by the ngraph pathfinder.

Type
  Object

#### streetToGraph()

Process a street layer and add it into a graph.

Source:
  - routing.js, line 32

#### (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:
  - buildings.js, line 383

##### 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:
  - agents.js, line 669

##### Returns:

- a GeoJSON Point feature with properties and coordinates for the agent, including a "place" property that will set the agent's initial Place and an object "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:
  - jsdocs.js, line 13
See:
  - http://geojson.org/

#### 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:
  - jsdocs.js, line 3

#### 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:
  - jsdocs.js, line 32

#### Point

A GeoJSON Feature specifically for individual points.

##### Type:

- Feature

##### Properties:

Name | Type | Description
--- | --- | ---
`geometry.coordinates` | Array | A single array with 2 elements: [longitude, latitude].

Source:
  - jsdocs.js, line 25