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 |
add
Creates a command to add a collection of objects to a data layer.
Signaturesadd(obj, obj, ...) obj are Nodes,
Ways, or
Relationss. Or javascript array
or Java collections thereof.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.
Signatureschange(obj,obj,..., options) obj are Nodes,
Ways, or
Relationss. Or javascript array
or Java collections thereof.lat:numberlat.lon:numberlon.pos:LatLon|objectpos. pos is either a
LatLon or an object {lat:..., lon:...}
tags:Map|objecttags.nodes:List|arraynodes.members:List|arraymembers.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
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.
| Name | Type | Description |
|---|---|---|
| ways | the ways to be combined |
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.
Signaturesdelete(obj,obj,..., ?options) obj are Nodes,
Ways, or
Relationss. Or javascript array
or Java collections thereof.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])
);