The global object josm.layers
represents the current layers in josm. The methods
and properties of this object are defined in the module layers.
The following scripts prints the names of the currently opened layers:
var util = require("josm/util");
var l = josm.layers.length;
for (var i=0; i<l; i++) {
util.println("Layer {0}: name is ''{1}''", i, josm.layers.get(i));
}
Data layers are instances of the JOSM native class OsmDataLayer. The Javascript mixin OsmDataLayerMixin provides additional methods and properties for instances of a data layer.
You can open a file with OSM data in a new data layer with the method
josm.open()
:
// Opens a new data layer for this file
josm.open("/my/data/file.osm");
Alternatively, you can create a data layer for a dataset, in particual for a dataset
which has been downloaded from the central OSM server.
var api = require("josm/api").Api;
var dataset = api.downloadArea({
min: {lat: 46.9479186, lon: 7.4619484},
max: {lat: 46.9497642, lon: 7.4660683}
});
josm.layers.addDataLayer({ds: dataset, name: "Obstberg"});