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. |
activeLayer:Layer
Set or get the active layer.
length:number
Replies the number of currently open layers.
add:Layer
Adds a layer.
Either pass in a layer object or a data set. In the later case, an OsmDataLayer is automatically created.
Name | Type | Description |
---|---|---|
obj | Layer|Layer | a layer to add, or a dataset. Ignored if null or undefined. |
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.
addDataLayer()
addDataLayer(ds)
addDataLayer(name)
name
addDataLayer({name: ..., ds: ...})
name
// 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.
key
is a number, replies the layer with index key, or
undefined, if no layer for this index exists.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.Name | Type | Description |
---|---|---|
key | number | the key to retrieve the layer |
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.
Name | Type | Description |
---|---|---|
layer | string | a layer, a layer name, or a layer index |
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.
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.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.Name | Type | Description |
---|---|---|
key | number | indicates the layer to remove |
var layers = require("josm/layers");
// remove the first layer
layers.remove(0);
// remove the first layer matching with the supplied name
layers.remove("myLayerName");