6
6
import java .util .Collections ;
7
7
import java .util .Map ;
8
8
import java .util .Objects ;
9
+ import java .util .Optional ;
9
10
import java .util .stream .Collectors ;
10
11
11
12
import javax .annotation .Nonnull ;
22
23
import org .openstreetmap .josm .data .osm .TagMap ;
23
24
import org .openstreetmap .josm .data .vector .VectorDataSet ;
24
25
import org .openstreetmap .josm .data .vector .VectorNode ;
26
+ import org .openstreetmap .josm .gui .MainApplication ;
27
+ import org .openstreetmap .josm .gui .layer .geoimage .ImageViewerDialog ;
25
28
import org .openstreetmap .josm .plugins .mapillary .gui .layer .MapillaryLayer ;
29
+ import org .openstreetmap .josm .plugins .mapillary .gui .layer .geoimage .MapillaryImageEntry ;
26
30
import org .openstreetmap .josm .plugins .mapillary .model .ImageDetection ;
27
31
import org .openstreetmap .josm .plugins .mapillary .utils .MapillaryImageUtils ;
28
32
import org .openstreetmap .josm .plugins .mapillary .utils .MapillaryKeys ;
@@ -94,11 +98,7 @@ private static Pair<String, VectorNode> decodeImageInfo(@Nullable final JsonObje
94
98
return null ;
95
99
}
96
100
final long id = Long .parseLong (key );
97
- final LatLon coordinates = JsonDecoder .decodeLatLon (json .getJsonObject (
98
- useComputedData && json .containsKey (MapillaryImageUtils .ImageProperties .COMPUTED_GEOMETRY .toString ())
99
- ? MapillaryImageUtils .ImageProperties .COMPUTED_GEOMETRY .toString ()
100
- : MapillaryImageUtils .ImageProperties .GEOMETRY .toString ())
101
- .getJsonArray ("coordinates" ));
101
+ final LatLon coordinates = getCoordinates (json , useComputedData );
102
102
final BBox searchBBox = new BBox (coordinates );
103
103
searchBBox .addLatLon (coordinates , 0.001 );
104
104
VectorNode image = VectorDataSetUtils .tryRead (data , () -> data .getPrimitiveById (id , OsmPrimitiveType .NODE ))
@@ -110,6 +110,21 @@ private static Pair<String, VectorNode> decodeImageInfo(@Nullable final JsonObje
110
110
111
111
if (coordinates != null ) {
112
112
image .setCoor (coordinates );
113
+ // Force the dataset to recache the location
114
+ VectorDataSetUtils .tryWrite (data , () -> {
115
+ if (data .containsNode (image )) {
116
+ data .removePrimitive (image );
117
+ }
118
+ data .addPrimitive (image );
119
+ if (Optional .ofNullable (MainApplication .getMap ())
120
+ .map (map -> map .getToggleDialog (ImageViewerDialog .class )).isPresent ()
121
+ && ImageViewerDialog .getCurrentImage () instanceof MapillaryImageEntry ) {
122
+ MapillaryImageEntry entry = (MapillaryImageEntry ) ImageViewerDialog .getCurrentImage ();
123
+ if (coordinates .equals (entry .getPos ())) {
124
+ entry .reload ();
125
+ }
126
+ }
127
+ });
113
128
}
114
129
for (Map .Entry <String , String > entry : JsonTagMapDecoder .getTagMap (json ).entrySet ()) {
115
130
image .put (entry .getKey (), entry .getValue ());
@@ -139,6 +154,22 @@ private static Pair<String, VectorNode> decodeImageInfo(@Nullable final JsonObje
139
154
return null ;
140
155
}
141
156
157
+ private static LatLon getCoordinates (JsonObject json , boolean useComputedData ) {
158
+ final LatLon originalCoordinates = JsonDecoder .decodeLatLon (
159
+ json .getJsonObject (MapillaryImageUtils .ImageProperties .GEOMETRY .toString ()).getJsonArray ("coordinates" ));
160
+ if (useComputedData && json .containsKey (MapillaryImageUtils .ImageProperties .COMPUTED_GEOMETRY .toString ())) {
161
+ final LatLon computedCoordinates = JsonDecoder
162
+ .decodeLatLon (json .getJsonObject (MapillaryImageUtils .ImageProperties .COMPUTED_GEOMETRY .toString ())
163
+ .getJsonArray ("coordinates" ));
164
+ if (computedCoordinates != null && originalCoordinates != null && computedCoordinates
165
+ .greatCircleDistance (originalCoordinates ) < MapillaryProperties .ASSUMED_HDOP .get ()) {
166
+ return computedCoordinates ;
167
+ }
168
+ return Utils .firstNonNull (originalCoordinates , computedCoordinates );
169
+ }
170
+ return originalCoordinates ;
171
+ }
172
+
142
173
/**
143
174
* Create a new image from a json
144
175
*
0 commit comments