Package-level declarations
Types
FeatureTree is a class which stores FeatureCollections within an rtree which gives us faster spatial searching. The APIs are purely FeatureCollections - pass one in to create the tree and then call one of generateFeatureCollection, generateNearbyFeatureCollection or generateNearestFeatureCollection to return a FeatureCollection trimmed down by location.
Properties
Functions
Gives the heading from one point to another point.
Calculate the approximate center coordinates of a circle based on the start and end coordinates of a segment and the arc midpoint.
Calculate the approximate center coordinates of a circle based on a segment.
Calculate the radius of a circle based on the chord length, arc midpoint and chord midpoint
There's a bug in the backend API where the GeoJSON can contain data that isn't part of the tile for example the 16/32277/21812.json contains MultiPolygons for the University of Law, University of Bristol, and Monarchs Way walking route. This strips out Features that someone has wrapped giant polygons around in the original OSM data. Need to see if there is a fix for this on the backend...
Return a triangle that is used as a "field of view".
processFeatureCollection goes through the feature collection from a tile and adds it to the feature collection for the grid, deduplicating by OSM is as it goes.
Compute the Haversine distance between the two coordinates.
Calculate distance of a point p to a line defined by two other points l1 and l2.
Calculate distance of a point (pLat,pLon) to a line defined by two other points (lat1,lon1) and (lat2,lon2)
Distance to a LineString from current location.
Distance to a Polygon from current location.
Given a Feature Collection that contains a LineString it will return a Feature Collection that contains the "exploded" LineString which are the individual segments of the LineString.
Given a Feature Collection that contains a Polygon it will return a Feature Collection that contains the "exploded" Polygon which are the individual segments of the Polygon as LineStrings.
Calculate the center coordinates of a circle based on the arc midpoint, chord bearing and radius.
This represent the original iOS AHEAD_BEHIND direction type which they described like this:
Given a BoundingBox returns the coordinates for the corners.
Given a LineString object returns the bounding box for it.
Given a MultiLineString object returns the bounding box for it.
Given a MultiPoint object return the bounding box for it.
Given a MultiPolygon object returns the bounding box for it.
Given a Point object returns the bounding box for it.
Given a Polygon object returns the bounding box.
Gives the coordinates for the center of a bounding box.
This represent the original iOS COMBINED direction type which they described like this:
Return a destination coordinate based on a starting point, bearing and distance.
Returns a road direction type in relation to the intersection: The road is leading up to an intersection - LEADING → --------------⦿ The road starts from an intersection - TRAILING → ⦿-------------- The road is leading up to and continues on from an intersection - LEADING_AND_TRAILING → → -------⦿------- The road is not part of the intersection - NONE ⦿
Given a Feature and a location this will calculate the nearest distance to it
Given a Feature Collection and location this will calculate the nearest distance to each Feature, and return a Feature Collection that contains the distance_to data for each Feature.
Given a road Feature and a set of intersectionRelativeDirections this will return a feature collection with an entry for the road each time it appears in the intersection. Normally this would be a single Feature (one road leaving the intersection) but if the road loops around and back into the roundabout then there can be two entries - see intersectionsLoopBackTest for an example e.g. https://geojson.io/#map=18/37.339112/-122.038756
Return a Feature Collection that contains the Features within the "field of view" triangle.
This represent the original iOS INDIVIDUAL direction type which they described like this:
Get the road names/ref/road type that make up the intersection. Intersection objects only contain "osm_ids" so we need to hook the osm_ids up with the information from the roads feature collection
Given an intersection Road names FeatureCollection, a nearest Intersection FeatureCollection and an intersectionRelativeDirections FeatureCollection. This will return a feature collection of the roads that make up the intersection tagged with their relative directions. 0 = Behind, 1 = Behind Left, 2 = Left, 3 = Ahead Left, 4 = Ahead, 5 = Ahead Right, 6 = Right, 7 = Behind Right
This represent the original iOS LEFT_RIGHT direction type which they described like this:
Get nearest road from roads Feature Collection. WARNING: It doesn't care which direction the road is. Roads can contain crossings which are Points not LineStrings.
Gets map coordinates from X and Y GPS coordinates. This is the same calculation as above but returns normalised x and y values scaled between 0 and 1.0. These are what are required by the mapcompose library to set markers/positions.
Parses out the super category Features contained in the Points of Interest (POI) Feature Collection.
Given a BoundingBox returns a closed Polygon.
Generates a quad key string from the tile X, Y coordinates and zoom level provided. Here's the Microsoft info: https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
Calculates the bounds of the quadrants that should be used for filtering POIs These quadrants are rotated from the standard cardinal direction quadrants (north: [315.0, 45.0), east: [45.0, 135.0), etc.) such that the provided heading becomes the center of the standard cardinal direction quadrant that it belongs to. This ensures that callouts filtered into quadrants will always be centered around the user's current heading if possible (if quadrants were fixed to the standard cardinal direction, and the user were facing 315.0, then all callouts for north
would be to the user's right). Here are several examples to illustrate how this works:
Calculates a coordinate on a LineString at a target distance from the first coordinate of the LineString.
A wrapper around: getCombinedDirectionPolygons, getIndividualDirectionPolygons, getAheadBehindDirectionPolygons, getLeftRightDirectionPolygons
Given an intersection Feature and a road Feature will return the bearing of the road to the intersection
Given a start and end location and a FeatureCollection that contains connected roads it will return a FeatureCollection with a LineString that represents the shortest route between the start and end locations. The shortest route is calculated using Dijkstra's algorithm.
Given a super category string returns a mutable list of things in the super category. Categories taken from original Soundscape.
Given a radius and location it calculates the set of tiles (VectorTiles) that cover a circular region around the specified location.
Determines the ground resolution (in meters per pixel) at a specified latitude and level of detail.
isDuplicateByOsmId returns true if the OSM id for the feature has already been entered into the existingSet. It returns false if it's the first time, or there's no OSM id.
Check if two LineStrings intersect.
Given an array of Segments and some user geometry with the location and Field of View distance it which represent the FoV triangles it will generate a FeatureCollection of triangles.
Checks if a point is on the right side of a line segment or not.
Determine if a coordinate is contained within a polygon.
Given a FeatureCollection checks for duplicate OSM IDs and removes them.
Given a Feature Collection and location this will calculate the nearest distance to each Feature, and return a sorted Feature Collection by the distance_to foreign member for each Feature.
Given an intersection Feature and a road Feature will split the road into two based on the coordinate of the intersection.
Calculates the Bounding Box coordinates for a Slippy Tile with a given zoom level.
Given a Feature Collection that contains a LineString it will return a Feature Collection of Points that trace along the LineString at given distance intervals. This is useful for faking the locations of a user walking down a road but isn't super accurate if you enter big distance intervals and the LineString has lots of curves or bends.