OsmPrimitiveMixin provides additional properties and methods which you can invoke on an instance of OsmPrimitive.
Name | Description |
---|---|
Properties | |
changesetId | et or get the changeset id this primitive was last modified in. |
dataSet | Replies the parent dataset. |
id | The unique numeric id |
isDeleted, deleted | Set or get wheter this primitive is deleted. |
isGlobal, global | Replies true, if this is a global primitive |
isIncomplete, isProxy, incomplete, proxy | Replies true if this is a proxy object |
isLocal, local, isNew | Replies true, if this is a local primitive. |
isNode | Replies true if this object is a node |
isRelation | Replies true if this object is a relation |
isWay | Replies true if this object is a way |
keys | Replies an array with the tag keys. |
tags | Get or set the tags of the object. |
timestamp | Get the timestamp this primitive was last modified on the server. |
user | Set or get the user. |
version | The version of the object. |
Methods | |
get | Replies the value of a tag. |
has | Checks whether a primitive has a tag. |
remove | Removes a tag. |
set | Set a tag or a collection of tags. |
This mixin provides additional properties and methods for the native Java class
OsmPrimitive, whose native public methods are available
for scripting, too. If a native method name is hidden by a property name in the mixin,
then prefix the native name with $
.
changesetId:number
Set or get the changeset id this primitive was last modified in.
get: - replies the changeset id or undefined, if no changeset id is known (i.e. for local primitives or proxy primitives).
set: - assign a changset id, a number >, 0.
var nb = require("josm/builder").NodeBuilder.forDataSet(ds);
var n1 = nb.create(12345);
// assign the changeset id
n1.changesetId = 6;
dataSet:DataSet
Replies the parent dataset or undefined, if this primitive is not attached to a dataset.
var ds = new DataSet();
var nb = require("josm/builder").NodeBuilder.forDataSet(ds);
// get members
var n1 = nb.create();
n1.dataSet; // -> ds
var nb = require("josm/builder").NodeBuilder;
var n2 = nb.create();
n2.dataSet; // -> undefined
id:number
The unique numeric id, positive for global primitives, negative for local primitives.
var nb = require("josm/builder").NodeBuilder;
// get members
var node = nb.create();
var id = node.id; // -> a negative value
isDeleted:boolean | Aliases: deleted
Set or get wheter this primitive is deleted.
In order to invoke the native method isDeleted()
, prefix the name
with $, i.e.
node.$isDeleted(); // -> same as node.isDeleted without parantheses
isGlobal:boolean | Aliases: global
Replies true, if this is a global primitive
var nb = require("josm/builder").NodeBuilder;
// get members
var node = nb.create();
node.isGlobal; // -> false
node = nb.create(1234);
node.isGlobal; // -> true
isIncomplete:boolean | Aliases: isProxy, incomplete, proxy
Replies true if this a proxy object, in JOSM terminology called an incomplete object.
isLocal:boolean | Aliases: local, isNew
Replies true, if this is a local primitive.
var nb = require("josm/builder").NodeBuilder;
// get members
var node = nb.create();
node.isLocal; // -> true
node = nb.create(1234);
node.isLocal; // -> false
isNode:boolean
Replies true if this object is a node
isRelation:boolean
Replies true if this object is a relation
isWay:boolean
Replies true if this object is a way
keys:array
Replies an array with the tag keys.
var node = .... // create a node
// get the tag keys
var keys = node.keys;
Get or set the tags of the object.
get: - replies the tags as javascript object.
set:
null values and undefined tag values aren't assigned. tag keys are normalized, i.e. leading and trailing white space is removed. Both, tag keys and tag values, are converted to strings.
var node = .... // create a node
// set the tags using a javascript object
node.tags = {amenity:"restaurant", name:"Obstberg"};
node.tags.amenity; // -> restaurant
node.tags.name; // -> Obstberg
// remove all tags
node.tags = null;
// set tags using a java map
var tags = new java.util.HashMap();
tags.put("amenity", "restaurant");
tags.put("name", "Obstberg");
node.tags = tags;
timestamp:Date
Get the timestamp this primitive was last modified on the server. Undefined, if this timestamp isn't known, i.e. for local primitives or for proxy primitives.
var nb = require("josm/builder").NodeBuilder.forDataSet(ds);
var n1 = ... // assume n1 was downloaded from the server
n1.timestamp; // the timestamp of last modification
user:DataSet
Set or get the user.
get: - replies a User object or undefined, if not user is set.
set: - assign a user, either as instance of User, supplying a user name or the unique global user id as number. Assign null or undefined to assign no user.
var User = org.openstreetmap.josm.data.osm.User;
var nb = require("josm/builder").NodeBuilder.forDataSet(ds);
var n1 = nb.create();
// assign a user object
n1.user = new User("foobar");
// assign the unique global user with name 'foobar'
n1.user = "foobar";
// assign the unique global user with id 12345
n1.user = 12345;
version:number
The version of the object.
Only global objects have a version. The version for local and proxy objects is undefined.
var nb = require("josm/builder").NodeBuilder;
// local object - get version is undefined
var node = nb.create();
node.version; // -> undefined
// global object - get version is defined
var node = nb.create(12345, {version: 9});
node.version; // -> 9
// proxy object - get version is undefined
var node = nb.createProxy(12345);
node.version; // -> undefined
get:string
Replies the value of a tag, or undefined, if the tag isn't set.
Name | Type | Description |
---|---|---|
name | string | the tag name. Must not be null or undefined. Non-string values are converted to a string. Leading and trailing whitespace is removed. |
var node = .... // create a node
// set the tags using a javascript object
node.tags = {amenity:"restaurant", name:"Obstberg"};
node.get("amenity"); // -> restaurant
node.get("name"); // -> Obstberg
has:boolean
Replies true, if the object has a tag with key key.
SignaturesName | Type | Description |
---|---|---|
key | string | the tag key. Must not be null or undefined. Non-string values are converted to a string. Leading and trailing whitespace is removed. |
var node = .... // create a node
// set the tags using a javascript object
node.tags = {amenity:"restaurant", name:"Obstberg"};
// test wheter the tags are set
node.has("amenity"); // -> true
node.has("no-such-tag"); // -> false
// use a regexp
node.has(/^a/); // -> true
node.has(/^name(:.*)?$/i); // -> false
remove:boolean
Removes a tag.
Name | Type | Description |
---|---|---|
name | string | the tag name. Must not be null or undefined. Non-string values are converted to a string. Leading and trailing whitespace is removed. |
var node = .... // create a node
// set the tags using a javascript object
node.tags = {amenity:"restaurant", name:"Obstberg"};
node.remove("amenity");
node.has("amenity"); // -> false
set:string
Set a tag or a collection of tags.
Signatures
var node = .... // create a node
// set the tags using a javascript object
node.set("amenity", "restaurant");
node.set("name", "obstberg");
node.get("amenity"); // -> restaurant
node.get("name"); // -> Obstberg
// set the tags using an object
node.set({amenity:"restaurant", name: "Obstberg"});
node.get("amenity"); // -> restaurant
node.get("name"); // -> Obstberg