Changeset 31831 in osm
- Timestamp:
- 2015-12-15T20:51:34+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryURL.java
r31828 r31831 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.mapillary.utils; 2 3 … … 23 24 } 24 25 26 /** 27 * Gives you the URL for the online editor of a specific mapillary image. 28 * @param key the key of the image to which you want to link 29 * @return the URL of the online editor for the image with the given image key 30 */ 25 31 public static URL browseEditURL(String key) { 26 32 if (key == null || !key.matches("[a-zA-Z0-9\\-_]{22}")) { … … 30 36 } 31 37 38 /** 39 * Gives you the URL for the online viewer of a specific mapillary image. 40 * @param key the key of the image to which you want to link 41 * @return the URL of the online viewer for the image with the given image key 42 */ 32 43 public static URL browseImageURL(String key) { 33 44 if (key == null || !key.matches("[a-zA-Z0-9\\-_]{22}")) { … … 37 48 } 38 49 50 /** 51 * @return the URL where the user can view all uploaded images that are not yet published 52 */ 39 53 public static URL browseUploadImageURL() { 40 return string2URL(BASE_WEBSITE_URL + "map/upload/im ");54 return string2URL(BASE_WEBSITE_URL + "map/upload/im/"); 41 55 } 42 56 57 /** 58 * Gives you the URL which the user should visit to initiate the OAuth authentication process 59 * @param redirectURI the URI to which the user will be redirected when the authentication is finished 60 * @return the URL that the user should visit to start the OAuth authentication 61 */ 43 62 public static URL connectURL(String redirectURI) { 44 63 HashMap<String, String> parts = new HashMap<>(); 45 parts.put("redirect_uri", redirectURI); 64 if (redirectURI != null && redirectURI.length() >= 1) { 65 parts.put("redirect_uri", redirectURI); 66 } 46 67 parts.put("response_type", "token"); 47 68 parts.put("scope", "user:read public:upload public:write"); … … 49 70 } 50 71 72 /** 73 * Gives you the API-URL where you get 20 images within the given bounds. 74 * For more than 20 images you have to use different URLs with different page numbers. 75 * @param bounds the bounds in which you want to search for images 76 * @param page number of the page to retrieve from the API 77 * @return the API-URL which gives you the images in the given bounds as JSON 78 */ 51 79 public static URL searchImageURL(Bounds bounds, int page) { 52 80 HashMap<String, String> parts = new HashMap<>(); … … 57 85 } 58 86 87 /** 88 * Gives you the API-URL where you get 10 sequences within the given bounds. 89 * For more than 10 sequences you have to use different URLs with different page numbers. 90 * @param bounds the bounds in which you want to search for sequences 91 * @param page number of the page to retrieve from the API 92 * @return the API-URL which gives you the sequences in the given bounds as JSON 93 */ 59 94 public static URL searchSequenceURL(Bounds bounds, int page) { 60 95 HashMap<String, String> parts = new HashMap<>(); … … 65 100 } 66 101 102 /** 103 * Gives you the API-URL where you get the traffic signs for 20 images within the given bounds. 104 * For the signs from more than 20 images you have to use different URLs with different page numbers. 105 * @param bounds the bounds in which you want to search for traffic signs 106 * @param page number of the page to retrieve from the API 107 * @return the API-URL which gives you the traffic signs in the given bounds as JSON 108 */ 67 109 public static URL searchTrafficSignURL(Bounds bounds, int page) { 68 110 HashMap<String, String> parts = new HashMap<>(); … … 73 115 } 74 116 117 /** 118 * @return the URL where you'll find the upload secrets as JSON 119 */ 75 120 public static URL uploadSecretsURL() { 76 121 return string2URL(BASE_API_URL + "me/uploads/secrets/" + queryString(null)); 77 122 } 78 123 124 /** 125 * @return the URL where you'll find information about the user account as JSON 126 */ 79 127 public static URL userURL() { 80 128 return string2URL(BASE_API_URL + "me/" + queryString(null)); 81 129 } 82 130 131 /** 132 * Adds the given {@link Bounds} to a {@link Map} that contains the parts of a query string. 133 * @param parts the parts of a query string 134 * @param bounds the bounds that will be added to the query string 135 */ 83 136 private static void putBoundsInQueryStringParts(Map<String, String> parts, Bounds bounds) { 84 parts.put("min_lat", String.format(Locale.UK, "%f", bounds.getMin().lat())); 85 parts.put("max_lat", String.format(Locale.UK, "%f", bounds.getMax().lat())); 86 parts.put("min_lon", String.format(Locale.UK, "%f", bounds.getMin().lon())); 87 parts.put("max_lon", String.format(Locale.UK, "%f", bounds.getMax().lon())); 137 if (bounds != null) { 138 parts.put("min_lat", String.format(Locale.UK, "%f", bounds.getMin().lat())); 139 parts.put("max_lat", String.format(Locale.UK, "%f", bounds.getMax().lat())); 140 parts.put("min_lon", String.format(Locale.UK, "%f", bounds.getMin().lon())); 141 parts.put("max_lon", String.format(Locale.UK, "%f", bounds.getMax().lon())); 142 } 88 143 } 89 144 145 /** 146 * Builds a query string from it's parts that are supplied as a {@link Map} 147 * @param parts the parts of the query string 148 * @return the constructed query string (including a leading ?) 149 */ 90 150 private static String queryString(Map<String, String> parts) { 91 StringBuilder ret = new StringBuilder( ).append("?client_id=").append(CLIENT_ID);151 StringBuilder ret = new StringBuilder("?client_id=").append(CLIENT_ID); 92 152 if (parts != null) { 93 153 for (Entry<String, String> entry : parts.entrySet()) { … … 105 165 } 106 166 167 /** 168 * Converts a {@link String} into a {@link URL} without throwing a {@link MalformedURLException}. 169 * Instead such an exception will lead to an {@link Main#error(Throwable)}. 170 * So you should be very confident that your URL is well-formed when calling this method. 171 * @param string the String describing the URL 172 * @return the URL that is constructed from the given string 173 */ 107 174 private static URL string2URL(String string) { 108 175 try { 109 176 return new URL(string); 110 177 } catch (MalformedURLException e) { 111 Main.error( "The MapillaryAPI class produces malformed URLs!", e);178 Main.error(new Exception("The "+MapillaryURL.class.getSimpleName()+" class produces malformed URLs!", e)); 112 179 return null; 113 180 }
Note:
See TracChangeset
for help on using the changeset viewer.