Changeset 32069 in osm for applications/editors/josm/plugins/mapillary/src
- Timestamp:
- 2016-02-15T14:58:49+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryImageInfoDownloadThread.java
r31843 r32069 46 46 public void run() { 47 47 try ( 48 BufferedReader br = new BufferedReader(new InputStreamReader(MapillaryURL.searchImageURL(bounds, page).openStream(), "UTF-8")); 48 BufferedReader br = new BufferedReader(new InputStreamReader( 49 MapillaryURL.searchImageInfoURL(bounds, page, null).openStream(), "UTF-8" 50 )); 49 51 ) { 50 52 JsonObject jsonobj = Json.createReader(br).readObject(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillarySequenceDownloadThread.java
r32064 r32069 53 53 public void run() { 54 54 try ( 55 BufferedReader br = new BufferedReader(new InputStreamReader( 56 MapillaryURL.searchSequenceURL(bounds, page).openStream(), 57 "UTF-8" 58 )); 55 BufferedReader br = new BufferedReader(new InputStreamReader( 56 MapillaryURL.searchSequenceURL(bounds, page).openStream(), "UTF-8" 57 )); 59 58 ) { 60 59 JsonObject jsonall = Json.createReader(br).readObject(); … … 121 120 } 122 121 } catch (IOException e) { 123 Main.error("Error reading the url " + MapillaryURL.searchSequenceURL(bounds, page) + " might be a Mapillary problem.", e); 122 Main.error(String.format( 123 "Error reading the url %s, this might be a Mapillary problem.", 124 MapillaryURL.searchSequenceURL(bounds, page) 125 ), e); 124 126 } 125 127 MapillaryData.dataUpdated(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryTrafficSignDownloadThread.java
r31951 r32069 18 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 19 19 import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryURL; 20 import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryURL.IMAGE_SELECTOR; 20 21 21 22 /** … … 48 49 try ( 49 50 BufferedReader br = new BufferedReader(new InputStreamReader( 50 MapillaryURL.search TrafficSignURL(bounds, page).openStream(), "UTF-8"51 MapillaryURL.searchImageInfoURL(bounds, page, IMAGE_SELECTOR.OBJ_REC_ONLY).openStream(), "UTF-8" 51 52 )); 52 53 ) { … … 78 79 for (int j = 0; j < rects.size(); j++) { 79 80 JsonObject data = rects.getJsonObject(j); 80 for (MapillaryAbstractImage image : MapillaryLayer.getInstance().getData().getImages()) 81 if (image instanceof MapillaryImage && ((MapillaryImage) image).getKey().equals(key)) 81 for (MapillaryAbstractImage image : MapillaryLayer.getInstance().getData().getImages()) { 82 if (image instanceof MapillaryImage && ((MapillaryImage) image).getKey().equals(key)) { 82 83 ((MapillaryImage) image).addSign(data.getString("type")); 84 } 85 } 83 86 } 84 87 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryURL.java
r32064 r32069 20 20 private static final String BASE_WEBSITE_URL = "https://www.mapillary.com/"; 21 21 22 public enum IMAGE_SELECTOR { 23 BLURRED_ONLY, COMMENTED_ONLY, OBJ_REC_ONLY // null is used when all images should be selected 24 } 25 22 26 private MapillaryURL() { 23 27 // Private constructor to avoid instantiation … … 33 37 public static URL browseEditURL(String imgKey) { 34 38 ValidationUtil.throwExceptionForInvalidImgKey(imgKey, false); 35 return string2URL(BASE_WEBSITE_URL +"map/e/"+imgKey);39 return string2URL(BASE_WEBSITE_URL, "map/e/", imgKey); 36 40 } 37 41 … … 45 49 public static URL browseImageURL(String key) { 46 50 ValidationUtil.throwExceptionForInvalidImgKey(key, false); 47 return string2URL(BASE_WEBSITE_URL +"map/im/"+key);51 return string2URL(BASE_WEBSITE_URL, "map/im/", key); 48 52 } 49 53 … … 52 56 */ 53 57 public static URL browseUploadImageURL() { 54 return string2URL(BASE_WEBSITE_URL +"map/upload/im/");58 return string2URL(BASE_WEBSITE_URL, "map/upload/im"); 55 59 } 56 60 … … 67 71 parts.put("response_type", "token"); 68 72 parts.put("scope", "user:read public:upload public:write"); 69 return string2URL(BASE_WEBSITE_URL +"connect"+queryString(parts));73 return string2URL(BASE_WEBSITE_URL, "connect", queryString(parts)); 70 74 } 71 75 … … 75 79 * @param bounds the bounds in which you want to search for images 76 80 * @param page number of the page to retrieve from the API 81 * @param selector 77 82 * @return the API-URL which gives you the images in the given bounds as JSON 78 83 */ 79 public static URL searchImageURL(Bounds bounds, int page) { 84 public static URL searchImageInfoURL(Bounds bounds, int page, IMAGE_SELECTOR selector) { 85 String selectorString = ""; 86 if (selector != null) { 87 switch (selector) { 88 case BLURRED_ONLY: 89 selectorString = "/b"; 90 break; 91 case COMMENTED_ONLY: 92 selectorString = "/cm"; 93 break; 94 case OBJ_REC_ONLY: 95 selectorString = "/or"; 96 break; 97 default: 98 selectorString = ""; 99 break; 100 } 101 } 80 102 HashMap<String, String> parts = new HashMap<>(); 81 103 putBoundsInQueryStringParts(parts, bounds); 82 104 parts.put("page", Integer.toString(page)); 83 105 parts.put("limit", "20"); 84 return string2URL(BASE_API_URL +"search/im/" +queryString(parts));106 return string2URL(BASE_API_URL, "search/im", selectorString, queryString(parts)); 85 107 } 86 108 … … 97 119 parts.put("page", Integer.toString(page)); 98 120 parts.put("limit", "10"); 99 return string2URL(BASE_API_URL + "search/s/" + queryString(parts)); 100 } 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 */ 109 public static URL searchTrafficSignURL(Bounds bounds, int page) { 110 HashMap<String, String> parts = new HashMap<>(); 111 putBoundsInQueryStringParts(parts, bounds); 112 parts.put("page", Integer.toString(page)); 113 parts.put("limit", "20"); 114 return string2URL(BASE_API_URL + "search/im/or/" + queryString(parts)); 121 return string2URL(BASE_API_URL, "search/s", queryString(parts)); 115 122 } 116 123 … … 119 126 */ 120 127 public static URL uploadSecretsURL() { 121 return string2URL(BASE_API_URL +"me/uploads/secrets/" +queryString(null));128 return string2URL(BASE_API_URL, "me/uploads/secrets", queryString(null)); 122 129 } 123 130 … … 126 133 */ 127 134 public static URL userURL() { 128 return string2URL(BASE_API_URL + "me/" +queryString(null));135 return string2URL(BASE_API_URL, "me", queryString(null)); 129 136 } 130 137 … … 172 179 * @return the URL that is constructed from the given string 173 180 */ 174 private static URL string2URL(String string) { 181 private static URL string2URL(String... strings) { 182 StringBuilder builder = new StringBuilder(); 183 for (int i = 0; strings != null && i < strings.length; i++) { 184 builder.append(strings[i]); 185 } 175 186 try { 176 return new URL( string);187 return new URL(builder.toString()); 177 188 } catch (MalformedURLException e) { 178 Main.error(new Exception("The "+MapillaryURL.class.getSimpleName()+" class produces malformed URLs!", e)); 189 Main.error(new Exception(String.format( 190 "The class '%s' produces malformed URLs like '%s'!", 191 MapillaryURL.class.getName(), 192 builder 193 ), e)); 179 194 return null; 180 195 }
Note:
See TracChangeset
for help on using the changeset viewer.