Skip to content

Commit

Permalink
Merged in MAPDATA-5298-improve_loading_workflow (pull request #44)
Browse files Browse the repository at this point in the history
MAPDATA-5298 improve loading workflow

Approved-by: Laura Dumitru
  • Loading branch information
nicoleta-viregan-grab committed Oct 16, 2020
2 parents 0382f3b + 59f71d9 commit 6fd4f81
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/org/openstreetmap/josm/plugins/openstreetcam/DataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
import org.openstreetmap.josm.data.osm.Way;
Expand Down Expand Up @@ -185,7 +186,7 @@ public synchronized void updateHighZoomLevelClusterData(final List<Cluster> clus
*/
public synchronized void updateHighZoomLevelPhotoData(final PhotoDataSet photoDataSet,
final boolean updateSelection) {
this.photoDataSet = photoDataSet;
revalidatePhotosToBeDrawn(photoDataSet);
if (updateSelection && hasSelectedPhoto() && !selectedPhotoBelongsToSelectedCluster()) {
selectedPhoto = photoDataSet != null ? photoDataSet.getPhotos().stream()
.filter(photo -> photo.equals(selectedPhoto)).findFirst().orElse(null) : null;
Expand All @@ -200,6 +201,36 @@ public synchronized void updateHighZoomLevelPhotoData(final PhotoDataSet photoDa
}
}

/**
* Eliminates the photos which are not in the active area and adds to the PhotoDataSet the photos which are not
* represented in the map.
*
* @param currentPhotoDataSet - the photos to be added in the map after an action
*/
private void revalidatePhotosToBeDrawn(final PhotoDataSet currentPhotoDataSet) {
List<Photo> photosToBeDrawn = new ArrayList<>();
if (currentPhotoDataSet != null && currentPhotoDataSet.getPhotos() != null) {
for (final Photo photo : currentPhotoDataSet.getPhotos()) {
if (!isPhotoDrawn(photo, this.photoDataSet)) {
photosToBeDrawn.add(photo);
}
}
}
final List<Photo> photosOutOfArea =
this.photoDataSet.getPhotos().stream().filter(photo -> !Util.isPointInActiveArea(photo.getPoint()))
.collect(Collectors.toList());
this.photoDataSet.removePhotos(photosOutOfArea);
this.photoDataSet.addPhotos(photosToBeDrawn);
}

private boolean isPhotoDrawn(final Photo photo, final PhotoDataSet previousPhotoDataSet) {
boolean isDrawn = false;
if (photo != null && previousPhotoDataSet != null && previousPhotoDataSet.hasItems()) {
isDrawn = previousPhotoDataSet.getPhotos().contains(photo);
}
return isDrawn;
}

/**
* Returns the photo that is located near to the given point. The method returns null if there is no nearby item.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public List<Photo> getPhotos() {
return photos;
}


public Integer getPage() {
return page;
}
Expand All @@ -68,4 +67,10 @@ public void addPhotos(final List<Photo> photos) {
this.photos.addAll(photos);
}
}

public void removePhotos(final List<Photo> photos) {
if (photos != null && !photos.isEmpty()) {
this.photos.removeAll(photos);
}
}
}

0 comments on commit 6fd4f81

Please sign in to comment.