- Timestamp:
- 2017-03-16T22:31:32+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r11658 r11735 8 8 import java.util.ArrayList; 9 9 import java.util.Collection; 10 import java.util.HashSet; 10 11 import java.util.Optional; 12 import java.util.Set; 11 13 import java.util.concurrent.Future; 12 14 import java.util.regex.Matcher; … … 19 21 import org.openstreetmap.josm.data.coor.LatLon; 20 22 import org.openstreetmap.josm.data.osm.DataSet; 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 import org.openstreetmap.josm.data.osm.Relation; 25 import org.openstreetmap.josm.data.osm.Way; 21 26 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 22 27 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 28 import org.openstreetmap.josm.gui.io.UpdatePrimitivesTask; 23 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 30 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; … … 272 278 if (layer == null) { 273 279 layer = Optional.ofNullable(getEditLayer()).orElseGet(this::getFirstDataLayer); 280 Collection<OsmPrimitive> primitivesToUpdate = searchPrimitivesToUpdate(bounds, layer.data); 274 281 layer.mergeFrom(dataSet); 275 282 if (zoomAfterDownload) { 276 283 computeBboxAndCenterScale(bounds); 277 284 } 285 if (!primitivesToUpdate.isEmpty()) { 286 Main.worker.submit(new UpdatePrimitivesTask(layer, primitivesToUpdate)); 287 } 278 288 layer.onPostDownloadFromServer(); 279 289 } 290 } 291 292 /** 293 * Look for primitives deleted on server (thus absent from downloaded data) 294 * but still present in existing data layer 295 * @param b download bounds 296 * @param ds existing data set 297 * @return the primitives to update 298 */ 299 private Collection<OsmPrimitive> searchPrimitivesToUpdate(Bounds b, DataSet ds) { 300 Collection<OsmPrimitive> col = new ArrayList<>(); 301 ds.searchNodes(b.toBBox()).stream().filter(n -> !n.isNew() && !dataSet.containsNode(n)).forEachOrdered(col::add); 302 if (!col.isEmpty()) { 303 Set<Way> ways = new HashSet<>(); 304 Set<Relation> rels = new HashSet<>(); 305 for (OsmPrimitive n : col) { 306 for (OsmPrimitive ref : n.getReferrers()) { 307 if (ref.isNew()) { 308 continue; 309 } else if (ref instanceof Way) { 310 ways.add((Way) ref); 311 } else if (ref instanceof Relation) { 312 rels.add((Relation) ref); 313 } 314 } 315 } 316 ways.stream().filter(w -> !dataSet.containsWay(w)).forEachOrdered(col::add); 317 rels.stream().filter(r -> !dataSet.containsRelation(r)).forEachOrdered(col::add); 318 } 319 return col; 280 320 } 281 321 }
Note:
See TracChangeset
for help on using the changeset viewer.