Module: josm/command

A collection of functions to create commands which can be applied, undone and redone on OsmDataLayers.
Source:

Example

import {
   buildAddCommand,
   buildChangeCommand,
   buildDeleteCommand
} from 'josm/command'

Classes

AddCommand
ChangeCommand
CommandHistory
Accessor to the global command history
DeleteCommand

Methods


<static> buildAddCommand(obj)

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.
Parameters:
Name Type Argument Description
obj OsmPrimitive | OsmPrimitive[] | Collection <repeatable>
the primitives to add
Source:
Returns:
the command object
Type
module:josm/command.AddCommand
Example
import {buildAddCommand} from 'josm/command'
import layers from 'josm/layer'
import {NodeBuilder} from 'josm/builder'
const layer  = layers.get('Data Layer 1')

// add two nodes
buildAddCommand(
  NodeBuilder.create(), 
  NodeBuilder.create()
).applyTo(layer)

<static> buildChangeCommand(objs, change)

Creates a command to change a collection of objects in a data layer. The mandatory last argument is an object with named parameters.
Parameters:
Name Type Argument Description
objs OsmPrimitive | OsmPrimitive[] | Collection <repeatable>
the objects to change. See documentation.
change module:josm/command~ChangeSpec the change specification
Source:
Returns:
the change command object
Type
module:josm/command.ChangeCommand
Example
import {buildChangeCommand} from 'josm/command'
import layers from 'josm/layers'
const layer = layers.get("Data Layer 1")

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

// change the tags of a collection of primitives
buildChangeCommand(n1, n3, w1, r1, {
   tags: {'mycustomtag': 'value'}
}).applyTo(layer)

<static> buildDeleteCommand(obj)

Creates a command to delete a collection of objects in a data layer.
Parameters:
Name Type Argument Description
obj OsmPrimitive | OsmPrimitive[] | Collection <repeatable>
the primitives to delete
Source:
Returns:
the command object
Type
module:josm/command.DeleteCommand
Example
import {buildDeleteCommand} from 'josm/command'
import layers from 'josm/layer'
import {NodeBuilder} from 'josm/builder'
const layer = layers.get('Data Layer 1')
// delete two nodes
buildDeleteCommand(NodeBuilder.create(),NodeBuilder.create()).applyTo(layer)
*

<static> combineSelectedWays()

Combines the currently selected ways.

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.
Source:
Example
import {combineSelectedWays} from 'josm/command'
import layers from 'josm/layer'
const ds = layers.activeLayer.data
combineSelectedWays(ways)

<static> combineWays(ways, ways)

Combines two or more ways into one resulting way.

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
ways Way | array the ways to be combined
Source:
Example
import {combineWays} from 'josm/command'
import layers from 'josm/layer'
const ds = layers.activeLayer.data
const ways  = [ds.way(1), ds.way(2), ds.way(3)]

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

Type Definitions


ChangeSpec

The change specification for a change command.
Type:
  • Object
Properties:
Name Type Description
lat number if present and applied to a node, changes the nodes latitude
lon number if present and applied to a node, changes the nodes longitude
pos LatLon | module:josm/command~LatLonSpec if present and applied to a node, changes the nodes position
tags Map | object if present, changes the tags of the target object
nodes List | OsmPrimitive[] if present and applied to a way, changes the ways nodes
nodes List | RelationMember[] if present and applied to a relation, changes the relations members
Source:
Example
// change the positon of a node 
const changeSpec1 = {
   lat: 1.0,
   lon: 2.0
}

// change the tags of one or more primitives
const changeSpec2 = {
   tags: {
      amentity: 'restaurant' 
   }
}

LatLonSpec

A lat/lon position as a JavaScript object.
Type:
  • Object
Properties:
Name Type Description
lat number the latitude of the position
lon number the longitude of the position
Source:
Example
const latLonSpec = {
 lat: 1.0,
 lon: 1.0
}