Class WayBuilder

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.

Constructor

new WayBuilder()

Creates a new builder for OSM ways

Parameters

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.

Functions

create:Way

Creates a new way.

Can be used in an instance or in a static context.

Optional named arguments in the parameters options:
id:number
the id of a global way (number > 0)
version:number
the version of a global way (number > 0)
nodes:array|list
an array or a list of nodes
tags:object
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.

Parameters

Name 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

Examples

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.

Examples

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.

Examples

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.

Parameters

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.

Examples

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.

Parameters

Name Type Description
nodes the list of nodes. See description and examples.

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.

Parameters

Name Type Description
tags object (optional) the tags

Examples

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();