Skip to content

Commit

Permalink
Fix image navigation pane
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Apr 30, 2024
1 parent 869b318 commit 514b3e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ public ImageNavigation(final VectorDataSet dataset, final MapillaryNode node) {
final EastNorth nodeEn = node.getEastNorth();
final double travelAngle;
MapillarySequence seq = this.node.getSequence();
if (Objects.equals(this.node, seq.firstNode()) && seq.getNodes().size() > 1) {
travelAngle = Math.toDegrees(this.node.bearing(seq.getNode(1)));
} else if (Objects.equals(this.node, seq.lastNode()) && seq.getNodes().size() > 1) {
travelAngle = Math.toDegrees(seq.getNode(seq.getNodesCount() - 1).bearing(this.node));
} else {
int idx = seq.getNodes().indexOf(this.node);
if (seq.getNodes().size() <= 3) {
travelAngle = MapillaryImageUtils.getAngle(this.node);
if (seq != null) {
if (Objects.equals(this.node, seq.firstNode()) && seq.getNodes().size() > 1) {
travelAngle = Math.toDegrees(this.node.bearing(seq.getNode(1)));
} else if (Objects.equals(this.node, seq.lastNode()) && seq.getNodes().size() > 1) {
travelAngle = Math.toDegrees(seq.getNode(seq.getNodesCount() - 1).bearing(this.node));
} else {
travelAngle = Math.toDegrees(seq.getNode(idx - 1).bearing(seq.getNode(idx + 1)));
int idx = seq.getNodes().indexOf(this.node);
if (seq.getNodes().size() <= 3) {
travelAngle = MapillaryImageUtils.getAngle(this.node);
} else {
travelAngle = Math.toDegrees(seq.getNode(idx - 1).bearing(seq.getNode(idx + 1)));
}
}
} else {
travelAngle = Double.NaN;
}
this.originalSort = surroundingNodes.stream().map(n -> sort(isPano, false, angle, travelAngle, n, nodeEn))
.filter(Objects::nonNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.openstreetmap.josm.data.osm.BBox;
import org.openstreetmap.josm.data.osm.INode;
Expand Down Expand Up @@ -74,7 +73,7 @@ public List<MapillaryNode> getNodes() {

@Override
public List<Long> getNodeIds() {
return Arrays.stream(this.nodes).map(MapillaryNode::getId).collect(Collectors.toList());
return Arrays.stream(this.nodes).map(MapillaryNode::getId).toList();
}

@Override
Expand Down Expand Up @@ -124,8 +123,8 @@ public OsmPrimitiveType getType() {

@Override
public boolean equals(Object other) {
if (other instanceof IWay) {
return Objects.equals(MapillarySequenceUtils.getKey(this), MapillarySequenceUtils.getKey((IWay<?>) other));
if (other instanceof IWay<?> iway) {
return Objects.equals(MapillarySequenceUtils.getKey(this), MapillarySequenceUtils.getKey(iway));
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openstreetmap.josm.plugins.mapillary.data.mapillary.MapillaryNode;
import org.openstreetmap.josm.plugins.mapillary.gui.boilerplate.MapillaryButton;
import org.openstreetmap.josm.plugins.mapillary.gui.layer.MapillaryLayer;
import org.openstreetmap.josm.plugins.mapillary.gui.layer.geoimage.MapillaryImageEntry;
import org.openstreetmap.josm.tools.Shortcut;

/**
Expand Down Expand Up @@ -69,16 +70,15 @@ public class ImageNavigationDialog extends ToggleDialog
*/
public ImageNavigationDialog() {
super(tr("Mapillary: Image Navigation"), "mapillary-main", tr("Navigate between different Mapillary images"),
Shortcut.registerShortcut("mapillary:image_navigation", tr("Mapillary: Image Navigation"), KeyEvent.CHAR_UNDEFINED,
Shortcut.NONE),
Shortcut.registerShortcut("mapillary:image_navigation", tr("Mapillary: Image Navigation"),
KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
80);
MainApplication.getLayerManager().addAndFireLayerChangeListener(this);
}

@Override
public void layerAdded(LayerManager.LayerAddEvent e) {
if (e.getAddedLayer() instanceof MapillaryLayer) {
MapillaryLayer layer = (MapillaryLayer) e.getAddedLayer();
if (e.getAddedLayer() instanceof MapillaryLayer layer) {
layer.addImageChangeListener(this);
}
}
Expand All @@ -96,11 +96,18 @@ public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e) {
@Override
public void imageChanged(IGeoImageLayer source, List<? extends IImageEntry<?>> oldImages,
List<? extends IImageEntry<?>> newImages) {
if (source instanceof MapillaryLayer
&& newImages.stream().filter(MapillaryNode.class::isInstance).count() == 1) {
MapillaryLayer layer = (MapillaryLayer) source;
MapillaryNode node = (MapillaryNode) newImages.get(0);
if (node != null && layer.getData() != null && node.getSequence() != null) {
if (source instanceof MapillaryLayer layer
&& newImages.stream()
.filter(n -> n instanceof MapillaryNode
|| (n instanceof MapillaryImageEntry mie && mie.getImage() instanceof MapillaryNode))
.count() == 1) {
final MapillaryNode node;
if (newImages.get(0) instanceof MapillaryNode tNode) {
node = tNode;
} else {
node = (MapillaryNode) ((MapillaryImageEntry) newImages.get(0)).getImage();
}
if (node != null && layer.getData() != null) {
this.imageNavigation = new ImageNavigation(layer.getData(), node);
} else {
this.imageNavigation = null;
Expand Down Expand Up @@ -201,8 +208,8 @@ private static final class ImageAction extends JosmAction {
@Override
public void actionPerformed(ActionEvent e) {
MapillaryLayer layer = MapillaryLayer.getInstance();
if (this.toSelect instanceof MapillaryNode) {
layer.setCurrentImage((MapillaryNode) this.toSelect);
if (this.toSelect instanceof MapillaryNode node) {
layer.setCurrentImage(node);
} else {
layer.getData().setSelected(this.toSelect);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ public MapillaryImageEntry getLastImage() {

@Override
public void selectImage(ImageViewerDialog imageViewerDialog, IImageEntry<?> entry) {
IImageEntry.super.selectImage(imageViewerDialog, entry);
// If the image is a Mapillary image, we want to use our custom path *first*
if (entry instanceof MapillaryImageEntry mapillaryImageEntry) {
selectImage(mapillaryImageEntry);
}
IImageEntry.super.selectImage(imageViewerDialog, entry);
}

private static void selectImage(@Nullable final MapillaryImageEntry entry) {
Expand Down

0 comments on commit 514b3e7

Please sign in to comment.