RelationBuilder helps to create OSM Relations.
Methods of RelationBuilder can be used in a static and in an instance context. It isn't necessary to create an instance of RelationBuilder, unless it is configured with a DataSet, which created ways are added to.
var RelationBuilder = require("josm/builder").RelationBuilder;
var DataSet = org.openstreetmap.josm.data.osm.DataSet;
var ds = new DataSet();
// create a relation builder without and underlying dataset ...
var rbuilder = new RelationBuilder();
// ... with an underlying dataset ...
rbuilder = new RelationBuilder(ds);
// ... or using this factory method
rbuilder = RelationBuilder.forDataSet(ds);
// create a new local relation
var r1 = rbuilder.create();
// create a new global way
var r2 = rbuilder.withTags({route: 'bicycle'}).create(123456);
// create a new proxy for a global relation (an "incomplete" node in JOSM terminology)
var r3 = rbuilder.createProxy(123456);
Name | Description |
---|---|
Methods | |
create | Creates a new relation. |
createProxy | Creates a new proxy relation. |
forDataSet | Creates a new RelationBuilder which adds created relations to a dataset |
withId | Declares the relation id and version. |
withMembers | Declares the members of a relation. |
withTags | Declares the tags to be assigned to the new relation. |
new RelationBuilder()
Creates a new builder for OSM relations
Name | Type | Description |
---|---|---|
ds | DataSet | (optional) a JOSM dataset which created ways are added to. If missing, the created ways aren't added to a dataset. |
create:Relation
Creates a new relation.
Can be used in an instance or in a static context.
Optional named arguments in the parametersargs
Name | Type | Description |
---|---|---|
id | number | (optional) a global way id. If missing and not set before using
withId(..) , creates a new local id. |
args | object | (optional) additional parameters for creating the way |
var rb = require("josm/builder").RelationBuilder
var nb = require("josm/builder").NodeBuilder
var member = rb.member;
// create a new local relation
var r1 = rb.create();
// create a new global relation
var r2 = rb.create(12345);
// create a new global relation with version 3 with some tags and two members
var r3 = rb.create(12345, {
version: 3,
tags: {type: "route"},
members: [member('house', nb.create()), member(nb.create())]
});
createProxy:Relation
Creates a new proxy relation. A proxy relation is a relation, for which we only know its global id. In order to know more details (members, tags, etc.), we would have to download it from the OSM server.
The method can be used in a static and in an instance context.
var rbuilder = require("josm/builder").RelationBuilder;
// a new proxy relation for the global way with id 12345
var r1 = rbuilder.createProxy(12345);
forDataSet:RelationBuilder
Creates a new RelationBuilder which will add created relations to the dataset.
var ds = new org.openstreetmap.josm.data.osm.DataSet();
var rb = require("josm/builder").RelationBuilder.forDataSet(ds);
withId:RelationBuilder
Declares the global relation id and the global relation version.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
id | number | (mandatory) the global relation id. A number > 0. |
version | number | (optional) the global relation version. If present, a number > 0. If missing, the version 1 is assumed. |
var rbuilder = require("josm/builder").RelationBuilder;
// creates a global relation with id 12345 an version 12
var r = rbuilder.withId(12345, 12).create();
withMembers:RelationBuilder
Declares the members of a relation.
Accepts either a vararg list of relation members, nodes, ways or relations, an array of relation members, nodes ways or relations, or a Java list of members, nodes, ways or relation.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
nodes | the list of members. See description and examples. |
var rbuilder = require("josm/builder").RelationBuilder;
var nbuilder = require("josm/builder").NodeBuilder;
var wbuilder = require("josm/builder").WayBuilder;
var member = require("josm/builder").RelationBuilder.member;
var r1 = rbuilder.withMembers(
member("house", nbuilder.create()),
member("house", nbuilder.create()),
member("street", wbuilder.create())
).create();
withTags:RelationBuilder
Declares the tags to be assigned to the new relation.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
tags | object | (optional) the tags |
var rbuilder = require("josm/builder").RelationBuilder;
// a new global relation with the global id 12345 and tags route="bicycle" and name="n8"
var r1 = rbuilder.withTags({name:"n8", route:"bicycle"}).create(12345);
// a new local node tags name=test and highway=road
var tags = {
name : "n8",
route : "bicycle"
};
var r2 = rbuilder.withTags(tags).create();