Class: Api
josm/api. Api
Collection of static methods to download objects from and upload objects
to the OSM server.
Note: this class doesn't provide a constructor.
Methods and properties are 'static'.
Collection of static methods to download objects from and upload objects to the OSM server
// load the api import { Api } from 'josm/api' // download node 12345 const ds = Api.downloadObject(12345, 'node')
Name | Type | Description |
---|---|---|
bounds |
Bounds | module:josm/api~BoundsSpec1 | module:josm/api~BoundsSpec2 | the bounding box |
import { Api } from 'josm/api' const Bounds = Java.type('org.openstreetmap.josm.data.Bounds') const LatLon = Java.type('org.openstreetmap.josm.data.coor.LatLon') const ds1 = Api.downloadArea(new Bounds( new LatLon(46.9479186,7.4619484), // min new LatLon(46.9497642, 7.4660683) // max )) const ds2 = Api.downloadArea({ min: {lat: 46.9479186, lon: 7.4619484}, max: {lat: 46.9497642, lon: 7.4660683} })
downloadObject(id, type, ?options)
id
is the global numeric id.
type
is either one of the strings 'node', 'way',
or 'relation', or one of the enumeration OsmPrimitiveType.NODE,
OsmPrimitiveType.WAY, or OsmPrimitiveType.RELATION
downloadObject(id, ?options)
id
is a PrimitiveId
or an object
with the (mandatory) properties id
and type
,
i.e. an object {id: ..., type: ...}
.
id
is again a number, type
is again either one
of the strings 'node', 'way', or 'relation', or one of the
enumeration OsmPrimitiveType.NODE, OsmPrimitiveType.WAY,
or OsmPrimitiveType.RELATION.
Name | Type | Argument | Description |
---|---|---|---|
id |
number | PrimitiveId | the id of the object | |
type |
string | OsmPrimitiveType |
<optional> |
the type of the object |
options |
module:josm/api~DownloadObjectOptions |
<optional> |
named options |
import { Api } from 'josm/api' const SimplePrimitiveId = Java.type('org.openstreetmap.josm.data.osm.SimplePrimitiveId') const OsmPrimitiveType = Java.type('org.openstreetmap.josm.data.osm.OsmPrimitiveType') // download the node with id 12345 const ds1 = Api.downloadObject(12345, 'node') // download the node with id 12345 const ds2 = Api.downloadObject({id: 12345, type: 'node'}) // download the full relation (including its members) with id 12345 const id = new SimplePrimitiveId(12345, OsmPrimitiveType.RELATION) const ds3 = Api.downloadObject(id, {full: true}) // download version 5 of the full way 12345 (including its nodes) const ds4 = Api.downloadObject(12345, OsmPrimitiveType.WAY, {full: true, version: 5})
{full: true}
, every referring object
is downloaded in full.
There are multiple options to specify what referrers to download.
In addition, the function accepts a set of optional named parameters as
last argument.
downloadReferrer(id, type, ?options)
id
is the global numeric id.
type
is either one of the strings 'node', 'way', or
'relation', or one of the enumeration
OsmPrimitiveType.NODE,
OsmPrimitiveType.WAY,
or OsmPrimitiveType.RELATION.
downloadReferrer(id, ?options)
id
is a PrimitiveId
or an object
with the (mandatory) properties id
and type
,
i.e. an object {id: ..., type: ...}
.
id
is again a number, type
is again either one
of the strings 'node', 'way', or 'relation', or one of the
enumeration
OsmPrimitiveType.NODE,
OsmPrimitiveType.WAY,
or OsmPrimitiveType.RELATION.
Name | Type | Argument | Description |
---|---|---|---|
id |
number | PrimitiveId | the id of the object | |
type |
string | OsmPrimitiveType |
<optional> |
the type of the object |
options |
module:josm/api~DownloadReferrerOptions |
<optional> |
named options |
import { Api } from 'josm/api' import { NodeBuilder } from 'josm/builder' const SimplePrimitiveId = Java.type('org.openstreetmap.josm.data.osm.SimplePrimitiveId') const OsmPrimitiveType = Java.type('org.openstreetmap.josm.data.osm.OsmPrimitiveType') // download the objects referring to the node with id 12345 const ds1 = Api.downloadReferrer(12345, 'node') // download the objects referring to the node with id 12345 const ds2 = Api.downloadReferrer({id: 12345, type: 'node'}) // download the relations referring to the relation with id 12345. // Referring relations are downloaded in full. const id = new SimplePrimitiveId(12345, OsmPrimitiveType.RELATION) const ds3 = Api.downloadReferrer(id, { full: true }) // create the global node 12345 ... const node = NodeBuilder.create(12345) // ... and downloads its referrers in full const ds = Api.downloadReferrer(node, { full: true })
{strategy: ...}
to choose the
strategy.
Be careful when uploading data to the OSM server! Do not upload copyright- protected or test data.
The method takes care to update the primitives in the uploaded data when the upload succeeds. For instance, uploaded new primitives become global objects and get assigned their new id and version, successfully deleted objects become invisible, etc. Even if the entire upload of a dataset fails, a subset therefore may have been uploaded successfully. In order to keep track, which pritives have been uploaded successfully in case of an error, the method replies a collection of the successfully uploaded objects.Name | Type | Argument | Description |
---|---|---|---|
data |
DataSet | APIDataSet | array | Collection | the data to upload | |
comment |
string | the upload comment | |
options |
module:josm/api~UploadOptions |
<optional> |
named options |
const DataSet = Java.type('org.openstreetmap.josm.data.osm.DataSet') import { WayBuilder, NodeBuilder } from 'josm/builder' import { Api } from 'josm/api' const ds = new DataSet() const nb = NodeBuilder.forDataSet(ds) WayBuilder .forDataSet(ds) .withNodes( nb.withTags({name: 'node1'}).create(), nb.withTags({name: 'node2'}).create() ) .withTags({name: 'way1'}) .create() // uploads the data in a new changeset in one chunk const processed = Api.upload(ds, 'just testing')