NodeBuilder helps to create OSM nodes.
Methods of NodeBuilder can be used in a static and in an instance context. It isn't necessary to create an instance of NodeBuilder, unless it is configured with a DataSet, which created nodes are added to.
var NodeBuilder = require("josm/builder").NodeBuilder;
var DataSet = org.openstreetmap.josm.data.osm.DataSet;
var ds = new DataSet();
// create a node builder without and underlying dataset ...
var nbuilder = new NodeBuilder();
// ... with an underlying dataset ....
nbuilder = new NodeBuilder(ds);
// ... or using this factory method
nbuilder = NodeBuilder.forDataSet(ds);
// create a new local node at position (0,0) without tags
var n1 = nbuilder.create();
// create a new global node at a specific position with tags
var n2 = nbuilder.withPosition(1,1).withTags({name: 'test'}).create(123456);
// create a new proxy for a global node (an "incomplete" node in JOSM terminology)
var n3 = nbuilder.createProxy(123456);
Name | Description |
---|---|
Methods | |
create | Creates a new Node |
createProxy | Creates a new proxy Node |
forDataSet | Creates a new NodeBuilder for a specific DataSet. |
withId | Declares the node id and version. |
withPosition | Declares the node position. |
withTags | Declares the node tags. |
new NodeBuilder()
Creates a new node builder.
Name | Type | Description |
---|---|---|
ds | DataSet | (optional) the dataset which created objects are added to |
create:Node
Creates a new Node.
Can be used in an instance or in a static context.
. Optional named arguments in the parametersargs
version
- the version of a global node (number > 0)lat
- a valide latitude (number in the range [-90,90])lon
- a valide longitude (number in the range [-180,180])pos
- either an array [lat,lon]
, an object {lat: ..., lon: ...}
,
or an instance of LatLontags
- an object with tags. Null values and undefined values are ignored. Any other value
is converted to a string. Leading and trailing white space in keys is removed.Name | Type | Description |
---|---|---|
id | number | (optional) a global node id. Optional. If missing and not set before using
withId(..) , creates a new local id. |
args | object | (optional) additional parameters for creating the node |
var nb = require("josm/builder").NodeBuilder
// create a new local node at position [0,0]
var n1 = nb.create();
// create a new global node at position [0,0]
var n2 = nb.create(12345);
// create a new global way with version 3 at a specific position and with some tags
var n3 = nb.create(12345, {version: 3, lat: 23.45, lon: 87.23, tags: {amenity: "restaurant"}});
createProxy:Node
Creates a new proxy Node. A proxy node is a node, for which we only know its global id. In order to know more details (position, 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.
Name | Type | Description |
---|---|---|
id | number | (mandatory) the node id (not null, number > 0 expected) |
var nbuilder = require("josm/builder").NodeBuilder;
// a new proxy node for the global node with id 12345
var n1 = nbuilder.createProxy(12345);
forDataSet:NodeBuilder
Creates a new NodeBuilder which will add created nodes to the dataset ds
.
Name | Type | Description |
---|---|---|
ds | DataSet | the dataset which created objects are added to |
var ds = new org.openstreetmap.josm.data.osm.DataSet();
var nb = require("josm/builder").NodeBuilder.forDataSet(ds);
withId
Declares the global node id and the global node version.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
id | number | (mandatory) the global node id. A number > 0. |
version | number | (optional) the global node version. If present, a number > 0. If missing, the version 1 is assumed. |
withPosition:NodeBuilder
Declares the node position.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
lat | Number | (mandatory) the latitude. A number in the range [-90..90]. |
lon | Number | (mandatory) the longitude. A number in the range [-180..180]. |
var nbuilder = require("josm/builder").NodeBuilder;
// a new global node with the global id 12345 at position (34,45)
var n1 = nbuilder.withPosition(34,45).create(12345);
// a new local node at position (23.2, 87.33)
var n2 = nbuilder.withPosition(23.3,87.33).create();
withTags:NodeBuilder
Declares the tags to be assigned to the new node.
The method can be used in a static and in an instance context.
Name | Type | Description |
---|---|---|
tags | object | (optional) the tags |
var nbuilder = require("josm/builder").NodeBuilder;
// a new global node with the global id 12345 and tags name=test and highway=road
var n1 = nbuilder.withTags({"name":"test", "highway":"road"}).global(12345);
// a new local node tags name=test and highway=road
var tags = {
"name" : "test",
"highway" : "road"
};
var n2 = nbuilder.withTags(tags).local();