Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Mapillary (website) no longer zooms in to images
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tsmock committed Dec 8, 2022
1 parent 72cff86 commit be4dc55
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static void downloadPicture(INode img, MapillaryCache.Type type) {
* The picture to be requested.
* @param lis
* The listener that is going to receive the picture.
* @param type The image type
*/
public static void submit(INode image, MapillaryCache.Type type, ICachedLoaderListener lis) {
submit(image, type, true, lis);
Expand All @@ -75,6 +76,8 @@ public static void submit(INode image, MapillaryCache.Type type, ICachedLoaderLi
* The picture to be requested.
* @param lis
* The listener that is going to receive the picture.
* @param type The image type to get
* @param removeCurrent {@code true} if any outstanding tasks should be canceled
*/
public static void submit(INode image, MapillaryCache.Type type, boolean removeCurrent, ICachedLoaderListener lis) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public V get(@Nonnull String url) {
* This is non-blocking.
*
* @param url The URL to get
* @param pool The worker pool
* @return The information
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.data.mapillary;

import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Filter;
import org.openstreetmap.josm.data.osm.FilterMatcher;
Expand Down Expand Up @@ -39,6 +40,7 @@ public void executeFilters() {
/**
* Runs the filters on a data set
*
* @param <O> The base primitive type of the dataset
* @param ds The dataset to run filters on
*/
public <O extends IPrimitive & IFilterablePrimitive> void executeFilters(OsmData<O, ?, ?, ?> ds) {
Expand All @@ -62,6 +64,7 @@ public void executeFilters(@Nullable Collection<? extends OsmPrimitive> primitiv
*
* @param ds The dataset with the primitives
* @param primitives The primitives
* @param <O> The base primitive type for the dataset
*/
public <O extends IPrimitive & IFilterablePrimitive> void executeFilters(@Nullable OsmData<O, ?, ?, ?> ds,
@Nullable Collection<? extends O> primitives) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public final class ObjectDetections {
/**
* Create an ObjectDetection
*
* @param key The key for the detection
* @param tagMap The OSM key(s) for the object
* @param taggingPresetType The valid types for the preset
* @param additionalCommands Additional commands to run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public boolean isFiltered(String searchString) {
* Set the box as selected
*
* @param selected Set the checkbox state to the selected boolean
* @return A future to indicate if the call finished
*/
public void setSelected(boolean selected) {
GuiHelper.runInEDT(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.net.URISyntaxException;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
Expand Down Expand Up @@ -41,7 +40,6 @@
import org.openstreetmap.josm.tools.GBC;
import org.openstreetmap.josm.tools.I18n;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.OpenBrowser;

/**
Expand Down Expand Up @@ -272,12 +270,8 @@ private static class LoginAction extends AbstractAction {
public void actionPerformed(ActionEvent arg0) {
OAuthPortListener portListener = new OAuthPortListener(callback);
portListener.start();
try {
OpenBrowser.displayUrl(
MapillaryConfig.getUrls().connect("http://localhost:" + OAuthPortListener.PORT + '/').toURI());
} catch (URISyntaxException e) {
Logging.error(e);
}
OpenBrowser
.displayUrl(MapillaryConfig.getUrls().connect("http://localhost:" + OAuthPortListener.PORT + '/'));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void executeFilters() {
* enabled.
*
* @param primitives The primitives
* @param <O> The primitive type
*/
public <O extends IPrimitive & IFilterablePrimitive> void executeFilters(Collection<O> primitives) {
executeFilters(primitives, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ private void updateShown(SpinnerNumberModel model) {
*
* @param button The button to check
* @param expr The filter text
* @param detections The detections to use to check and see if the button is relevant
* @return {@code true} if the button should be shown
*/
private boolean checkRelevant(ImageCheckBoxButton button, String expr, Collection<String> detections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -50,10 +51,14 @@
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryProperties;
import org.openstreetmap.josm.plugins.mapillary.utils.OffsetUtils;
import org.openstreetmap.josm.tools.GBC;
import org.openstreetmap.josm.tools.JosmRuntimeException;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Shortcut;
import org.openstreetmap.josm.tools.Utils;

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

offsetModel.setValue(OffsetUtils.getOffset(newImage));
imageLinkChangeListener = b -> imgLinkAction.setURL(newImageUrl);
if (blur) {
imageLinkChangeListener = b -> imgLinkAction.setURI(newImageUrl);
} else {
try {
final URI newImageUrlWithLocation = new URI(newImageUrl.getScheme(), newImageUrl.getAuthority(),
newImageUrl.getPath(),
newImageUrl.getQuery() + "&z=18&lat=" + newImage.lat() + "&lng=" + newImage.lon(),
newImageUrl.getFragment());
imageLinkChangeListener = b -> imgLinkAction.setURI(newImageUrlWithLocation);
} catch (URISyntaxException e) {
throw new JosmRuntimeException(e);
}
}
imageLinkChangeListener.valueChanged(null);
MapillaryProperties.IMAGE_LINK_TO_BLUR_EDITOR.addListener(imageLinkChangeListener);
copyImgUrlAction.setContents(new StringSelection(newImageUrl.toString()));
Expand All @@ -273,7 +290,7 @@ private void selectedImageChanged(@Nullable INode oldImage, @Nullable INode newI
imageLinkChangeListener = null;
}
this.offsetModel.setValue(OffsetUtils.getOffset(null));
imgLinkAction.setURL(null);
imgLinkAction.setURI(null);
copyImgUrlAction.setContents(null);

imgKeyValue.setText('‹' + tr("image has no key") + '›');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
package org.openstreetmap.josm.plugins.mapillary.gui.imageinfo;

import java.awt.event.ActionEvent;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
Expand All @@ -15,23 +15,32 @@
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.OpenBrowser;

/**
* An action to open web links
*/
public class WebLinkAction extends AbstractAction {
private static final long serialVersionUID = 2397830510179013823L;

private URL url;
private URI uri;

public WebLinkAction(final String name, final URL url) {
/**
* Create a new action
*
* @param name The name to show users
* @param uri The original URI to open
*/
public WebLinkAction(final String name, final URI uri) {
super(name, ImageProvider.get("link", ImageSizes.SMALLICON));
setURL(url);
setURI(uri);
}

/**
* Set the URL to be opened
*
* @param url the url to set
*/
public final void setURL(URL url) {
this.url = url;
public final void setURI(URI url) {
this.uri = url;
setEnabled(url != null);
}

Expand All @@ -42,13 +51,13 @@ public final void setURL(URL url) {
@Override
public void actionPerformed(ActionEvent e) {
try {
if (url != null) {
OpenBrowser.displayUrl(url.toURI());
if (uri != null) {
OpenBrowser.displayUrl(uri);
} else {
throw new URISyntaxException("‹null›", "The URL is null");
}
} catch (URISyntaxException e1) {
String msg = I18n.tr("Could not open the URL {0} in a browser", url == null ? "‹null›" : url);
String msg = I18n.tr("Could not open the URL {0} in a browser", "‹null›");
Logging.log(Logging.LEVEL_WARN, msg, e1);
new Notification(msg).setIcon(JOptionPane.WARNING_MESSAGE).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.DateFormat;
import java.time.Instant;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -421,19 +420,12 @@ public void setHeight(int height) {
@Override
@Nullable
public File getFile() {
return new File(MapillaryConfig.getUrls().browseImage(Long.toString(MapillaryImageUtils.getKey(this.image)))
.toExternalForm());
return new File(getImageURI());
}

// @Override -- added in JOSM r18427
public URI getImageURI() {
try {
return new URI(MapillaryConfig.getUrls().browseImage(Long.toString(MapillaryImageUtils.getKey(this.image)))
.toExternalForm());
} catch (URISyntaxException e) {
// This should never happen.
throw new JosmRuntimeException(this.toString(), e);
}
return MapillaryConfig.getUrls().browseImage(Long.toString(MapillaryImageUtils.getKey(this.image)));
}

@Override
Expand Down Expand Up @@ -571,6 +563,15 @@ public void reload() {
this.updateImageEntry();
}

/**
* Get the image node for this entry
*
* @return The image node
*/
public INode getImage() {
return this.image;
}

private void updateImageEntry() {
// Clone this entry. Needed to ensure that the image display refreshes.
final MapillaryImageEntry temporaryImageEntry = new MapillaryImageEntry(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -72,6 +73,20 @@ public static JsonObject getWithHeader(URL url) throws IOException {
return getWithHeader(client);
}

/**
* Returns a JsonObject containing the result of making a GET request with the
* authorization header.
*
* @param uri
* The {@link URI} where the request must be made.
* @return A JsonObject containing the result of the GET request.
* @throws IOException
* Errors relating to the connection.
*/
public static JsonObject getWithHeader(URI uri) throws IOException {
return getWithHeader(uri.toURL());
}

/**
* Returns a JsonObject containing the result of making a request with the
* authorization header.
Expand Down Expand Up @@ -190,6 +205,7 @@ private static String getAuthorizationToken() {
* Refresh authorization
*
* @param authorizationCode The code to use to refresh auth
* @throws OAuthUtilsException if there was an {@link IOException} of some type
*/
private static void refreshAuthorization(final String authorizationCode) throws OAuthUtilsException {
HttpClient.Response response = null;
Expand Down
Loading

0 comments on commit be4dc55

Please sign in to comment.