Changeset 18046 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Mediawiki.java
r17880 r18046 95 95 public void searchGeoImages(Bounds bounds, BiConsumer<String, LatLon> imageConsumer) 96 96 throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { 97 final URL url = new URL(baseUrl + 98 "?format=xml" + 99 "&action=query" + 100 "&list=geosearch" + 101 "&gsnamespace=6" + 102 "&gslimit=500" + 103 "&gsprop=type|name" + 104 "&gsbbox=" + bounds.getMaxLat() + "|" + bounds.getMinLon() + "|" + bounds.getMinLat() + "|" + bounds.getMaxLon()); 97 final URL url = new URL(getGeoImagesUrl(baseUrl, bounds)); 105 98 final Document document = getDocument(url); 106 99 final XPath xPath = XPathFactory.newInstance().newXPath(); … … 113 106 imageConsumer.accept(title, new LatLon(lat, lon)); 114 107 } 108 } 109 110 /** 111 * Returns the URL for searching geolocated images in given bounds. 112 * @param baseUrl The wiki base URL 113 * @param bounds the bounds of the search area 114 * @return the URL for searching geolocated images in given bounds 115 * @since 18046 116 */ 117 public static String getGeoImagesUrl(String baseUrl, Bounds bounds) { 118 String sep = Utils.encodeUrl("|"); 119 return baseUrl + 120 "?format=xml" + 121 "&action=query" + 122 "&list=geosearch" + 123 "&gsnamespace=6" + 124 "&gslimit=500" + 125 "&gsprop=type" + sep + "name" + 126 "&gsbbox=" + bounds.getMaxLat() + sep + bounds.getMinLon() + sep + bounds.getMinLat() + sep + bounds.getMaxLon(); 115 127 } 116 128 -
trunk/test/unit/org/openstreetmap/josm/tools/MediawikiTest.java
r17275 r18046 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 5 6 import java.net.URI; 7 import java.net.URL; 8 6 9 import org.junit.jupiter.api.Test; 10 import org.openstreetmap.josm.data.Bounds; 7 11 8 12 /** … … 21 25 Mediawiki.getImageUrl("https://upload.wikimedia.org/wikipedia/commons/", "OpenJDK_logo.svg")); 22 26 } 27 28 /** 29 * Test of {@link Mediawiki#getGeoImagesUrl} 30 * @throws Exception never 31 */ 32 @Test 33 void testGeoImagesUrl() throws Exception { 34 // See https://josm.openstreetmap.de/ticket/21126 35 // Checks that URL can be converted to URI, needed for HTTP/2 36 assertEquals(new URI("https://commons.wikimedia.org/w/api.php?format=xml&action=query&list=geosearch&gsnamespace=6&gslimit=500&gsprop=type%7Cname&gsbbox=48.8623665%7C2.3913497%7C48.8600879%7C2.3967605"), 37 new URL(Mediawiki.getGeoImagesUrl("https://commons.wikimedia.org/w/api.php", new Bounds(48.8600879, 2.3913497, 48.8623665, 2.3967605))).toURI()); 38 } 23 39 }
Note:
See TracChangeset
for help on using the changeset viewer.