From 2ec09d5dcdee8a2387456aceaa8bcb5e4d732b76 Mon Sep 17 00:00:00 2001 From: tobrun Date: Fri, 26 Apr 2019 19:53:57 +0200 Subject: [PATCH] [annotation] - add getGeometry --- .../annotation_manager_unit_test.junit.ejs | 28 ++++++- .../scripts/annotation_options.java.ejs | 73 +++++++++++++++++++ .../plugins/annotation/CircleOptions.java | 21 ++++++ .../plugins/annotation/FillOptions.java | 28 +++++++ .../plugins/annotation/LineOptions.java | 24 ++++++ .../plugins/annotation/SymbolOptions.java | 21 ++++++ .../plugins/annotation/CircleManagerTest.java | 7 +- .../plugins/annotation/FillManagerTest.java | 12 ++- .../plugins/annotation/LineManagerTest.java | 9 ++- .../plugins/annotation/SymbolManagerTest.java | 7 +- 10 files changed, 223 insertions(+), 7 deletions(-) diff --git a/plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs b/plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs index 3c0ffb03b..8a2dd1807 100644 --- a/plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs +++ b/plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs @@ -327,13 +327,25 @@ public class <%- camelize(type) %>ManagerTest { public void testGeometry<%- camelize(type) %>() { <%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); <% if (type === "circle" || type === "symbol") { -%> - <%- camelize(type) %> <%- type %> = <%- type %>Manager.create(new <%- camelize(type) %>Options().withLatLng(new LatLng(12, 34))); + LatLng latLng = new LatLng(12, 34); + <%- camelize(type) %>Options options = new <%- camelize(type) %>Options().withLatLng(latLng); + <%- camelize(type) %> <%- type %> = <%- type %>Manager.create(options); + assertEquals(options.getLatLng(), latLng); + assertEquals(<%- type %>.getLatLng(), latLng); + assertEquals(options.getGeometry(), Point.fromLngLat(34, 12)); assertEquals(<%- type %>.getGeometry(), Point.fromLngLat(34, 12)); <% } else if (type === "line") { -%> ListlatLngs = new ArrayList<>(); latLngs.add(new LatLng()); latLngs.add(new LatLng(1,1)); - <%- camelize(type) %> <%- type %> = <%- type %>Manager.create(new <%- camelize(type) %>Options().withLatLngs(latLngs)); + <%- camelize(type) %>Options options = new <%- camelize(type) %>Options().withLatLngs(latLngs); + <%- camelize(type) %> <%- type %> = <%- type %>Manager.create(options); + assertEquals(options.getLatLngs(), latLngs); + assertEquals(line.getLatLngs(), latLngs); + assertEquals(options.getGeometry(), LineString.fromLngLats(new ArrayList() {{ + add(Point.fromLngLat(0, 0)); + add(Point.fromLngLat(1, 1)); + }})); assertEquals(line.getGeometry(), LineString.fromLngLats(new ArrayList() {{ add(Point.fromLngLat(0, 0)); add(Point.fromLngLat(1, 1)); @@ -345,7 +357,17 @@ public class <%- camelize(type) %>ManagerTest { innerLatLngs.add(new LatLng(-1,-1)); List>latLngs = new ArrayList<>(); latLngs.add(innerLatLngs); - Fill fill = fillManager.create(new <%- camelize(type) %>Options().withLatLngs(latLngs)); + <%- camelize(type) %>Options options = new <%- camelize(type) %>Options().withLatLngs(latLngs); + Fill fill = fillManager.create(options); + assertEquals(options.getLatLngs(), latLngs); + assertEquals(fill.getLatLngs(), latLngs); + assertEquals(options.getGeometry(), Polygon.fromLngLats(new ArrayList>() {{ + add(new ArrayList() {{ + add(Point.fromLngLat(0, 0)); + add(Point.fromLngLat(1, 1)); + add(Point.fromLngLat(-1, -1)); + }}); + }})); assertEquals(fill.getGeometry(), Polygon.fromLngLats(new ArrayList>() {{ add(new ArrayList() {{ add(Point.fromLngLat(0, 0)); diff --git a/plugin-annotation/scripts/annotation_options.java.ejs b/plugin-annotation/scripts/annotation_options.java.ejs index f1a07c815..e40717d8a 100644 --- a/plugin-annotation/scripts/annotation_options.java.ejs +++ b/plugin-annotation/scripts/annotation_options.java.ejs @@ -91,6 +91,18 @@ public class <%- camelize(type) %>Options extends Options<<%- camelize(type) %>> return this; } + /** + * Get the LatLng of the <%- type %>, which represents the location of the <%- type %> on the map + * + * @return the location of the <%- type %> in a longitude and latitude pair + */ + public LatLng getLatLng() { + if (geometry == null) { + return null; + } + return new LatLng(geometry.latitude(), geometry.longitude()); + } + /** * Set the geometry of the <%- type %>, which represents the location of the <%- type %> on the map * @@ -101,6 +113,15 @@ public class <%- camelize(type) %>Options extends Options<<%- camelize(type) %>> this.geometry = geometry; return this; } + + /** + * Get the geometry of the <%- type %>, which represents the location of the <%- type %> on the map + * + * @return the location of the <%- type %> + */ + public Point getGeometry() { + return geometry; + } <% } else if (type === "line") { -%> /** @@ -118,6 +139,21 @@ public class <%- camelize(type) %>Options extends Options<<%- camelize(type) %>> return this; } + /** + * Get a list of LatLng for the line, which represents the locations of the line on the map + * + * @return a list of the locations of the line in a longitude and latitude pairs + */ + public List getLatLngs() { + ListlatLngs = new ArrayList<>(); + if (geometry!=null) { + for (Point coordinate : geometry.coordinates()) { + latLngs.add(new LatLng(coordinate.latitude(), coordinate.longitude())); + } + } + return latLngs; + } + /** * Set the geometry of the <%- type %>, which represents the location of the <%- type %> on the map * @@ -128,6 +164,15 @@ public class <%- camelize(type) %>Options extends Options<<%- camelize(type) %>> this.geometry = geometry; return this; } + + /** + * Get the geometry of the <%- type %>, which represents the location of the <%- type %> on the map + * + * @return the location of the <%- type %> + */ + public LineString getGeometry() { + return geometry; + } <% } else { -%> /** @@ -149,6 +194,25 @@ public class <%- camelize(type) %>Options extends Options<<%- camelize(type) %>> return this; } + /** + * Get a list of lists of LatLng for the fill, which represents the locations of the fill on the map + * + * @return a list of a lists of the locations of the line in a longitude and latitude pairs + */ + public List> getLatLngs() { + List> points = new ArrayList<>(); + if (geometry != null) { + for (List coordinates : geometry.coordinates()) { + List innerList = new ArrayList<>(); + for (Point point : coordinates) { + innerList.add(new LatLng(point.latitude(), point.longitude())); + } + points.add(innerList); + } + } + return points; + } + /** * Set the geometry of the <%- type %>, which represents the location of the <%- type %> on the map * @@ -159,6 +223,15 @@ public class <%- camelize(type) %>Options extends Options<<%- camelize(type) %>> this.geometry = geometry; return this; } + + /** + * Get the geometry of the <%- type %>, which represents the location of the <%- type %> on the map + * + * @return the location of the <%- type %> + */ + public Polygon getGeometry() { + return geometry; + } <% } -%> <% if (type === "symbol") { -%> diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleOptions.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleOptions.java index b83488652..5964fe384 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleOptions.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleOptions.java @@ -223,6 +223,18 @@ public CircleOptions withLatLng(LatLng latLng) { return this; } + /** + * Get the LatLng of the circle, which represents the location of the circle on the map + * + * @return the location of the circle in a longitude and latitude pair + */ + public LatLng getLatLng() { + if (geometry == null) { + return null; + } + return new LatLng(geometry.latitude(), geometry.longitude()); + } + /** * Set the geometry of the circle, which represents the location of the circle on the map * @@ -234,6 +246,15 @@ public CircleOptions withGeometry(Point geometry) { return this; } + /** + * Get the geometry of the circle, which represents the location of the circle on the map + * + * @return the location of the circle + */ + public Point getGeometry() { + return geometry; + } + /** * Returns whether this circle is draggable, meaning it can be dragged across the screen when touched and moved. * diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillOptions.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillOptions.java index 11679ac2d..f1660c6fc 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillOptions.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillOptions.java @@ -153,6 +153,25 @@ public FillOptions withLatLngs(List> latLngs) { return this; } + /** + * Get a list of lists of LatLng for the fill, which represents the locations of the fill on the map + * + * @return a list of a lists of the locations of the line in a longitude and latitude pairs + */ + public List> getLatLngs() { + List> points = new ArrayList<>(); + if (geometry != null) { + for (List coordinates : geometry.coordinates()) { + List innerList = new ArrayList<>(); + for (Point point : coordinates) { + innerList.add(new LatLng(point.latitude(), point.longitude())); + } + points.add(innerList); + } + } + return points; + } + /** * Set the geometry of the fill, which represents the location of the fill on the map * @@ -164,6 +183,15 @@ public FillOptions withGeometry(Polygon geometry) { return this; } + /** + * Get the geometry of the fill, which represents the location of the fill on the map + * + * @return the location of the fill + */ + public Polygon getGeometry() { + return geometry; + } + /** * Returns whether this fill is draggable, meaning it can be dragged across the screen when touched and moved. * diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineOptions.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineOptions.java index 61f768abc..41809c863 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineOptions.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineOptions.java @@ -253,6 +253,21 @@ public LineOptions withLatLngs(List latLngs) { return this; } + /** + * Get a list of LatLng for the line, which represents the locations of the line on the map + * + * @return a list of the locations of the line in a longitude and latitude pairs + */ + public List getLatLngs() { + ListlatLngs = new ArrayList<>(); + if (geometry!=null) { + for (Point coordinate : geometry.coordinates()) { + latLngs.add(new LatLng(coordinate.latitude(), coordinate.longitude())); + } + } + return latLngs; + } + /** * Set the geometry of the line, which represents the location of the line on the map * @@ -264,6 +279,15 @@ public LineOptions withGeometry(LineString geometry) { return this; } + /** + * Get the geometry of the line, which represents the location of the line on the map + * + * @return the location of the line + */ + public LineString getGeometry() { + return geometry; + } + /** * Returns whether this line is draggable, meaning it can be dragged across the screen when touched and moved. * diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolOptions.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolOptions.java index b8cf238f0..dcbfaf64a 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolOptions.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolOptions.java @@ -693,6 +693,18 @@ public SymbolOptions withLatLng(LatLng latLng) { return this; } + /** + * Get the LatLng of the symbol, which represents the location of the symbol on the map + * + * @return the location of the symbol in a longitude and latitude pair + */ + public LatLng getLatLng() { + if (geometry == null) { + return null; + } + return new LatLng(geometry.latitude(), geometry.longitude()); + } + /** * Set the geometry of the symbol, which represents the location of the symbol on the map * @@ -704,6 +716,15 @@ public SymbolOptions withGeometry(Point geometry) { return this; } + /** + * Get the geometry of the symbol, which represents the location of the symbol on the map + * + * @return the location of the symbol + */ + public Point getGeometry() { + return geometry; + } + /** * Set the zIndex of the symbol, which represents the place of the symbol on the map inside a layer. *

diff --git a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManagerTest.java b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManagerTest.java index 696a657b0..ba8b9ed6f 100644 --- a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManagerTest.java +++ b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManagerTest.java @@ -209,7 +209,12 @@ public void testDeleteCircle() { @Test public void testGeometryCircle() { circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); - Circle circle = circleManager.create(new CircleOptions().withLatLng(new LatLng(12, 34))); + LatLng latLng = new LatLng(12, 34); + CircleOptions options = new CircleOptions().withLatLng(latLng); + Circle circle = circleManager.create(options); + assertEquals(options.getLatLng(), latLng); + assertEquals(circle.getLatLng(), latLng); + assertEquals(options.getGeometry(), Point.fromLngLat(34, 12)); assertEquals(circle.getGeometry(), Point.fromLngLat(34, 12)); } diff --git a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/FillManagerTest.java b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/FillManagerTest.java index 8b0f77333..03993af2d 100644 --- a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/FillManagerTest.java +++ b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/FillManagerTest.java @@ -250,7 +250,17 @@ public void testGeometryFill() { innerLatLngs.add(new LatLng(-1,-1)); List>latLngs = new ArrayList<>(); latLngs.add(innerLatLngs); - Fill fill = fillManager.create(new FillOptions().withLatLngs(latLngs)); + FillOptions options = new FillOptions().withLatLngs(latLngs); + Fill fill = fillManager.create(options); + assertEquals(options.getLatLngs(), latLngs); + assertEquals(fill.getLatLngs(), latLngs); + assertEquals(options.getGeometry(), Polygon.fromLngLats(new ArrayList>() {{ + add(new ArrayList() {{ + add(Point.fromLngLat(0, 0)); + add(Point.fromLngLat(1, 1)); + add(Point.fromLngLat(-1, -1)); + }}); + }})); assertEquals(fill.getGeometry(), Polygon.fromLngLats(new ArrayList>() {{ add(new ArrayList() {{ add(Point.fromLngLat(0, 0)); diff --git a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/LineManagerTest.java b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/LineManagerTest.java index 689a55961..c491e17b5 100644 --- a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/LineManagerTest.java +++ b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/LineManagerTest.java @@ -229,7 +229,14 @@ public void testGeometryLine() { ListlatLngs = new ArrayList<>(); latLngs.add(new LatLng()); latLngs.add(new LatLng(1,1)); - Line line = lineManager.create(new LineOptions().withLatLngs(latLngs)); + LineOptions options = new LineOptions().withLatLngs(latLngs); + Line line = lineManager.create(options); + assertEquals(options.getLatLngs(), latLngs); + assertEquals(line.getLatLngs(), latLngs); + assertEquals(options.getGeometry(), LineString.fromLngLats(new ArrayList() {{ + add(Point.fromLngLat(0, 0)); + add(Point.fromLngLat(1, 1)); + }})); assertEquals(line.getGeometry(), LineString.fromLngLats(new ArrayList() {{ add(Point.fromLngLat(0, 0)); add(Point.fromLngLat(1, 1)); diff --git a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManagerTest.java b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManagerTest.java index 2456f77b1..d5314cacb 100644 --- a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManagerTest.java +++ b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManagerTest.java @@ -251,7 +251,12 @@ public void testDeleteSymbol() { @Test public void testGeometrySymbol() { symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); - Symbol symbol = symbolManager.create(new SymbolOptions().withLatLng(new LatLng(12, 34))); + LatLng latLng = new LatLng(12, 34); + SymbolOptions options = new SymbolOptions().withLatLng(latLng); + Symbol symbol = symbolManager.create(options); + assertEquals(options.getLatLng(), latLng); + assertEquals(symbol.getLatLng(), latLng); + assertEquals(options.getGeometry(), Point.fromLngLat(34, 12)); assertEquals(symbol.getGeometry(), Point.fromLngLat(34, 12)); }