Skip to content

Commit be4dc55

Browse files
committed
Mapillary (website) no longer zooms in to images
This adds lat, lng, and z params to the URL opened in the browser. It also fixes some documentation issues. Signed-off-by: Taylor Smock <tsmock@meta.com>
1 parent 72cff86 commit be4dc55

File tree

18 files changed

+116
-55
lines changed

18 files changed

+116
-55
lines changed

src/main/java/org/openstreetmap/josm/plugins/mapillary/cache/CacheUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static void downloadPicture(INode img, MapillaryCache.Type type) {
6262
* The picture to be requested.
6363
* @param lis
6464
* The listener that is going to receive the picture.
65+
* @param type The image type
6566
*/
6667
public static void submit(INode image, MapillaryCache.Type type, ICachedLoaderListener lis) {
6768
submit(image, type, true, lis);
@@ -75,6 +76,8 @@ public static void submit(INode image, MapillaryCache.Type type, ICachedLoaderLi
7576
* The picture to be requested.
7677
* @param lis
7778
* The listener that is going to receive the picture.
79+
* @param type The image type to get
80+
* @param removeCurrent {@code true} if any outstanding tasks should be canceled
7881
*/
7982
public static void submit(INode image, MapillaryCache.Type type, boolean removeCurrent, ICachedLoaderListener lis) {
8083
try {

src/main/java/org/openstreetmap/josm/plugins/mapillary/cache/Caches.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public V get(@Nonnull String url) {
194194
* This is non-blocking.
195195
*
196196
* @param url The URL to get
197+
* @param pool The worker pool
197198
* @return The information
198199
*/
199200
@Nullable

src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/MapillaryFilterModel.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// License: GPL. For details, see LICENSE file.
22
package org.openstreetmap.josm.plugins.mapillary.data.mapillary;
33

4-
import javax.annotation.Nullable;
54
import java.util.Collection;
65
import java.util.Collections;
76
import java.util.Set;
87
import java.util.concurrent.locks.Lock;
98
import java.util.stream.Collectors;
109

10+
import javax.annotation.Nullable;
11+
1112
import org.openstreetmap.josm.data.osm.DataSet;
1213
import org.openstreetmap.josm.data.osm.Filter;
1314
import org.openstreetmap.josm.data.osm.FilterMatcher;
@@ -39,6 +40,7 @@ public void executeFilters() {
3940
/**
4041
* Runs the filters on a data set
4142
*
43+
* @param <O> The base primitive type of the dataset
4244
* @param ds The dataset to run filters on
4345
*/
4446
public <O extends IPrimitive & IFilterablePrimitive> void executeFilters(OsmData<O, ?, ?, ?> ds) {
@@ -62,6 +64,7 @@ public void executeFilters(@Nullable Collection<? extends OsmPrimitive> primitiv
6264
*
6365
* @param ds The dataset with the primitives
6466
* @param primitives The primitives
67+
* @param <O> The base primitive type for the dataset
6568
*/
6669
public <O extends IPrimitive & IFilterablePrimitive> void executeFilters(@Nullable OsmData<O, ?, ?, ?> ds,
6770
@Nullable Collection<? extends O> primitives) {

src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/ObjectDetections.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public final class ObjectDetections {
7676
/**
7777
* Create an ObjectDetection
7878
*
79+
* @param key The key for the detection
7980
* @param tagMap The OSM key(s) for the object
8081
* @param taggingPresetType The valid types for the preset
8182
* @param additionalCommands Additional commands to run

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/ImageCheckBoxButton.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public boolean isFiltered(String searchString) {
179179
* Set the box as selected
180180
*
181181
* @param selected Set the checkbox state to the selected boolean
182-
* @return A future to indicate if the call finished
183182
*/
184183
public void setSelected(boolean selected) {
185184
GuiHelper.runInEDT(() -> {

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.awt.GridBagConstraints;
77
import java.awt.GridBagLayout;
88
import java.awt.event.ActionEvent;
9-
import java.net.URISyntaxException;
109

1110
import javax.swing.AbstractAction;
1211
import javax.swing.BorderFactory;
@@ -41,7 +40,6 @@
4140
import org.openstreetmap.josm.tools.GBC;
4241
import org.openstreetmap.josm.tools.I18n;
4342
import org.openstreetmap.josm.tools.ImageProvider;
44-
import org.openstreetmap.josm.tools.Logging;
4543
import org.openstreetmap.josm.tools.OpenBrowser;
4644

4745
/**
@@ -272,12 +270,8 @@ private static class LoginAction extends AbstractAction {
272270
public void actionPerformed(ActionEvent arg0) {
273271
OAuthPortListener portListener = new OAuthPortListener(callback);
274272
portListener.start();
275-
try {
276-
OpenBrowser.displayUrl(
277-
MapillaryConfig.getUrls().connect("http://localhost:" + OAuthPortListener.PORT + '/').toURI());
278-
} catch (URISyntaxException e) {
279-
Logging.error(e);
280-
}
273+
OpenBrowser
274+
.displayUrl(MapillaryConfig.getUrls().connect("http://localhost:" + OAuthPortListener.PORT + '/'));
281275
}
282276
}
283277

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/dialog/MapillaryFilterTableModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public void executeFilters() {
9696
* enabled.
9797
*
9898
* @param primitives The primitives
99+
* @param <O> The primitive type
99100
*/
100101
public <O extends IPrimitive & IFilterablePrimitive> void executeFilters(Collection<O> primitives) {
101102
executeFilters(primitives, false);

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/dialog/TrafficSignFilter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ private void updateShown(SpinnerNumberModel model) {
259259
*
260260
* @param button The button to check
261261
* @param expr The filter text
262+
* @param detections The detections to use to check and see if the button is relevant
262263
* @return {@code true} if the button should be shown
263264
*/
264265
private boolean checkRelevant(ImageCheckBoxButton button, String expr, Collection<String> detections) {

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/imageinfo/ImageInfoPanel.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import java.awt.datatransfer.StringSelection;
1212
import java.awt.event.KeyEvent;
1313
import java.awt.image.BufferedImage;
14-
import java.net.URL;
14+
import java.net.URI;
15+
import java.net.URISyntaxException;
1516
import java.util.Collection;
1617
import java.util.List;
1718
import java.util.Optional;
@@ -50,10 +51,14 @@
5051
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryProperties;
5152
import org.openstreetmap.josm.plugins.mapillary.utils.OffsetUtils;
5253
import org.openstreetmap.josm.tools.GBC;
54+
import org.openstreetmap.josm.tools.JosmRuntimeException;
5355
import org.openstreetmap.josm.tools.Logging;
5456
import org.openstreetmap.josm.tools.Shortcut;
5557
import org.openstreetmap.josm.tools.Utils;
5658

59+
/**
60+
* A panel to show image specific information
61+
*/
5762
public final class ImageInfoPanel extends ToggleDialog implements DataSelectionListener, VectorDataSelectionListener {
5863
private static final long serialVersionUID = 1320443250226377651L;
5964
private static ImageInfoPanel instance;
@@ -243,12 +248,24 @@ private void selectedImageChanged(@Nullable INode oldImage, @Nullable INode newI
243248
imgKeyValue.setEnabled(newImage != null);
244249
final String newImageKey = newImage != null ? Long.toString(newImage.getId()) : null;
245250
if (newImageKey != null) {
246-
final URL newImageUrl = MapillaryProperties.IMAGE_LINK_TO_BLUR_EDITOR.get()
247-
? MapillaryConfig.getUrls().blurEditImage(newImageKey)
251+
final boolean blur = Boolean.TRUE.equals(MapillaryProperties.IMAGE_LINK_TO_BLUR_EDITOR.get());
252+
final URI newImageUrl = blur ? MapillaryConfig.getUrls().blurEditImage(newImageKey)
248253
: MapillaryConfig.getUrls().browseImage(newImageKey);
249254

250255
offsetModel.setValue(OffsetUtils.getOffset(newImage));
251-
imageLinkChangeListener = b -> imgLinkAction.setURL(newImageUrl);
256+
if (blur) {
257+
imageLinkChangeListener = b -> imgLinkAction.setURI(newImageUrl);
258+
} else {
259+
try {
260+
final URI newImageUrlWithLocation = new URI(newImageUrl.getScheme(), newImageUrl.getAuthority(),
261+
newImageUrl.getPath(),
262+
newImageUrl.getQuery() + "&z=18&lat=" + newImage.lat() + "&lng=" + newImage.lon(),
263+
newImageUrl.getFragment());
264+
imageLinkChangeListener = b -> imgLinkAction.setURI(newImageUrlWithLocation);
265+
} catch (URISyntaxException e) {
266+
throw new JosmRuntimeException(e);
267+
}
268+
}
252269
imageLinkChangeListener.valueChanged(null);
253270
MapillaryProperties.IMAGE_LINK_TO_BLUR_EDITOR.addListener(imageLinkChangeListener);
254271
copyImgUrlAction.setContents(new StringSelection(newImageUrl.toString()));
@@ -273,7 +290,7 @@ private void selectedImageChanged(@Nullable INode oldImage, @Nullable INode newI
273290
imageLinkChangeListener = null;
274291
}
275292
this.offsetModel.setValue(OffsetUtils.getOffset(null));
276-
imgLinkAction.setURL(null);
293+
imgLinkAction.setURI(null);
277294
copyImgUrlAction.setContents(null);
278295

279296
imgKeyValue.setText('‹' + tr("image has no key") + '›');

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/imageinfo/WebLinkAction.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
package org.openstreetmap.josm.plugins.mapillary.gui.imageinfo;
33

44
import java.awt.event.ActionEvent;
5+
import java.net.URI;
56
import java.net.URISyntaxException;
6-
import java.net.URL;
77

88
import javax.swing.AbstractAction;
99
import javax.swing.JOptionPane;
@@ -15,23 +15,32 @@
1515
import org.openstreetmap.josm.tools.Logging;
1616
import org.openstreetmap.josm.tools.OpenBrowser;
1717

18+
/**
19+
* An action to open web links
20+
*/
1821
public class WebLinkAction extends AbstractAction {
1922
private static final long serialVersionUID = 2397830510179013823L;
2023

21-
private URL url;
24+
private URI uri;
2225

23-
public WebLinkAction(final String name, final URL url) {
26+
/**
27+
* Create a new action
28+
*
29+
* @param name The name to show users
30+
* @param uri The original URI to open
31+
*/
32+
public WebLinkAction(final String name, final URI uri) {
2433
super(name, ImageProvider.get("link", ImageSizes.SMALLICON));
25-
setURL(url);
34+
setURI(uri);
2635
}
2736

2837
/**
2938
* Set the URL to be opened
3039
*
3140
* @param url the url to set
3241
*/
33-
public final void setURL(URL url) {
34-
this.url = url;
42+
public final void setURI(URI url) {
43+
this.uri = url;
3544
setEnabled(url != null);
3645
}
3746

@@ -42,13 +51,13 @@ public final void setURL(URL url) {
4251
@Override
4352
public void actionPerformed(ActionEvent e) {
4453
try {
45-
if (url != null) {
46-
OpenBrowser.displayUrl(url.toURI());
54+
if (uri != null) {
55+
OpenBrowser.displayUrl(uri);
4756
} else {
4857
throw new URISyntaxException("‹null›", "The URL is null");
4958
}
5059
} catch (URISyntaxException e1) {
51-
String msg = I18n.tr("Could not open the URL {0} in a browser", url == null ? "‹null›" : url);
60+
String msg = I18n.tr("Could not open the URL {0} in a browser", "‹null›");
5261
Logging.log(Logging.LEVEL_WARN, msg, e1);
5362
new Notification(msg).setIcon(JOptionPane.WARNING_MESSAGE).show();
5463
}

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/layer/geoimage/MapillaryImageEntry.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.io.IOException;
1818
import java.lang.ref.SoftReference;
1919
import java.net.URI;
20-
import java.net.URISyntaxException;
2120
import java.text.DateFormat;
2221
import java.time.Instant;
2322
import java.time.ZoneOffset;
@@ -421,19 +420,12 @@ public void setHeight(int height) {
421420
@Override
422421
@Nullable
423422
public File getFile() {
424-
return new File(MapillaryConfig.getUrls().browseImage(Long.toString(MapillaryImageUtils.getKey(this.image)))
425-
.toExternalForm());
423+
return new File(getImageURI());
426424
}
427425

428426
// @Override -- added in JOSM r18427
429427
public URI getImageURI() {
430-
try {
431-
return new URI(MapillaryConfig.getUrls().browseImage(Long.toString(MapillaryImageUtils.getKey(this.image)))
432-
.toExternalForm());
433-
} catch (URISyntaxException e) {
434-
// This should never happen.
435-
throw new JosmRuntimeException(this.toString(), e);
436-
}
428+
return MapillaryConfig.getUrls().browseImage(Long.toString(MapillaryImageUtils.getKey(this.image)));
437429
}
438430

439431
@Override
@@ -571,6 +563,15 @@ public void reload() {
571563
this.updateImageEntry();
572564
}
573565

566+
/**
567+
* Get the image node for this entry
568+
*
569+
* @return The image node
570+
*/
571+
public INode getImage() {
572+
return this.image;
573+
}
574+
574575
private void updateImageEntry() {
575576
// Clone this entry. Needed to ensure that the image display refreshes.
576577
final MapillaryImageEntry temporaryImageEntry = new MapillaryImageEntry(this);

src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.IOException;
99
import java.io.InputStream;
1010
import java.net.HttpURLConnection;
11+
import java.net.URI;
1112
import java.net.URL;
1213
import java.net.URLConnection;
1314
import java.nio.charset.StandardCharsets;
@@ -72,6 +73,20 @@ public static JsonObject getWithHeader(URL url) throws IOException {
7273
return getWithHeader(client);
7374
}
7475

76+
/**
77+
* Returns a JsonObject containing the result of making a GET request with the
78+
* authorization header.
79+
*
80+
* @param uri
81+
* The {@link URI} where the request must be made.
82+
* @return A JsonObject containing the result of the GET request.
83+
* @throws IOException
84+
* Errors relating to the connection.
85+
*/
86+
public static JsonObject getWithHeader(URI uri) throws IOException {
87+
return getWithHeader(uri.toURL());
88+
}
89+
7590
/**
7691
* Returns a JsonObject containing the result of making a request with the
7792
* authorization header.
@@ -190,6 +205,7 @@ private static String getAuthorizationToken() {
190205
* Refresh authorization
191206
*
192207
* @param authorizationCode The code to use to refresh auth
208+
* @throws OAuthUtilsException if there was an {@link IOException} of some type
193209
*/
194210
private static void refreshAuthorization(final String authorizationCode) throws OAuthUtilsException {
195211
HttpClient.Response response = null;

0 commit comments

Comments
 (0)