Changeset 18046 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2021-07-17T14:42:03+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21126 - make sure URL generated for searching Wikimedia Commons images can be converted to URI, needed for HTTP/2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Mediawiki.java

    r17880 r18046  
    9595    public void searchGeoImages(Bounds bounds, BiConsumer<String, LatLon> imageConsumer)
    9696            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));
    10598        final Document document = getDocument(url);
    10699        final XPath xPath = XPathFactory.newInstance().newXPath();
     
    113106            imageConsumer.accept(title, new LatLon(lat, lon));
    114107        }
     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();
    115127    }
    116128
Note: See TracChangeset for help on using the changeset viewer.