Module josm/layers

Provides access to the JOSM layers.

Name Description
Properties
activeLayer Set or get the active layer.
length Replies the number of currently open layers.
Methods
add Adds a layer.
addDataLayer Adds a data layer
get Replies one of the layers given a key.
has Checks whether layer is currently registered layer.
remove Removes a layer.

Properties

activeLayer:Layer

Set or get the active layer.

get
Replies the active layer or undefined.
set
Assign either an existing Layer , the name of a layer as string, or a layer index as number.

length:number

Replies the number of currently open layers.

Functions

add:Layer

Adds a layer.

Either pass in a layer object or a data set. In the later case, an OsmDataLayer is automatically created.

Parameters

Name Type Description
obj Layer|Layer a layer to add, or a dataset. Ignored if null or undefined.

Examples

var layers = require("josm/layers");
var OsmDataLayer = org.openstreetmap.josm.gui.layer.OsmDataLayer;	
var DataSet = org.openstreetmap.josm.data.osm.DataSet;

var dataLayer = new OsmDataLayer(new DataSet(), null, null);
// add a layer ...
layers.add(dataLayer);

// or add a dataset, which will create a data layer
var ds = new DataSet();
layer.add(ds); 

addDataLayer:OsmDataLayer

Creates and adds a new data layer. The new layer becomes the new edit layer.

Signatures
addDataLayer()
create data layer with a new dataset and default name
addDataLayer(ds)
create data layer with dataset ds and default name
addDataLayer(name)
create data layer with a new dataset and name name
addDataLayer({name: ..., ds: ...})
create data layer with a new dataset and name name

Examples

// creates a new data layer 
var layer = josm.layers.addDataLayer();

// creates a new data layer with name 'test'
layer = josm.layers.addDataLayer("test");

// creates a new data layer for the dataset ds
var ds = new DataSet();
layer = josm.layers.addDataLayer(ds);

get

Replies one of the layers given a key.

  • If key is a number, replies the layer with index key, or undefined, if no layer for this index exists.
  • If key is a string, replies the first layer whose name is identical to key ( case insensitive, without leading/trailing whitespace), or undefined, if no layer with such a name exists.

Parameters

Name Type Description
key number the key to retrieve the layer

Examples

var layers = require("josm/layers");

// get the first layer  
var layer1  = layers.get(0);

// get the first layer with name "data layer"
var layer2 = layers.get("data layer"); 

has:boolean

Checks whether layer is a currently registered layer.

Parameters

Name Type Description
layer string a layer, a layer name, or a layer index

Examples

var layers = require("josm/layers");

// is there a layer with name "my layer"? 
var b = layers.has("my layer");

// is there a layer at index position 2
b = layers.has(2);

// is there a specific layer? 
var l = layers.get(0); 
b = layers.has(l);

remove

Removes a layer with the given key.

  • If key is a Number, removes the layer with the index key. If the index doesn't isn't a valid layer index, nothing is removed.
  • If key is a string, removes the layer with the name key. Leading and trailing white space is removed, matching is a case-insensitive sub-string match.

Parameters

Name Type Description
key number indicates the layer to remove

Examples

var layers = require("josm/layers");

// remove the first layer 
layers.remove(0);

// remove the first layer matching with the supplied name
layers.remove("myLayerName");