Class: NodeBuilder

josm/builder/node~ NodeBuilder


new NodeBuilder( [ds])

NodeBuilder helps to create OSM nodes

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, to which created nodes are added.
Parameters:
Name Type Argument Description
ds DataSet <optional>
the dataset which created objects are added to
Source:
Example
import {NodeBuilder} from 'josm/builder'
const DataSet = Java.type('org.openstreetmap.josm.data.osm.DataSet')

const ds = new DataSet()
// create a node builder without and underlying dataset ...
let 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
const n1 = NodeBuilder.create()

// create a new global node at a specific position with tags
const n2 = NodeBuilder.withPosition(1,1).withTags({name: 'test'}).create(1)

// create a new proxy for a global node
// (an 'incomplete' node in JOSM terminology)
const n3 = NodeBuilder.createProxy(2)

Methods


create( [id] [, options])

Creates a new Node

Creates a new Node. Can be used in an instance or in a static context.
Parameters:
Name Type Argument Description
id number <optional>
a global node id. If missing and not set before using withId(..), creates a new local id.
options module:josm/builder/node~NodeBuilder.NodeBuilderOptions <optional>
additional options for creating the node
Source:
Returns:
the created node
Type
Node
Example
import { NodeBuilder } from 'josm/builder'
// create a new local node at position [0,0]
const n1 = NodeBuilder.create()

// create a new global node with id 1111 at position [0,0]
const n2 = NodeBuilder.create(1111)

// create a new global node with version 3 at a specific position
// and with some tags
const n3 = NodeBuilder.create(2222, {
    version: 3,
    lat: 23.45,
    lon: 87.23,
    tags: {amenity: 'restaurant'}
})

createProxy(id)

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.
Parameters:
Name Type Description
id number the node id (not null, number > 0 expected)
Source:
Returns:
the new proxy node
Type
Node
Example
import { NodeBuilder } from 'josm/builder'

// a new proxy node for the global node with id 1111
const n1 = NodeBuilder.createProxy(1111)

forDataSet(ds)

Creates a new NodeBuilder for a specific DataSet.

Creates or configures a NodeBuilder which will add created nodes to the dataset ds.
Parameters:
Name Type Description
ds DataSet the dataset which created objects are added to
Source:
Returns:
the node builder
Type
module:josm/builder/node~NodeBuilder
Example
import { NodeBuilder } from 'josm/builder'

 // create a new node builder building to a data set
 const DataSet = Java.type('org.openstreetmap.josm.data.osm.DataSet')
 const ds = new DataSet()

 // ... using a static method ...
 const nb1 = NodeBuilder.forDataSet(ds)
 // ... or the instance method
 const nb2 = new NodeBuilder.forDataSet(ds)

withId(id [, version])

Declares the global node id and the global node version. The method can be used in a static and in an instance context.
Parameters:
Name Type Argument Default Description
id number the global node id. A number > 0.
version number <optional>
1 optional the global node version. If present, a number > 0.
Source:
Returns:
the node builder (for method chaining)
Type
module:josm/builder/node~NodeBuilder

withPosition(lat, lon)

Declares the node position. The method can be used in a static and in an instance context.
Parameters:
Name Type Description
lat Number the latitude. A number in the range [-90..90].
lon Number the longitude. A number in the range [-180..180].
Source:
Returns:
a node builder (for method chaining)
Type
module:josm/builder/node~NodeBuilder
Example
import { NodeBuilder } from 'josm/builder'

// a new global node with the global id 1111 at position (34,45)
const n1 = NodeBuilder.withPosition(34,45).create(1111)

// a new local node at position (23.2, 87.33)
const n2 = NodeBuilder.withPosition(23.3,87.33).create()

withTags( [tags])

Declares the tags to be assigned to the new node. The method can be used in a static and in an instance context.
Parameters:
Name Type Argument Description
tags object <optional>
the tags
Source:
Returns:
the node builder (for method chaining)
Type
module:josm/builder/node~NodeBuilder
Example
import { NodeBuilder } from 'josm/builder'

// a new global node with the global id 1111 and tags name=test and
// highway=road
const n1 = NodeBuilder.withTags({'name':'test', 'highway':'road'}).create(1111)

// a new local node with tags name=test and highway=road
const tags = {
     'name'    : 'test',
     'highway' : 'road'
}
const n2 = NodeBuilder.withTags(tags).create()

Type Definitions


NodeBuilderOptions

Named options for {@link module:josm/builder/node~NodeBuilder#create create}
Properties:
Name Type Argument Default Description
version number <optional>
1 the version (> 0) of the node. Default: 1.
lat number <optional>
0.0 a valide latitude (number in the range [-90,90]. Default: 0.0
lon number <optional>
0.0 a valide longitude (number in the range[-180,180]. Default: 0.0
pos Array.<number> | Object <optional>
null a position, either an array with two numbers or as an object
tags object <optional>
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.
Source:
Example
// options to create a node at position (1.0, 2.0) with some tags
const options = {
  lat: 1.0,
  lon: 2.0,
  tags: {
    amenity: 'restaurant'
  }  
}