From 042e21c28684d08eea28fd5f4b8f7409b460a9a4 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Tue, 16 Jan 2024 13:55:44 -0700 Subject: [PATCH] Fix an issue where a custom source would have "&" for the first query parameter instead of "?" Signed-off-by: Taylor Smock --- .../BoundingBoxMapWithAIDownloader.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloader.java index 87a5124d..886b4d89 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloader.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -130,14 +131,20 @@ protected String getRequestForBbox(double lon1, double lat1, double lon2, double final var tile = TileXYZ.tileFromBBox(lon1, lat1, lon2, lat2); return getRequestForTile(tile); } - return url.replace("{bbox}", Double.toString(lon1) + ',' + lat1 + ',' + lon2 + ',' + lat2) + var current = url.replace("{bbox}", Double.toString(lon1) + ',' + lat1 + ',' + lon2 + ',' + lat2) .replace("{xmin}", Double.toString(lon1)).replace("{ymin}", Double.toString(lat1)) - .replace("{xmax}", Double.toString(lon2)).replace("{ymax}", Double.toString(lat2)) - + (crop ? "&crop_bbox=" + DetectTaskingManagerUtils.getTaskingManagerBounds().toBBox().toStringCSV(",") - : "") - + (this.info.getSourceType() == MapWithAIType.ESRI_FEATURE_SERVER && !this.info.isConflated() - ? "&resultOffset=" + this.start - : ""); + .replace("{xmax}", Double.toString(lon2)).replace("{ymax}", Double.toString(lat2)); + boolean hasQuery = Optional.ofNullable(URI.create(current).getRawQuery()).map(String::isEmpty).orElse(false); + + if (crop) { + current = (hasQuery ? '&' : '?') + "crop_bbox=" + + DetectTaskingManagerUtils.getTaskingManagerBounds().toBBox().toStringCSV(","); + hasQuery = true; + } + if (this.info.getSourceType() == MapWithAIType.ESRI_FEATURE_SERVER && !this.info.isConflated()) { + current = (hasQuery ? '&' : '?') + "resultOffset=" + this.start; + } + return current; } private String getRequestForTile(TileXYZ tile) {