Module josm/command

A collection of functions to create commands which can be applied, undone and redone on org.opoenstreetmap.josm.gui.layer.OsmDataLayers.

This module provides the following classes:

Name Description
Methods
add Creates a command to add a collection of objects
change Creates a command to change a collection of objects
combineSelectedWays Combines the currently selected ways.
combineWays Combines two or more ways into one resulting way.
delete Creates a command to delete a collection of objects

Functions

add

Creates a command to add a collection of objects to a data layer.

Signatures
add(obj, obj, ...)
obj are Nodes, Ways, or Relationss. Or javascript array or Java collections thereof.

Examples

var cmd = require("josm/command");
var layers = require("josm/layer");
var layer  = layers.get("Data Layer 1");

// add two nodes 
cmd.add(n1,n1).applyTo(layer);

// add an array of two nodes and a way  
layer.apply(
   cmd.add([n1,n2,w2])
);

change

Creates a command to change a collection of objects in a data layer.

Signatures
change(obj,obj,..., options)
obj are Nodes, Ways, or Relationss. Or javascript array or Java collections thereof.
The mandatory last argument is an object with named parameters. It accepts the following named parameters:
lat:number
Changes the latitude of the target nodes to lat.
lon:number
Changes the longitude of the target nodes to lon.
pos:LatLon|object
Changes the position of the target nodes to pos. pos is either a LatLon or an object {lat:..., lon:...}
tags:Map|object
Changes the tags of the target objects to tags.
nodes:List|array
Changes the nodes of the target way sto nodes.
members:List|array
Changes the nodes of the target relations to members.

Examples

var cmd = require("josm/command");
var layers = require("josm/layer");
var layer = layers.get("Data Layer 1");

// change the position of a node  
cmd.change(n1,n1, {lat: 123.45, lon: 44.234}).applyTo(layer);

// change the nodes of a way 
layer.apply(
   cmd.change(w2, {nodes: [n1,n2,3]})
);

// change the tags of a collection of primitives
cmd.change(n1,n3, w1,r1, {
   tags: {"mycustommtag": "value"}
}).applyTo(layer);

combineSelectedWays

Combines the currently selected ways in the active layer into one resulting way. Returns without effect if

  • there is no active layer
  • the active layer is not a data layer
  • there are less than two selected ways in the active layer
Reuses the logic behind the JOSM standard menu entry Tools->Combine Ways. If invoked from a script, this may trigger modal dialogs which are presented to the user, in particular if the direction of the ways has to be reversed because otherwise they could not be combined.

Examples

var cmd = require("josm/command");
var layers = require("josm/layer");
var ds = layers.activeLayer.data; 
var ways  = [ds.way(1), ds.way(2), ds.way(3)];
cmd.combineWays(ways);

combineWays

Combines two or more ways into one resulting way. Reuses the logic behind the JOSM standard menu entry Tools->Combine Ways. If invoked from a script, this may trigger modal dialogs which are presented to the user, in particular if the direction of the ways has to be reversed because otherwise they could not be combined.

Parameters

Name Type Description
ways the ways to be combined

Examples

var cmd = require("josm/command");
var layers = require("josm/layer");
var ds = layers.activeLayer.data; 
var ways  = [ds.way(1), ds.way(2), ds.way(3)];

// pass in an array ...
cmd.combineWays(ways);
// ... or the individual ways ...
cmd.combineWays(ds.way(1), ds.way(2), ds.way(3));
// ... or any combination thereof. 

delete

Creates a command to delete a collection of objects in a data layer.

Signatures
delete(obj,obj,..., ?options)
obj are Nodes, Ways, or Relationss. Or javascript array or Java collections thereof.

Examples

var cmd = require("josm/command");
var layers= require("josm/layer");
var layer = layers.get("Data Layer 1");

// delete two nodes 
cmd.delete(n1,n1).applyTo(layer);

// delete an array of two nodes and a way  
layer.apply(
   cmd.delete([n1,n2,w2])
);