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 5ad1ae4..a8509c2 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 @@ -31,6 +31,18 @@ public class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader { + (crop ? "crop_bbox=" + lon1 + ',' + lat1 + ',' + lon2 + ',' + lat2 : ""); } + @Override + protected DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { + DataSet ds = OsmReaderCustom.parseDataSet(source, progressMonitor, true); + GetDataRunnable.addMapWithAISourceTag(ds, + MapWithAIPreferenceHelper.getMapWithAIUrl().stream() + .filter(map -> map.getOrDefault("url", "no-url").equals(url)) + .map(map -> map.getOrDefault("source", MapWithAIPlugin.NAME)).findFirst() + .orElse(MapWithAIPlugin.NAME)); + GetDataRunnable.cleanup(ds, downloadArea); + return ds; + } + /** * Returns the name of the download task to be displayed in the * {@link ProgressMonitor}. diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java index 072f673..39fbda9 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java @@ -196,13 +196,18 @@ public final class MapWithAIDataUtils { return forkJoinPool; } + /** + * Get the height of a bbox + * + * @param bbox The bbox with lat/lon information + * @return The height in meters (see {@link LatLon#greatCircleDistance}) + */ public static double getHeight(BBox bbox) { final LatLon bottomRight = bbox.getBottomRight(); final LatLon topLeft = bbox.getTopLeft(); final double minx = topLeft.getX(); final double miny = bottomRight.getY(); final LatLon bottomLeft = new LatLon(miny, minx); - // TODO handle poles return topLeft.greatCircleDistance(bottomLeft); } @@ -309,13 +314,17 @@ public final class MapWithAIDataUtils { final BBox bbox1 = alreadyDownloadedReduced.get(i); for (int j = 0; j < alreadyDownloadedReduced.size(); j++) { final BBox bbox2 = alreadyDownloadedReduced.get(j); - if (!bbox1.equals(bbox2) && bboxesShareSide(bbox1, bbox2)) { + if (!bbox1.bboxIsFunctionallyEqual(bbox2, null) && bboxesShareSide(bbox1, bbox2)) { bbox1.add(bbox2); alreadyDownloadedReduced.remove(bbox2); } } } } while (aDRSize != alreadyDownloadedReduced.size()); + return removeDuplicateBBoxes(wantToDownload, alreadyDownloadedReduced); + } + + private static List removeDuplicateBBoxes(List wantToDownload, List alreadyDownloaded) { for (final BBox bbox : wantToDownload) { for (final BBox downloaded : alreadyDownloaded) { if (downloaded.bboxIsFunctionallyEqual(downloaded, null)) { @@ -325,9 +334,10 @@ public final class MapWithAIDataUtils { } } return wantToDownload.parallelStream() - .filter(bbox1 -> alreadyDownloadedReduced.parallelStream() + .filter(bbox1 -> alreadyDownloaded.parallelStream() .noneMatch(bbox2 -> bbox2.bboxIsFunctionallyEqual(bbox1, 0.000_02))) .collect(Collectors.toList()); + } private static boolean bboxesShareSide(BBox bbox1, BBox bbox2) { @@ -352,7 +362,6 @@ public final class MapWithAIDataUtils { final double maxy = topLeft.getY(); final LatLon bottomLeft = new LatLon(miny, minx); final LatLon topRight = new LatLon(maxy, maxx); - // TODO handle meridian return Math.max(bottomRight.greatCircleDistance(bottomLeft), topRight.greatCircleDistance(topLeft)); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/OsmReaderCustom.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/OsmReaderCustom.java index 123382c..e136998 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/OsmReaderCustom.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/OsmReaderCustom.java @@ -28,7 +28,7 @@ public class OsmReaderCustom extends OsmReader { } // check every so often to see if I can keep original negative ids - // See https://josm.openstreetmap.de/ticket/18258 (TODO) + // See https://josm.openstreetmap.de/ticket/18258 (TODO) // NOSONAR @Override protected OsmPrimitive buildPrimitive(PrimitiveData pd) { final Long serverId = pd.getUniqueId(); @@ -65,4 +65,4 @@ public class OsmReaderCustom extends OsmReader { throws IllegalDataException { return new OsmReaderCustom(convertUnknownToTags).doParseDataSet(source, progressMonitor); } -} \ No newline at end of file +} diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/frontend/MapWithAIDownloadReader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/frontend/MapWithAIDownloadReader.java index 28559fc..84ad2f0 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/frontend/MapWithAIDownloadReader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/frontend/MapWithAIDownloadReader.java @@ -126,7 +126,6 @@ public class MapWithAIDownloadReader implements DownloadSource> errorReporter = errors -> { - boolean onlyNoDataError = errors.size() == 1 && errors.contains("No data found in this area."); }; return new MapWithAIDownloadData(MapWithAIPreferenceHelper.getMapWithAIUrl(), errorReporter); } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPluginTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPluginTest.java index 4600f2e..f52b665 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPluginTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPluginTest.java @@ -23,7 +23,6 @@ import org.openstreetmap.josm.plugins.PluginInformation; import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils; import org.openstreetmap.josm.spi.preferences.Config; import org.openstreetmap.josm.testutils.JOSMTestRules; -import org.openstreetmap.josm.tools.Logging; import com.github.tomakehurst.wiremock.WireMockServer;