Working with layers
The global object josm.layers
represents the current layers in josm. The methods and properties of this object are defined in the module josm/layers.
The following scripts prints the names of the currently opened layers:
import josm from 'josm'
import * as console from 'josm/scriptingconsole'
const numLayers = josm.layers.length
for (let i=0; i < numLayers; i++) {
console.println(`Layer ${i}: name = '${josm.layers.get(i)}'`)
}
Working with data layers
Data layers are instances of the JOSM native class OsmDataLayer. You can open a file with OSM data in a new data layer with the method josm.open()
:
import josm from 'josm'
// 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 particular for a dataset which has been downloaded from the central OSM server.
import josm from 'josm'
import {Api} from 'josm/api'
const dataset = Api.downloadArea({
min: {lat: 46.9479186, lon: 7.4619484},
max: {lat: 46.9497642, lon: 7.4660683}
})
josm.layers.addDataLayer({ds: dataset, name: 'Obstberg'})