WayBuilder helps to create OSM Ways.
Methods of WayBuilder can be used in a static and in an instance context. It isn't necessary to create an instance of WayBuilder, unless it is configured with a DataSet, which created ways are added to.
var WayBuilder = require("josm/builder").WayBuilder;
var DataSet = org.openstreetmap.josm.data.osm.DataSet;
var ds = new DataSet();
// create a way builder without and underlying dataset ...
var wbuilder = new WayBuilder();
// ... with an underlying dataset ....
wbuilder = new WayBuilder(ds);
// ... or using this factory method
wbuilder = WayBuilder.forDataSet(ds);
// create a new local way
var w1 = wbuilder.create();
// create a new global way
var w2 = wbuilder.withTags({highway: 'residential'}).create(123456);
// create a new proxy for a global way (an "incomplete" node in JOSM terminology)
var w3 = wbuilder.createProxy(123456);
Name | Description |
---|---|
Methods | |
create | Creates a new way |
createProxy | Creates a new proxy way |
forDataSet | Creates a new WayBuilder with an underlying dataset. |
withId | Declares the global way id and the global way version. |
withNodes | Declares the nodes of the way. |
withTags | Declares the tags to be assigned to the new way. |
new WayBuilder()
Creates a new builder for OSM ways
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:Way
Creates a new way.
Can be used in an instance or in a static context.
Optional named arguments in the parametersoptions
:
id
:numberversion
:numbernodes
:array|listtags
:objectName | Type | Description |
---|---|---|
id | number | (optional) a global way id. If missing and not set before using
withId(..) , creates a new local id. |
options | object | (optional) additional parameters for creating the way |
var wb = require("josm/builder").WayBuilder
// create a new local way
var w1 = wb.create();
// create a new global way
var w2 = wb.create(12345);
// create a new global way with version 3 at a specific position and with some tags
var w3 = wb.create(12345, {
version: 3,
tags: {amenity: "restaurant"},
nodes: [n1,n2,n3]
});
createProxy:Way
Creates a new proxy way. A proxy way is a way, for which we only know its global id. In order to know more details (nodes, 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 wbuilder = require("josm/builder").WayBuilder;
// a new proxy way for the global way with id 12345
var w1 = wbuilder.createProxy(12345);
forDataSet:WayBuilder
Creates a new WayBuilder with an underlying dataset.
var ds = new org.openstreetmap.josm.data.osm.DataSet();
var wbuilder = require("josm/builder").WayBuilder.forDataSet(ds);
// creates a new local way and assigns it to the dataset 'ds'
var w = wbuilder.create();
withId:WayBuilder
Declares the global way id and the global way version.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
id | number | (mandatory) the global way id. A number > 0. |
version | number | (optional) the global way version. If present, a number > 0. If missing, the version 1 is assumed. |
var wbuilder = require("josm/builder").WayBuilder;
// creates a global way with id 12345 an version 12
var w = wbuilder.withId(12345, 12).create();
withNodes:WayBuilder
Declares the nodes of the way.
Accepts either a vararg list of Node, an array of Nodes or a Java list of Nodes. At least two non-identical nodes have to be supplied. The same node can occure more than once in the list, but a consecutive sequence of the same node is collapsed to one node.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
nodes | the list of nodes. See description and examples. |
var wbuilder = require("josm/builder").WayBuilder;
var nbuilder = require("josm/builder").NodeBuilder;
// creates a new local way with two local nodes
var way = builder.withNodes(
nbuilder.create(), nbuilder.create()
).create();
withTags:WayBuilder
Declares the tags to be assigned to the new way.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
tags | object | (optional) the tags |
var wbuilder = require("josm/builder").WayBuilder;
// a new global way with the global id 12345 and tags name="Laubeggstrasse" and highway=residential
var n1 = wbuilder.withTags({name:"Laubeggstrasse", highway:"residential"}).create(12345);
// a new local node tags name=test and highway=road
var tags = {
name : "Laubeggstrasse",
highway : "residential"
};
var n2 = wbuilder.withTags(tags).create();