Commit f23d43e1 authored by Yuri Astrakhan's avatar Yuri Astrakhan

Fixed Wikosm template parameter expansion

git-svn-id: https://svn.openstreetmap.org/applications/editors/josm/plugins/wikipedia@33626 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
parent 51113e1f
......@@ -220,7 +220,10 @@ public class WikosmDownloadSource implements DownloadSource<WikosmDownloadSource
* Absence of the selected area can be justified only if the Wikosm query
* is not restricted to bbox.
*/
if (!settings.getDownloadBounds().isPresent() && query.contains("{{bbox}}")) {
if (!settings.getDownloadBounds().isPresent() && (
query.contains("{{boxParams}}") ||
query.contains("{{center}}")
)) {
JOptionPane.showMessageDialog(
this.getParent(),
tr("Please select a download area first."),
......
......@@ -87,23 +87,23 @@ public class WikosmDownloadReader extends BoundingBoxDownloader {
@Override
protected String getRequestForBbox(double lon1, double lat1, double lon2, double lat2) {
final String query = this.wikosmQuery
.replace("{{boxParams}}", bbox(lon1, lat1, lon2, lat2))
.replace("{{boxParams}}", boxParams(lon1, lat1, lon2, lat2))
.replace("{{center}}", center(lon1, lat1, lon2, lat2));
return DATA_PREFIX + Utils.encodeUrl(query);
}
private static String bbox(double lon1, double lat1, double lon2, double lat2) {
return "\nbd:serviceParam wikibase:cornerWest " + point(lon1, lat1) + "." +
public static String boxParams(double lon1, double lat1, double lon2, double lat2) {
return "\nbd:serviceParam wikibase:cornerWest " + point(lon1, lat1) + ".\n" +
"bd:serviceParam wikibase:cornerEast " + point(lon2, lat2) + ".\n";
}
private static String center(double lon1, double lat1, double lon2, double lat2) {
public static String center(double lon1, double lat1, double lon2, double lat2) {
LatLon c = new BBox(lon1, lat1, lon2, lat2).getCenter();
return point(c.lon(), c.lat());
}
private static String point(double lon, double lat) {
return "Point(\"" + lon + " " + lat + "\")^^geo:wktLiteral";
public static String point(double lon, double lat) {
return "\"Point(" + lon + " " + lat + ")\"^^geo:wktLiteral";
}
static String date(String humanDuration, LocalDateTime from) {
......@@ -265,7 +265,7 @@ public class WikosmDownloadReader extends BoundingBoxDownloader {
DataSet ds = super.parseOsm(progressMonitor);
// add bounds if necessary (note that Wikosm API does not return bounds in the response XML)
if (ds != null && ds.getDataSources().isEmpty() && wikosmQuery.contains("{{bbox}}")) {
if (ds != null && ds.getDataSources().isEmpty() && wikosmQuery.contains("{{boxParams}}")) {
if (crosses180th) {
Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0);
DataSource src = new DataSource(bounds, getBaseUrl());
......
......@@ -16,6 +16,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
......@@ -32,7 +33,19 @@ public class WikosmDownloadReaderTest {
public JOSMTestRules test = new JOSMTestRules().preferences();
/**
* Tests evaluating the extended query feature {@code date}.
* Tests point generation
*/
@Test
public void testPoint() throws UnsupportedEncodingException {
assertThat(WikosmDownloadReader.point(9.5, 47.16),
is("\"Point(9.5 47.16)\"^^geo:wktLiteral"));
assertThat(WikosmDownloadReader.boxParams(1, 2, 3, 4),
is("\nbd:serviceParam wikibase:cornerWest \"Point(1 2)\"^^geo:wktLiteral." +
"\nbd:serviceParam wikibase:cornerEast \"Point(3 4)\"^^geo:wktLiteral.\n"));
}
/**
* Tests server response parsing
*/
@Test
public void testIdParsing() throws UnsupportedEncodingException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment