Class: OverpassFrontend

OverpassFrontend(url, options)

A connection to an Overpass API Server or an OpenStreetMap file

Constructor

new OverpassFrontend(url, options)

Parameters:
Name Type Description
url string The URL of the API, e.g. 'https://overpass-api.de/api/'. If you omit the protocol, it will use the protocol which is in use for the current page (or https: on nodejs): '//overpass-api.de/api/'. If the url ends in .json, .osm or .osm.bz2 it will load this OpenStreetMap file and use the data from there.
options object Options
Properties
Name Type Attributes Default Description
effortPerRequest number <optional>
1000 To avoid huge requests to the Overpass API, the request will be split into smaller chunks. This value defines, how many objects will be requested per API call (for get() calls see effortNode, effortWay, effortRelation, e.g. up to 1000 nodes or 250 ways or (500 nodes and 125 ways) at default values; for BBoxQuery() calls the setting will be divided by 4).
effortNode number <optional>
1 The effort for request a node. Default: 1.
effortWay number <optional>
4 The effort for request a way.
effortRelation number <optional>
64 The effort for request a relation.
timeGap number <optional>
10 A short time gap between two requests to the Overpass API (milliseconds).
timeGap429 number <optional>
1000 A longer time after a 429 response from Overpass API (milliseconds).
loadChunkSize number <optional>
1000 When loading a file (instead connecting to an Overpass URL) load elements in chunks of n items.
Properties:
Name Type Default Description
hasStretchLon180 boolean false Are there any map features in the cache which stretch over lon=180/-180?
Source:

Methods

BBoxQuery(query, bounds, options, featureCallback, finalCallback) → {RequestBBox}

Parameters:
Name Type Description
query string Query for requesting objects from Overpass API, e.g. "node[amenity=restaurant]" or "(node[amenity];way[highway~'^(primary|secondary)$];)". See Filter for details.
bounds BoundingBox A Leaflet Bounds object, e.g. from map.getBounds()
options object
Properties
Name Type Attributes Default Description
priority number <optional>
0 Priority for loading these objects. The lower the sooner they will be requested.
sort boolean | string <optional>
false If false, it will be called as soon as the features are availabe (e.g. immediately when cached).
properties bit_array <optional>
Which properties of the features should be downloaded: OVERPASS_ID_ONLY, OVERPASS_BBOX, OVERPASS_TAGS, OVERPASS_GEOM, OVERPASS_META. Combine by binary OR: ``OVERPASS_ID | OVERPASS_BBOX``. Default: OverpassFrontend.TAGS | OverpassFrontend.MEMBERS | OverpassFrontend.BBOX
split number <optional>
0 If more than 'split' elements would be returned, split into several smaller requests, with 'split' elements each. Default: 0 (do not split)
members boolean <optional>
false Query relation members of. Default: false
memberCallback function <optional>
For every member, call this callback function. (Requires options.members=true)
memberProperties bit_array <optional>
Which properties should be loaded for the members. Default: OverpassFrontend.TAGS | OverpassFrontend.MEMBERS | OverpassFrontend.BBOX
memberSplit number <optional>
0 If more than 'memberSplit' member elements would be returned, split into smaller requests (see 'split'). 0 = do not split.
filter string | Filter <optional>
Additional filter.
noCacheQuery boolean <optional>
false If true, the local cache will not be queried
featureCallback function Will be called for each matching object. Will be passed: 1. err (if an error occured, otherwise null), 2. the object or null.
finalCallback function Will be called after the last feature. Will be passed: 1. err (if an error occured, otherwise null).
Source:
Returns:
Type
RequestBBox

clearCache()

clear all caches
Source:

get(ids, options, featureCallback, finalCallback) → {RequestGet}

Parameters:
Name Type Description
ids string | Array.<string> Id or array of Ids of OSM map features, e.g. [ 'n123', 'w2345', 'n123' ]. Illegal IDs will not produce an error but generate a 'null' object.
options object Various options, see below
Properties
Name Type Attributes Default Description
priority number <optional>
0 Priority for loading these objects. The lower the sooner they will be requested.
sort string | boolean <optional>
false When set to true or "index", the function featureCallback will be called in order of the "ids" array. When set to false or null, the featureCallback will be called as soon as the object is loaded (e.g. immediately, if it is cached). When set to "BBoxDiagonalLength", the objects are ordered by the length of the diagonal of the bounding box.
sortDir "asc" | "desc" <optional>
"asc" Sort direction.
featureCallback function Will be called for each object which is passed in parameter 'ids'. Will be passed: 1. err (if an error occured, otherwise null), 2. the object or null, 3. index of the item in parameter ids.
finalCallback function Will be called after the last feature. Will be passed: 1. err (if an error occured, otherwise null).
Source:
Returns:
Type
RequestGet

getCached(id, options) → {null|false|OverpassObject}

return an OSM object, if it is already in the cache
Parameters:
Name Type Description
id string Id of an OSM map feature
options object
Properties
Name Type Attributes Description
properties int <optional>
Which properties have to be known (default: OverpassFrontend.DEFAULT)
Source:
Returns:
- null: does not exist in the database; false: may exist, but has not been loaded yet (or not enough properties known); OverpassObject: sucessful object
Type
null | false | OverpassObject

Type Definitions

Context

Current request context
Type:
  • Object
Properties:
Name Type Description
query string The compiled code of all sub requests
requests Array.<Request> List of all requests in the context
subRequests Array.<Request#SubRequest> List of all subRequests in the context
bbox BoundingBox when there are any BBox requests, add this global bbox
maxEffort int how many queries can we still add to this context
todo object list of items which should be loaded via get requests to avoid duplicates
Source:

Events

error

An error occured
Parameters:
Name Type Description
error Error
Source:

load

When a file is specified as URL, this event notifies, that the file has been completely loaded. When a Overpass API is used, every time when data has been received.
Parameters:
Name Type Description
osm3sMeta object Meta data (not all properties of meta data might be set)
Properties
Name Type Attributes Description
version number OpenStreetMap API version (currently 0.6)
generator string Data generator
timestamp_osm_base string RFC8601 timestamp of OpenStreetMap data
copyright string Copyright statement
bounds BoundingBox <optional>
Bounding Box (only when loading from file)
Source:

update

When an object is updated (e.g. when loaded; additional information loaded; when a member object got loaded)
Parameters:
Name Type Description
object OverpassNode | OverpassWay | OverpassRelation The object which got updated.
Source: