Ignore:
Timestamp:
2017-09-18T06:27:29+02:00 (7 years ago)
Author:
nyuriks
Message:

Fixed Wikosm template parameter expansion

Location:
applications/editors/josm/plugins/wikipedia
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wikipedia/src/org/wikipedia/gui/WikosmDownloadSource.java

    r33624 r33626  
    221221             * is not restricted to bbox.
    222222             */
    223             if (!settings.getDownloadBounds().isPresent() && query.contains("{{bbox}}")) {
     223            if (!settings.getDownloadBounds().isPresent() && (
     224                    query.contains("{{boxParams}}") ||
     225                    query.contains("{{center}}")
     226            )) {
    224227                JOptionPane.showMessageDialog(
    225228                        this.getParent(),
  • applications/editors/josm/plugins/wikipedia/src/org/wikipedia/io/WikosmDownloadReader.java

    r33624 r33626  
    8888    protected String getRequestForBbox(double lon1, double lat1, double lon2, double lat2) {
    8989        final String query = this.wikosmQuery
    90                 .replace("{{boxParams}}", bbox(lon1, lat1, lon2, lat2))
     90                .replace("{{boxParams}}", boxParams(lon1, lat1, lon2, lat2))
    9191                .replace("{{center}}", center(lon1, lat1, lon2, lat2));
    9292        return DATA_PREFIX + Utils.encodeUrl(query);
    9393    }
    9494
    95     private static String bbox(double lon1, double lat1, double lon2, double lat2) {
    96         return "\nbd:serviceParam wikibase:cornerWest " + point(lon1, lat1) + "." +
     95    public static String boxParams(double lon1, double lat1, double lon2, double lat2) {
     96        return "\nbd:serviceParam wikibase:cornerWest " + point(lon1, lat1) + ".\n" +
    9797                "bd:serviceParam wikibase:cornerEast " + point(lon2, lat2) + ".\n";
    9898    }
    9999
    100     private static String center(double lon1, double lat1, double lon2, double lat2) {
     100    public static String center(double lon1, double lat1, double lon2, double lat2) {
    101101        LatLon c = new BBox(lon1, lat1, lon2, lat2).getCenter();
    102102        return point(c.lon(), c.lat());
    103103    }
    104104
    105     private static String point(double lon, double lat) {
    106         return "Point(\"" + lon + " " + lat + "\")^^geo:wktLiteral";
     105    public static String point(double lon, double lat) {
     106        return "\"Point(" + lon + " " + lat + ")\"^^geo:wktLiteral";
    107107    }
    108108
     
    266266
    267267        // add bounds if necessary (note that Wikosm API does not return bounds in the response XML)
    268         if (ds != null && ds.getDataSources().isEmpty() && wikosmQuery.contains("{{bbox}}")) {
     268        if (ds != null && ds.getDataSources().isEmpty() && wikosmQuery.contains("{{boxParams}}")) {
    269269            if (crosses180th) {
    270270                Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0);
  • applications/editors/josm/plugins/wikipedia/test/unit/org/wikipedia/io/WikosmDownloadReaderTest.java

    r33622 r33626  
    1717import java.util.List;
    1818
     19import static org.hamcrest.CoreMatchers.equalTo;
    1920import static org.hamcrest.CoreMatchers.is;
    2021import static org.junit.Assert.assertThat;
     
    3334
    3435    /**
    35      * Tests evaluating the extended query feature {@code date}.
     36     * Tests point generation
     37     */
     38    @Test
     39    public void testPoint() throws UnsupportedEncodingException {
     40        assertThat(WikosmDownloadReader.point(9.5, 47.16),
     41                is("\"Point(9.5 47.16)\"^^geo:wktLiteral"));
     42        assertThat(WikosmDownloadReader.boxParams(1, 2, 3, 4),
     43                is("\nbd:serviceParam wikibase:cornerWest \"Point(1 2)\"^^geo:wktLiteral." +
     44                        "\nbd:serviceParam wikibase:cornerEast \"Point(3 4)\"^^geo:wktLiteral.\n"));
     45    }
     46
     47    /**
     48     * Tests server response parsing
    3649     */
    3750    @Test
Note: See TracChangeset for help on using the changeset viewer.