Gubaer / josm-scripting-plugin

Task automation in the OpenStreetMap editor JOSM
https://gubaer.github.io/josm-scripting-plugin
GNU General Public License v3.0
26 stars 9 forks source link

Combining multiple Api.downloadObject results into one layer (class jdk.proxy2.$Proxy34 cannot be cast to class org.openstreetmap.josm.data.osm.OsmPrimitive) #102

Closed arminus closed 1 year ago

arminus commented 1 year ago

Starting with the simple working example:

let ds = Api.downloadObject(12345, 'way', {full: true});
let l = josm.layers.addDataLayer({ds: ds, name: 'myways'});

How do I add additional ways as retrieved by consecutive Api.downloadObject calls to the existing layer? The following approach doesn't work:

let ds2 = Api.downloadObject(67890, 'way', {full: true});
ds.addPrimitive(ds2.getNodes());
ds.addPrimitive(ds2.getWays());

causes a

class jdk.proxy2.$Proxy34 cannot be cast to class org.openstreetmap.josm.data.osm.OsmPrimitive (jdk.proxy2.$Proxy34 is in module jdk.proxy2 of loader 'app'; org.openstreetmap.josm.data.osm.OsmPrimitive is in unnamed module of loader 'app')

pl71 commented 1 year ago

You can try merging ds:

const DataSetMerger = Java.type('org.openstreetmap.josm.data.osm.DataSetMerger');

let ds1 = Api.downloadObject(840103836, 'way', {full: true});
let l = josm.layers.addDataLayer({ds: ds1, name: 'myways'});

let ds2 = Api.downloadObject(25689829, 'way', {full: true});
ds1 = new DataSetMerger(ds1, ds2);
ds1.merge();
arminus commented 1 year ago

Great, that works, thanks a lot!