From c31b7348eedeb41ec19f5acc23fb87cc8caec4fe Mon Sep 17 00:00:00 2001 From: tobrun Date: Tue, 14 May 2019 12:12:08 +0200 Subject: [android] - remove annotations --- .../mapbox/mapboxsdk/annotations/Annotation.java | 153 ----- .../mapboxsdk/annotations/ArrowDirection.java | 31 - .../mapboxsdk/annotations/BaseMarkerOptions.java | 124 ---- .../mapboxsdk/annotations/BasePointCollection.java | 82 --- .../com/mapbox/mapboxsdk/annotations/Bubble.java | 315 --------- .../mapbox/mapboxsdk/annotations/BubbleLayout.java | 350 ---------- .../mapboxsdk/annotations/BubblePopupHelper.java | 35 - .../com/mapbox/mapboxsdk/annotations/Icon.java | 124 ---- .../mapbox/mapboxsdk/annotations/IconFactory.java | 188 ------ .../mapbox/mapboxsdk/annotations/InfoWindow.java | 351 ---------- .../com/mapbox/mapboxsdk/annotations/Marker.java | 278 -------- .../mapboxsdk/annotations/MarkerOptions.java | 195 ------ .../com/mapbox/mapboxsdk/annotations/Polygon.java | 109 ---- .../mapboxsdk/annotations/PolygonOptions.java | 308 --------- .../com/mapbox/mapboxsdk/annotations/Polyline.java | 71 -- .../mapboxsdk/annotations/PolylineOptions.java | 250 ------- .../mapbox/mapboxsdk/annotations/package-info.java | 4 - .../exceptions/IconBitmapChangedException.java | 25 - .../exceptions/InvalidMarkerPositionException.java | 16 - .../exceptions/TooManyIconsException.java | 20 - .../mapbox/mapboxsdk/maps/AnnotationContainer.java | 87 --- .../mapbox/mapboxsdk/maps/AnnotationManager.java | 519 --------------- .../com/mapbox/mapboxsdk/maps/Annotations.java | 25 - .../com/mapbox/mapboxsdk/maps/IconManager.java | 155 ----- .../mapbox/mapboxsdk/maps/InfoWindowManager.java | 96 --- .../mapbox/mapboxsdk/maps/MapGestureDetector.java | 17 +- .../java/com/mapbox/mapboxsdk/maps/MapView.java | 45 +- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 718 --------------------- .../com/mapbox/mapboxsdk/maps/MarkerContainer.java | 146 ----- .../java/com/mapbox/mapboxsdk/maps/Markers.java | 27 - .../java/com/mapbox/mapboxsdk/maps/NativeMap.java | 44 -- .../com/mapbox/mapboxsdk/maps/NativeMapView.java | 181 ------ .../mapbox/mapboxsdk/maps/PolygonContainer.java | 84 --- .../java/com/mapbox/mapboxsdk/maps/Polygons.java | 22 - .../mapbox/mapboxsdk/maps/PolylineContainer.java | 83 --- .../java/com/mapbox/mapboxsdk/maps/Polylines.java | 22 - .../mapboxsdk/maps/ShapeAnnotationContainer.java | 41 -- .../mapbox/mapboxsdk/maps/ShapeAnnotations.java | 13 - .../drawable-hdpi/mapbox_marker_icon_default.png | Bin 1520 -> 0 bytes .../mapbox_markerview_icon_default.png | Bin 1669 -> 0 bytes .../drawable-mdpi/mapbox_marker_icon_default.png | Bin 1010 -> 0 bytes .../mapbox_markerview_icon_default.png | Bin 1115 -> 0 bytes .../drawable-xhdpi/mapbox_marker_icon_default.png | Bin 1995 -> 0 bytes .../mapbox_markerview_icon_default.png | Bin 2163 -> 0 bytes .../drawable-xxhdpi/mapbox_marker_icon_default.png | Bin 2998 -> 0 bytes .../mapbox_markerview_icon_default.png | Bin 3163 -> 0 bytes .../mapbox_marker_icon_default.png | Bin 4006 -> 0 bytes .../mapbox_markerview_icon_default.png | Bin 4071 -> 0 bytes .../main/res/layout/mapbox_infowindow_content.xml | 53 -- .../main/res/layout/mapbox_view_image_marker.xml | 6 - .../mapboxsdk/annotations/AnnotationTest.java | 93 --- .../com/mapbox/mapboxsdk/annotations/IconTest.java | 56 -- .../mapboxsdk/annotations/InfoWindowTest.java | 86 --- .../mapbox/mapboxsdk/annotations/MarkerTest.java | 160 ----- .../mapbox/mapboxsdk/annotations/PolygonTest.java | 75 --- .../mapbox/mapboxsdk/annotations/PolylineTest.java | 75 --- .../mapboxsdk/maps/AnnotationManagerTest.java | 86 --- .../mapboxsdk/maps/MapTouchListenersTest.java | 4 +- .../mapbox/mapboxsdk/maps/IconManagerResolver.java | 42 -- .../com/mapbox/mapboxsdk/maps/MapboxMapTest.java | 477 -------------- .../mapboxsdk/testapp/annotations/IconTest.java | 138 ---- .../mapboxsdk/testapp/annotations/MarkerTest.java | 63 -- .../mapboxsdk/testapp/annotations/PolygonTest.java | 46 -- .../testapp/annotations/PolylineTest.java | 42 -- .../src/main/AndroidManifest.xml | 91 +-- .../annotation/AnimatedSymbolLayerActivity.java | 443 ------------- .../activity/annotation/BulkMarkerActivity.java | 200 ------ .../annotation/DynamicMarkerChangeActivity.java | 120 ---- .../activity/annotation/PolygonActivity.java | 219 ------- .../activity/annotation/PolylineActivity.java | 224 ------- .../annotation/PressForMarkerActivity.java | 151 ----- .../activity/camera/GestureDetectorActivity.java | 42 +- .../activity/camera/LatLngBoundsActivity.java | 35 +- ...ueryRenderedFeaturesBoxSymbolCountActivity.java | 8 +- .../QueryRenderedFeaturesPropertiesActivity.java | 145 +---- .../activity/fragment/FragmentBackStackActivity.kt | 5 +- .../DynamicInfoWindowAdapterActivity.java | 158 ----- .../activity/infowindow/InfoWindowActivity.java | 199 ------ .../infowindow/InfoWindowAdapterActivity.java | 128 ---- .../maplayout/LatLngBoundsForCameraActivity.java | 53 +- .../activity/maplayout/MapPaddingActivity.java | 19 +- .../snapshot/MapSnapshotterMarkerActivity.java | 6 +- .../style/AnimatedSymbolLayerActivity.java | 443 +++++++++++++ .../activity/style/DraggableMarkerActivity.kt | 8 +- .../testapp/model/annotations/CityStateMarker.java | 18 - .../model/annotations/CityStateMarkerOptions.java | 68 -- .../testapp/model/annotations/CountryMarker.java | 24 - .../model/annotations/CountryMarkerOptions.java | 75 --- .../mapbox/mapboxsdk/testapp/utils/IconUtils.java | 31 - .../main/res/drawable-hdpi/mapbox_marker_icon.png | Bin 0 -> 1669 bytes .../main/res/drawable-mdpi/mapbox_marker_icon.png | Bin 0 -> 1115 bytes .../main/res/drawable-xhdpi/mapbox_marker_icon.png | Bin 0 -> 2163 bytes .../res/drawable-xxhdpi/mapbox_marker_icon.png | Bin 0 -> 3163 bytes .../res/drawable-xxxhdpi/mapbox_marker_icon.png | Bin 0 -> 4071 bytes .../src/main/res/values/categories.xml | 1 - .../src/main/res/values/descriptions.xml | 10 +- .../src/main/res/values/titles.xml | 8 - platform/android/core-files.json | 7 - platform/android/src/annotation/marker.cpp | 23 - platform/android/src/annotation/marker.hpp | 28 - platform/android/src/annotation/multi_point.hpp | 34 - platform/android/src/annotation/polygon.cpp | 40 -- platform/android/src/annotation/polygon.hpp | 21 - platform/android/src/annotation/polyline.cpp | 31 - platform/android/src/annotation/polyline.hpp | 21 - platform/android/src/jni.cpp | 8 - platform/android/src/native_map_view.cpp | 170 ----- platform/android/src/native_map_view.hpp | 27 - 108 files changed, 600 insertions(+), 9598 deletions(-) delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/ArrowDirection.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerOptions.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BasePointCollection.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Bubble.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubblePopupHelper.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/package-info.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidMarkerPositionException.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TooManyIconsException.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationContainer.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Annotations.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Markers.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Polygons.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Polylines.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotationContainer.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotations.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_marker_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_markerview_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_marker_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_markerview_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_marker_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_markerview_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_marker_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_markerview_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_marker_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_markerview_icon_default.png delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_view_image_marker.xml delete mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/AnnotationTest.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/PolygonTest.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/PolylineTest.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/IconManagerResolver.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/PolygonTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/PolylineTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedSymbolLayerActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PressForMarkerActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/AnimatedSymbolLayerActivity.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CityStateMarker.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CityStateMarkerOptions.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarker.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerOptions.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IconUtils.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-hdpi/mapbox_marker_icon.png create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-mdpi/mapbox_marker_icon.png create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xhdpi/mapbox_marker_icon.png create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/mapbox_marker_icon.png create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/mapbox_marker_icon.png delete mode 100644 platform/android/src/annotation/marker.cpp delete mode 100644 platform/android/src/annotation/marker.hpp delete mode 100644 platform/android/src/annotation/multi_point.hpp delete mode 100644 platform/android/src/annotation/polygon.cpp delete mode 100644 platform/android/src/annotation/polygon.hpp delete mode 100644 platform/android/src/annotation/polyline.cpp delete mode 100644 platform/android/src/annotation/polyline.hpp diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java deleted file mode 100644 index 8ea2266499..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.support.annotation.NonNull; - -import android.support.annotation.Nullable; - -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; - -/** - * Annotation is an overlay on top of a Map. - *

- * Known subclasses are {@link Polygon}, {@link Polyline} and {@link Marker}. - *

- *

- * This class manages attachment to a map and identification, but does not require - * content to be placed at a geographical point. - *

- * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public abstract class Annotation implements Comparable { - - /** - *

- * The annotation id - *

- * Internal C++ id is stored as unsigned int. - */ - private long id = -1; // -1 unless added to a MapView - protected MapboxMap mapboxMap; - protected MapView mapView; - - protected Annotation() { - } - - /** - *

- * Gets the annotation's unique ID. - *

- * This ID is unique for a MapView instance and is suitable for associating your own extra - * data with. - * - * @return the assigned id. - */ - public long getId() { - return id; - } - - /** - * Do not use this method, used internally by the SDK. - */ - public void remove() { - if (mapboxMap == null) { - return; - } - mapboxMap.removeAnnotation(this); - } - - /** - * Do not use this method, used internally by the SDK. - * - * @param id the assigned id - */ - public void setId(long id) { - this.id = id; - } - - /** - * Do not use this method, used internally by the SDK. - * - * @param mapboxMap the hosting mapbox map - */ - public void setMapboxMap(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; - } - - /** - * Gets the hosting mapbox map. - * - * @return the MapboxMap - */ - protected MapboxMap getMapboxMap() { - return mapboxMap; - } - - /** - * Do not use this method, used internally by the SDK. - * - * @param mapView the hosting map view - */ - public void setMapView(MapView mapView) { - this.mapView = mapView; - } - - /** - * Gets the hosting map view. - * - * @return The MapView - */ - protected MapView getMapView() { - return mapView; - } - - /** - * Compares this Annotation object with another Annotation. - * - * @param annotation Another Annotation to compare with this object. - * @return returns 0 if id's match, 1 if id is lower, -1 if id is higher of another Annotation - */ - @Override - public int compareTo(@NonNull Annotation annotation) { - if (id < annotation.getId()) { - return 1; - } else if (id > annotation.getId()) { - return -1; - } - return 0; - } - - /** - * Checks if this Annotation object is equal to another Annotation. - * - * @param object Another Annotation to check equality with this object. - * @return returns true both id's match else returns false. - */ - @Override - public boolean equals(@Nullable Object object) { - if (this == object) { - return true; - } - if (object == null || !(object instanceof Annotation)) { - return false; - } - Annotation that = (Annotation) object; - return id == that.getId(); - } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - return (int) (getId() ^ (getId() >>> 32)); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/ArrowDirection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/ArrowDirection.java deleted file mode 100644 index 220544815e..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/ArrowDirection.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.support.annotation.IntDef; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Deprecated -class ArrowDirection { - @IntDef( {LEFT, RIGHT, TOP, BOTTOM}) - @Retention(RetentionPolicy.SOURCE) - @interface Value { - } - - static final int LEFT = 0; - static final int RIGHT = 1; - static final int TOP = 2; - static final int BOTTOM = 3; - - @Value - private final int value; - - ArrowDirection(@Value int value) { - this.value = value; - } - - @Value - public int getValue() { - return value; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerOptions.java deleted file mode 100644 index 384ff8c0ac..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerOptions.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.geometry.LatLng; - -/** - * Abstract builder class for composing custom Marker objects. - *

- * Extending this class requires implementing Parceable interface. - * - * @param Type of the marker to be composed - * @param Type of the builder to be used for composing a custom Marker - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public abstract class BaseMarkerOptions> implements Parcelable { - - protected LatLng position; - protected String snippet; - protected String title; - protected Icon icon; - - /** - * Set the geographical location of the Marker. - * - * @param position the location to position the {@link Marker}. - * @return the object for which the method was called. - */ - public T position(LatLng position) { - this.position = position; - return getThis(); - } - - /** - * Set the snippet of the Marker. - * - * @param snippet the snippet of the {@link Marker}. - * @return the object for which the method was called. - */ - public T snippet(String snippet) { - this.snippet = snippet; - return getThis(); - } - - /** - * Set the title of the Marker. - * - * @param title the title of the {@link Marker}. - * @return the object for which the method was called. - */ - public T title(String title) { - this.title = title; - return getThis(); - } - - /** - * Set the icon of the Marker. - * - * @param icon the icon of the {@link Marker}. - * @return the object for which the method was called. - */ - public T icon(Icon icon) { - this.icon = icon; - return getThis(); - } - - /** - * Set the icon of the Marker. - * - * @param icon the icon of the {@link Marker}. - * @return the object for which the method was called. - */ - public T setIcon(Icon icon) { - return icon(icon); - } - - /** - * Set the geographical location of the Marker. - * - * @param position the location to position the {@link Marker}. - * @return the object for which the method was called. - */ - public T setPosition(LatLng position) { - return position(position); - } - - /** - * Set the snippet of the Marker. - * - * @param snippet the snippet of the {@link Marker}. - * @return the object for which the method was called. - */ - public T setSnippet(String snippet) { - return snippet(snippet); - } - - /** - * Set the title of the Marker. - * - * @param title the title of the {@link Marker}. - * @return the object for which the method was called. - */ - public T setTitle(String title) { - return title(title); - } - - /** - * Get the instance of the object for which this method was called. - * - * @return the object for which the this method was called. - */ - public abstract T getThis(); - - /** - * Get the Marker. - * - * @return the Marker created from this builder. - */ - public abstract U getMarker(); - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BasePointCollection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BasePointCollection.java deleted file mode 100644 index b94721a80a..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BasePointCollection.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.support.annotation.Keep; - -import android.support.annotation.NonNull; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import java.util.ArrayList; -import java.util.List; - -/** - * Multipoint is an abstract annotation for combining geographical locations. - * - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public abstract class BasePointCollection extends Annotation { - - @Keep - private List points; - @Keep - private float alpha = 1.0f; - - protected BasePointCollection() { - super(); - points = new ArrayList<>(); - } - - /** - * Returns a copy of the points. - * - * @return A {@link List} of points. - */ - @NonNull - public List getPoints() { - return new ArrayList<>(points); - } - - /** - * Sets the points of this polyline. This method will take a copy of the points, so further - * mutations to points will have no effect on this polyline. - * - * @param points A {@link List} of {@link LatLng} points making up the polyline. - */ - public void setPoints(@NonNull List points) { - this.points = new ArrayList<>(points); - update(); - } - - /** - * Add a point to the polyline. - * - * @param point A {@link LatLng} point to be added. - */ - public void addPoint(LatLng point) { - points.add(point); - update(); - } - - /** - * Value between 0 and 1 defining the polyline alpha. - * - * @return float value between 0 and 1. - */ - public float getAlpha() { - return alpha; - } - - /** - * Set this {@link BasePointCollection}s alpha. - * - * @param alpha float value between 0 and 1. - */ - public void setAlpha(float alpha) { - this.alpha = alpha; - update(); - } - - abstract void update(); -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Bubble.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Bubble.java deleted file mode 100644 index 0768f9c2e4..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Bubble.java +++ /dev/null @@ -1,315 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.Canvas; -import android.graphics.ColorFilter; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.PixelFormat; -import android.graphics.Rect; -import android.graphics.RectF; -import android.graphics.drawable.Drawable; -import android.support.annotation.NonNull; - -@Deprecated -class Bubble extends Drawable { - - private RectF rect; - private float arrowWidth; - private float arrowHeight; - private float arrowPosition; - private float cornersRadius; - @NonNull - private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); - private float strokeWidth; - private Paint strokePaint; - private Path strokePath; - @NonNull - private Path path = new Path(); - - Bubble(@NonNull RectF rect, @NonNull ArrowDirection arrowDirection, float arrowWidth, float arrowHeight, - float arrowPosition, float cornersRadius, int bubbleColor, float strokeWidth, int strokeColor) { - this.rect = rect; - this.arrowWidth = arrowWidth; - this.arrowHeight = arrowHeight; - this.arrowPosition = arrowPosition; - this.cornersRadius = cornersRadius; - paint.setColor(bubbleColor); - this.strokeWidth = strokeWidth; - - if (strokeWidth > 0) { - strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); - strokePaint.setColor(strokeColor); - strokePath = new Path(); - initPath(arrowDirection, path, strokeWidth); - initPath(arrowDirection, strokePath, 0); - } else { - initPath(arrowDirection, path, 0); - } - } - - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - } - - @Override - public void draw(@NonNull Canvas canvas) { - if (strokeWidth > 0) { - canvas.drawPath(strokePath, strokePaint); - } - canvas.drawPath(path, paint); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - @Override - public void setAlpha(int alpha) { - paint.setAlpha(alpha); - } - - @Override - public void setColorFilter(ColorFilter cf) { - paint.setColorFilter(cf); - } - - @Override - public int getIntrinsicWidth() { - return (int) rect.width(); - } - - @Override - public int getIntrinsicHeight() { - return (int) rect.height(); - } - - private void initPath(@NonNull ArrowDirection arrowDirection, @NonNull Path path, float strokeWidth) { - switch (arrowDirection.getValue()) { - case ArrowDirection.LEFT: - if (cornersRadius <= 0) { - initLeftSquarePath(rect, path, strokeWidth); - break; - } - - if (strokeWidth > 0 && strokeWidth > cornersRadius) { - initLeftSquarePath(rect, path, strokeWidth); - break; - } - - initLeftRoundedPath(rect, path, strokeWidth); - break; - case ArrowDirection.TOP: - if (cornersRadius <= 0) { - initTopSquarePath(rect, path, strokeWidth); - break; - } - - if (strokeWidth > 0 && strokeWidth > cornersRadius) { - initTopSquarePath(rect, path, strokeWidth); - break; - } - - initTopRoundedPath(rect, path, strokeWidth); - break; - case ArrowDirection.RIGHT: - if (cornersRadius <= 0) { - initRightSquarePath(rect, path, strokeWidth); - break; - } - - if (strokeWidth > 0 && strokeWidth > cornersRadius) { - initRightSquarePath(rect, path, strokeWidth); - break; - } - - initRightRoundedPath(rect, path, strokeWidth); - break; - case ArrowDirection.BOTTOM: - if (cornersRadius <= 0) { - initBottomSquarePath(rect, path, strokeWidth); - break; - } - - if (strokeWidth > 0 && strokeWidth > cornersRadius) { - initBottomSquarePath(rect, path, strokeWidth); - break; - } - - initBottomRoundedPath(rect, path, strokeWidth); - break; - } - } - - private void initLeftSquarePath(@NonNull RectF rect, @NonNull Path path, float strokeWidth) { - path.moveTo(arrowWidth + rect.left + strokeWidth, rect.top + strokeWidth); - path.lineTo(rect.width() - strokeWidth, rect.top + strokeWidth); - - path.lineTo(rect.right - strokeWidth, rect.bottom - strokeWidth); - - path.lineTo(rect.left + arrowWidth + strokeWidth, rect.bottom - strokeWidth); - - path.lineTo(rect.left + arrowWidth + strokeWidth, arrowHeight + arrowPosition - (strokeWidth / 2)); - path.lineTo(rect.left + strokeWidth + strokeWidth, arrowPosition + arrowHeight / 2); - path.lineTo(rect.left + arrowWidth + strokeWidth, arrowPosition + (strokeWidth / 2)); - - path.lineTo(rect.left + arrowWidth + strokeWidth, rect.top + strokeWidth); - - path.close(); - } - - private void initLeftRoundedPath(@NonNull RectF rect, @NonNull Path path, float strokeWidth) { - path.moveTo(arrowWidth + rect.left + cornersRadius + strokeWidth, rect.top + strokeWidth); - path.lineTo(rect.width() - cornersRadius - strokeWidth, rect.top + strokeWidth); - path.arcTo(new RectF(rect.right - cornersRadius, rect.top + strokeWidth, rect.right - strokeWidth, - cornersRadius + rect.top), 270, 90); - - path.lineTo(rect.right - strokeWidth, rect.bottom - cornersRadius - strokeWidth); - path.arcTo(new RectF(rect.right - cornersRadius, rect.bottom - cornersRadius, - rect.right - strokeWidth, rect.bottom - strokeWidth), 0, 90); - - path.lineTo(rect.left + arrowWidth + cornersRadius + strokeWidth, rect.bottom - strokeWidth); - - path.arcTo(new RectF(rect.left + arrowWidth + strokeWidth, rect.bottom - cornersRadius, - cornersRadius + rect.left + arrowWidth, rect.bottom - strokeWidth), 90, 90); - - path.lineTo(rect.left + arrowWidth + strokeWidth, arrowHeight + arrowPosition - (strokeWidth / 2)); - - path.lineTo(rect.left + strokeWidth + strokeWidth, arrowPosition + arrowHeight / 2); - - path.lineTo(rect.left + arrowWidth + strokeWidth, arrowPosition + (strokeWidth / 2)); - - path.lineTo(rect.left + arrowWidth + strokeWidth, rect.top + cornersRadius + strokeWidth); - - path.arcTo(new RectF(rect.left + arrowWidth + strokeWidth, rect.top + strokeWidth, cornersRadius - + rect.left + arrowWidth, cornersRadius + rect.top), 180, 90); - - path.close(); - } - - private void initTopSquarePath(@NonNull RectF rect, @NonNull Path path, float strokeWidth) { - path.moveTo(rect.left + arrowPosition + strokeWidth, rect.top + arrowHeight + strokeWidth); - - path.lineTo(rect.left + arrowPosition + (strokeWidth / 2), rect.top + arrowHeight + strokeWidth); - path.lineTo(rect.left + arrowWidth / 2 + arrowPosition, rect.top + strokeWidth + strokeWidth); - path.lineTo(rect.left + arrowWidth + arrowPosition - (strokeWidth / 2), rect.top + arrowHeight + strokeWidth); - path.lineTo(rect.right - strokeWidth, rect.top + arrowHeight + strokeWidth); - - path.lineTo(rect.right - strokeWidth, rect.bottom - strokeWidth); - - path.lineTo(rect.left + strokeWidth, rect.bottom - strokeWidth); - - path.lineTo(rect.left + strokeWidth, rect.top + arrowHeight + strokeWidth); - - path.lineTo(rect.left + arrowPosition + strokeWidth, rect.top + arrowHeight + strokeWidth); - - path.close(); - } - - private void initTopRoundedPath(@NonNull RectF rect, @NonNull Path path, float strokeWidth) { - path.moveTo(rect.left + Math.min(arrowPosition, cornersRadius) + strokeWidth, rect.top + arrowHeight - + strokeWidth); - path.lineTo(rect.left + arrowPosition + (strokeWidth / 2), rect.top + arrowHeight + strokeWidth); - path.lineTo(rect.left + arrowWidth / 2 + arrowPosition, rect.top + strokeWidth + strokeWidth); - path.lineTo(rect.left + arrowWidth + arrowPosition - (strokeWidth / 2), rect.top + arrowHeight + strokeWidth); - path.lineTo(rect.right - cornersRadius - strokeWidth, rect.top + arrowHeight + strokeWidth); - - path.arcTo(new RectF(rect.right - cornersRadius, - rect.top + arrowHeight + strokeWidth, rect.right - strokeWidth, cornersRadius + rect.top + arrowHeight), - 270, 90); - path.lineTo(rect.right - strokeWidth, rect.bottom - cornersRadius - strokeWidth); - - path.arcTo(new RectF(rect.right - cornersRadius, rect.bottom - cornersRadius, - rect.right - strokeWidth, rect.bottom - strokeWidth), 0, 90); - path.lineTo(rect.left + cornersRadius + strokeWidth, rect.bottom - strokeWidth); - - path.arcTo(new RectF(rect.left + strokeWidth, rect.bottom - cornersRadius, - cornersRadius + rect.left, rect.bottom - strokeWidth), 90, 90); - - path.lineTo(rect.left + strokeWidth, rect.top + arrowHeight + cornersRadius + strokeWidth); - - path.arcTo(new RectF(rect.left + strokeWidth, rect.top + arrowHeight + strokeWidth, cornersRadius - + rect.left, cornersRadius + rect.top + arrowHeight), 180, 90); - - path.close(); - } - - private void initRightSquarePath(@NonNull RectF rect, @NonNull Path path, float strokeWidth) { - path.moveTo(rect.left + strokeWidth, rect.top + strokeWidth); - path.lineTo(rect.width() - arrowWidth - strokeWidth, rect.top + strokeWidth); - - path.lineTo(rect.right - arrowWidth - strokeWidth, arrowPosition + (strokeWidth / 2)); - path.lineTo(rect.right - strokeWidth - strokeWidth, arrowPosition + arrowHeight / 2); - path.lineTo(rect.right - arrowWidth - strokeWidth, arrowPosition + arrowHeight - (strokeWidth / 2)); - - path.lineTo(rect.right - arrowWidth - strokeWidth, rect.bottom - strokeWidth); - - path.lineTo(rect.left + strokeWidth, rect.bottom - strokeWidth); - path.lineTo(rect.left + strokeWidth, rect.top + strokeWidth); - - path.close(); - } - - private void initRightRoundedPath(@NonNull RectF rect, @NonNull Path path, float strokeWidth) { - path.moveTo(rect.left + cornersRadius + strokeWidth, rect.top + strokeWidth); - path.lineTo(rect.width() - cornersRadius - arrowWidth - strokeWidth, rect.top + strokeWidth); - path.arcTo(new RectF(rect.right - cornersRadius - arrowWidth, - rect.top + strokeWidth, rect.right - arrowWidth - strokeWidth, cornersRadius + rect.top), 270, 90); - - path.lineTo(rect.right - arrowWidth - strokeWidth, arrowPosition + (strokeWidth / 2)); - path.lineTo(rect.right - strokeWidth - strokeWidth, arrowPosition + arrowHeight / 2); - path.lineTo(rect.right - arrowWidth - strokeWidth, arrowPosition + arrowHeight - (strokeWidth / 2)); - path.lineTo(rect.right - arrowWidth - strokeWidth, rect.bottom - cornersRadius - strokeWidth); - - path.arcTo(new RectF(rect.right - cornersRadius - arrowWidth, rect.bottom - cornersRadius, - rect.right - arrowWidth - strokeWidth, rect.bottom - strokeWidth), 0, 90); - path.lineTo(rect.left + arrowWidth + strokeWidth, rect.bottom - strokeWidth); - - path.arcTo(new RectF(rect.left + strokeWidth, rect.bottom - cornersRadius, - cornersRadius + rect.left, rect.bottom - strokeWidth), 90, 90); - - path.arcTo(new RectF(rect.left + strokeWidth, rect.top + strokeWidth, cornersRadius - + rect.left, cornersRadius + rect.top), 180, 90); - path.close(); - } - - private void initBottomSquarePath(@NonNull RectF rect, @NonNull Path path, float strokeWidth) { - path.moveTo(rect.left + strokeWidth, rect.top + strokeWidth); - path.lineTo(rect.right - strokeWidth, rect.top + strokeWidth); - path.lineTo(rect.right - strokeWidth, rect.bottom - arrowHeight - strokeWidth); - - path.lineTo(rect.left + arrowWidth + arrowPosition - (strokeWidth / 2), rect.bottom - arrowHeight - strokeWidth); - path.lineTo(rect.left + arrowPosition + arrowWidth / 2, rect.bottom - strokeWidth - strokeWidth); - path.lineTo(rect.left + arrowPosition + (strokeWidth / 2), rect.bottom - arrowHeight - strokeWidth); - path.lineTo(rect.left + arrowPosition + strokeWidth, rect.bottom - arrowHeight - strokeWidth); - - path.lineTo(rect.left + strokeWidth, rect.bottom - arrowHeight - strokeWidth); - path.lineTo(rect.left + strokeWidth, rect.top + strokeWidth); - path.close(); - } - - private void initBottomRoundedPath(@NonNull RectF rect, @NonNull Path path, float strokeWidth) { - path.moveTo(rect.left + cornersRadius + strokeWidth, rect.top + strokeWidth); - path.lineTo(rect.width() - cornersRadius - strokeWidth, rect.top + strokeWidth); - path.arcTo(new RectF(rect.right - cornersRadius, - rect.top + strokeWidth, rect.right - strokeWidth, cornersRadius + rect.top), 270, 90); - - path.lineTo(rect.right - strokeWidth, rect.bottom - arrowHeight - cornersRadius - strokeWidth); - path.arcTo(new RectF(rect.right - cornersRadius, rect.bottom - cornersRadius - arrowHeight, - rect.right - strokeWidth, rect.bottom - arrowHeight - strokeWidth), 0, 90); - - path.lineTo(rect.left + arrowWidth + arrowPosition - (strokeWidth / 2), rect.bottom - arrowHeight - strokeWidth); - path.lineTo(rect.left + arrowPosition + arrowWidth / 2, rect.bottom - strokeWidth - strokeWidth); - path.lineTo(rect.left + arrowPosition + (strokeWidth / 2), rect.bottom - arrowHeight - strokeWidth); - path.lineTo(rect.left + Math.min(cornersRadius, arrowPosition) + strokeWidth, rect.bottom - arrowHeight - - strokeWidth); - - path.arcTo(new RectF(rect.left + strokeWidth, rect.bottom - cornersRadius - arrowHeight, - cornersRadius + rect.left, rect.bottom - arrowHeight - strokeWidth), 90, 90); - path.lineTo(rect.left + strokeWidth, rect.top + cornersRadius + strokeWidth); - path.arcTo(new RectF(rect.left + strokeWidth, rect.top + strokeWidth, cornersRadius - + rect.left, cornersRadius + rect.top), 180, 90); - path.close(); - } -} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java deleted file mode 100644 index f4a1484f8a..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java +++ /dev/null @@ -1,350 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.RectF; -import android.support.annotation.NonNull; -import android.util.AttributeSet; -import android.util.DisplayMetrics; -import android.widget.LinearLayout; - -import com.mapbox.mapboxsdk.R; - -/** - * Bubble View for Android with custom stroke width and color, arrow size, position and direction. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public class BubbleLayout extends LinearLayout { - - public static final float DEFAULT_STROKE_WIDTH = -1; - private ArrowDirection arrowDirection; - private float arrowWidth; - private float arrowHeight; - private float arrowPosition; - private float cornersRadius; - private Bubble bubble; - private int bubbleColor; - private float strokeWidth; - private int strokeColor; - - /** - * Creates an instance of bubble layout. - * - * @param context The context used to inflate this bubble layout - */ - public BubbleLayout(@NonNull Context context) { - this(context, null, 0); - } - - /** - * Creates an instance of bubble layout. - * - * @param context The context used to inflate this bubble layout - * @param attrs The attribute set to initialise this bubble layout from - */ - public BubbleLayout(@NonNull Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - /** - * Creates an instance of bubble layout. - * - * @param context The context used to inflate this bubble layout - * @param attrs The attribute set to initialise this bubble layout from - * @param defStyleAttr The default style to apply this bubble layout with - */ - public BubbleLayout(@NonNull Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - - TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.mapbox_BubbleLayout); - @ArrowDirection.Value - int location = a.getInt(R.styleable.mapbox_BubbleLayout_mapbox_bl_arrowDirection, - ArrowDirection.LEFT); - arrowDirection = new ArrowDirection(location); - arrowWidth = a.getDimension(R.styleable.mapbox_BubbleLayout_mapbox_bl_arrowWidth, - convertDpToPixel(8, context)); - arrowHeight = a.getDimension(R.styleable.mapbox_BubbleLayout_mapbox_bl_arrowHeight, - convertDpToPixel(8, context)); - arrowPosition = a.getDimension(R.styleable.mapbox_BubbleLayout_mapbox_bl_arrowPosition, - convertDpToPixel(12, context)); - cornersRadius = a.getDimension(R.styleable.mapbox_BubbleLayout_mapbox_bl_cornersRadius, 0); - bubbleColor = a.getColor(R.styleable.mapbox_BubbleLayout_mapbox_bl_bubbleColor, Color.WHITE); - strokeWidth = - a.getDimension(R.styleable.mapbox_BubbleLayout_mapbox_bl_strokeWidth, DEFAULT_STROKE_WIDTH); - strokeColor = a.getColor(R.styleable.mapbox_BubbleLayout_mapbox_bl_strokeColor, Color.GRAY); - - a.recycle(); - initPadding(); - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - initDrawable(0, getWidth(), 0, getHeight()); - } - - @Override - protected void dispatchDraw(@NonNull Canvas canvas) { - if (bubble != null) { - bubble.draw(canvas); - } - super.dispatchDraw(canvas); - } - - static float convertDpToPixel(float dp, Context context) { - DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - return dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); - } - - /** - * Get the arrow direction. - * - * @return the arrow direction - */ - public ArrowDirection getArrowDirection() { - return arrowDirection; - } - - /** - * Set the arrow direction. - * - * @param arrowDirection The direction of the arrow - * @return this - */ - @NonNull - public BubbleLayout setArrowDirection(ArrowDirection arrowDirection) { - resetPadding(); - this.arrowDirection = arrowDirection; - initPadding(); - return this; - } - - /** - * Get the arrow width. - * - * @return the width of the arrow - */ - public float getArrowWidth() { - return arrowWidth; - } - - /** - * Set the arrow width. - * - * @param arrowWidth The width of the arrow - * @return this - */ - @NonNull - public BubbleLayout setArrowWidth(float arrowWidth) { - resetPadding(); - this.arrowWidth = arrowWidth; - initPadding(); - return this; - } - - /** - * Get the arrow height - * - * @return the height of the arrow - */ - public float getArrowHeight() { - return arrowHeight; - } - - /** - * Set the arrow height. - * - * @param arrowHeight The height of the arrow - * @return this - */ - @NonNull - public BubbleLayout setArrowHeight(float arrowHeight) { - resetPadding(); - this.arrowHeight = arrowHeight; - initPadding(); - return this; - } - - /** - * Get the arrow position. - * - * @return the arrow position - */ - public float getArrowPosition() { - return arrowPosition; - } - - /** - * Get the arrow position. - * - * @param arrowPosition The arrow position - * @return this - */ - @NonNull - public BubbleLayout setArrowPosition(float arrowPosition) { - resetPadding(); - this.arrowPosition = arrowPosition; - initPadding(); - return this; - } - - /** - * Get the corner radius - * - * @return the corner radius - */ - public float getCornersRadius() { - return cornersRadius; - } - - /** - * Set the corner radius - * - * @param cornersRadius The corner radius - * @return this - */ - @NonNull - public BubbleLayout setCornersRadius(float cornersRadius) { - this.cornersRadius = cornersRadius; - requestLayout(); - return this; - } - - /** - * Get the bubble color. - * - * @return the bubble color - */ - public int getBubbleColor() { - return bubbleColor; - } - - /** - * Set the bubble color. - * - * @param bubbleColor The buble color - * @return this - */ - @NonNull - public BubbleLayout setBubbleColor(int bubbleColor) { - this.bubbleColor = bubbleColor; - requestLayout(); - return this; - } - - /** - * Get stroke width. - * - * @return the stroke width - */ - public float getStrokeWidth() { - return strokeWidth; - } - - /** - * Set the stroke width. - * - * @param strokeWidth The stroke width - * @return this - */ - @NonNull - public BubbleLayout setStrokeWidth(float strokeWidth) { - resetPadding(); - this.strokeWidth = strokeWidth; - initPadding(); - return this; - } - - /** - * Get the stroke color. - * - * @return the stroke color - */ - public int getStrokeColor() { - return strokeColor; - } - - /** - * Set the stroke color. - * - * @param strokeColor The stroke color - * @return this - */ - @NonNull - public BubbleLayout setStrokeColor(int strokeColor) { - this.strokeColor = strokeColor; - requestLayout(); - return this; - } - - private void initPadding() { - int paddingLeft = getPaddingLeft(); - int paddingRight = getPaddingRight(); - int paddingTop = getPaddingTop(); - int paddingBottom = getPaddingBottom(); - switch (arrowDirection.getValue()) { - case ArrowDirection.LEFT: - paddingLeft += arrowWidth; - break; - case ArrowDirection.RIGHT: - paddingRight += arrowWidth; - break; - case ArrowDirection.TOP: - paddingTop += arrowHeight; - break; - case ArrowDirection.BOTTOM: - paddingBottom += arrowHeight; - break; - } - if (strokeWidth > 0) { - paddingLeft += strokeWidth; - paddingRight += strokeWidth; - paddingTop += strokeWidth; - paddingBottom += strokeWidth; - } - setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); - } - - private void initDrawable(int left, int right, int top, int bottom) { - if (right < left || bottom < top) { - return; - } - - RectF rectF = new RectF(left, top, right, bottom); - bubble = new Bubble(rectF, arrowDirection, arrowWidth, arrowHeight, arrowPosition, cornersRadius, - bubbleColor, strokeWidth, strokeColor); - } - - private void resetPadding() { - int paddingLeft = getPaddingLeft(); - int paddingRight = getPaddingRight(); - int paddingTop = getPaddingTop(); - int paddingBottom = getPaddingBottom(); - switch (arrowDirection.getValue()) { - case ArrowDirection.LEFT: - paddingLeft -= arrowWidth; - break; - case ArrowDirection.RIGHT: - paddingRight -= arrowWidth; - break; - case ArrowDirection.TOP: - paddingTop -= arrowHeight; - break; - case ArrowDirection.BOTTOM: - paddingBottom -= arrowHeight; - break; - } - if (strokeWidth > 0) { - paddingLeft -= strokeWidth; - paddingRight -= strokeWidth; - paddingTop -= strokeWidth; - paddingBottom -= strokeWidth; - } - setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubblePopupHelper.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubblePopupHelper.java deleted file mode 100644 index 055bfe5368..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubblePopupHelper.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.support.annotation.NonNull; -import android.view.ViewGroup; -import android.widget.PopupWindow; - -import com.mapbox.mapboxsdk.R; - -@Deprecated -class BubblePopupHelper { - - @NonNull - static PopupWindow create(@NonNull Context context, @NonNull BubbleLayout bubbleLayout) { - PopupWindow popupWindow = new PopupWindow(context); - - popupWindow.setContentView(bubbleLayout); - popupWindow.setOutsideTouchable(true); - popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); - popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); - popupWindow.setAnimationStyle(android.R.style.Animation_Dialog); - // change background color to transparent - Drawable drawable; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - drawable = context.getDrawable(R.drawable.mapbox_popup_window_transparent); - } else { - drawable = context.getResources().getDrawable(R.drawable.mapbox_popup_window_transparent); - } - popupWindow.setBackgroundDrawable(drawable); - - return popupWindow; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java deleted file mode 100644 index 7ace113505..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.Bitmap; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.util.DisplayMetrics; - -import java.nio.ByteBuffer; - -/** - * Icon is the visual representation of a Marker on a MapView. - * - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public class Icon { - - private Bitmap mBitmap; - private String mId; - - Icon(String id, Bitmap bitmap) { - mId = id; - mBitmap = bitmap; - } - - /** - * String identifier for this icon. - * - * @return String identifier for this icon. - */ - public String getId() { - return mId; - } - - /** - * Get the bitmap being used for this icon. - * - * @return The bitmap being used for the icon. - */ - public Bitmap getBitmap() { - if (mBitmap != null && mBitmap.getConfig() != Bitmap.Config.ARGB_8888) { - mBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, false); - } - return mBitmap; - } - - /** - * Get the icon bitmap scale. - *

- * Requires the bitmap to be set before calling this method. - *

- * - * @return the scale of the bitmap - */ - public float getScale() { - if (mBitmap == null) { - throw new IllegalStateException("Required to set a Icon before calling getScale"); - } - float density = mBitmap.getDensity(); - if (density == Bitmap.DENSITY_NONE) { - density = DisplayMetrics.DENSITY_DEFAULT; - } - return density / DisplayMetrics.DENSITY_DEFAULT; - } - - /** - * Get the icon bitmap bytes. - *

- * Requires the bitmap to be set before calling this method. - *

- * - * @return the bytes of the bitmap - */ - @NonNull - public byte[] toBytes() { - if (mBitmap == null) { - throw new IllegalStateException("Required to set a Icon before calling toBytes"); - } - ByteBuffer buffer = ByteBuffer.allocate(mBitmap.getRowBytes() * mBitmap.getHeight()); - mBitmap.copyPixelsToBuffer(buffer); - return buffer.array(); - } - - /** - * Compares this icon object with another icon and determines if they match. - * - * @param object Another iconi to compare with this object. - * @return True if the icon being passed in matches this icon object. Else, false. - */ - @Override - public boolean equals(@Nullable Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - - Icon icon = (Icon) object; - return mBitmap.equals(icon.mBitmap) && mId.equals(icon.mId); - } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - int result = 0; - if (mBitmap != null) { - result = mBitmap.hashCode(); - } - if (mId != null) { - result = 31 * result + mId.hashCode(); - } - return result; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java deleted file mode 100644 index 9f0fa62cdd..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.support.annotation.DrawableRes; -import android.support.annotation.NonNull; -import android.util.DisplayMetrics; -import android.view.WindowManager; - -import com.mapbox.mapboxsdk.MapStrictMode; -import com.mapbox.mapboxsdk.R; -import com.mapbox.mapboxsdk.exceptions.TooManyIconsException; -import com.mapbox.mapboxsdk.utils.BitmapUtils; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; - -/** - * Factory for creating Icons from bitmap images. - *

- * icon is used to display bitmaps on top of the map using {@link Marker}. - *

- * - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public final class IconFactory { - - private static final String ICON_ID_PREFIX = "com.mapbox.icons.icon_"; - - private Context context; - @SuppressLint("StaticFieldLeak") - private static IconFactory instance; - private Icon defaultMarker; - private BitmapFactory.Options options; - - private int nextId = 0; - - /** - * Get a single instance of IconFactory. - * - * @param context the context to derive the application context from - * @return the single instance of IconFactory - */ - public static synchronized IconFactory getInstance(@NonNull Context context) { - if (instance == null) { - instance = new IconFactory(context.getApplicationContext()); - } - return instance; - } - - private IconFactory(@NonNull Context context) { - this.context = context; - DisplayMetrics realMetrics = null; - DisplayMetrics metrics = new DisplayMetrics(); - WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - realMetrics = new DisplayMetrics(); - wm.getDefaultDisplay().getRealMetrics(realMetrics); - } - wm.getDefaultDisplay().getMetrics(metrics); - - options = new BitmapFactory.Options(); - options.inScaled = true; - options.inDensity = DisplayMetrics.DENSITY_DEFAULT; - options.inTargetDensity = metrics.densityDpi; - if (realMetrics != null) { - options.inScreenDensity = realMetrics.densityDpi; - } - } - - /** - * Creates an icon from a given Bitmap image. - * - * @param bitmap image used for creating the Icon. - * @return The icon using the given Bitmap image. - */ - public Icon fromBitmap(@NonNull Bitmap bitmap) { - if (nextId < 0) { - throw new TooManyIconsException(); - } - String id = ICON_ID_PREFIX + ++nextId; - return new Icon(id, bitmap); - } - - /** - * Creates an icon using the resource ID of a Bitmap image. - * - * @param resourceId The resource ID of a Bitmap image. - * @return The icon that was loaded from the asset or {@code null} if failed to load. - */ - public Icon fromResource(@DrawableRes int resourceId) { - Drawable drawable = BitmapUtils.getDrawableFromRes(context, resourceId); - if (drawable instanceof BitmapDrawable) { - BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; - return fromBitmap(bitmapDrawable.getBitmap()); - } else { - throw new IllegalArgumentException("Failed to decode image. The resource provided must be a Bitmap."); - } - } - - /** - * Provides an icon using the default marker icon used for {@link Marker}. - * - * @return An icon with the default {@link Marker} icon. - */ - public Icon defaultMarker() { - if (defaultMarker == null) { - defaultMarker = fromResource(R.drawable.mapbox_marker_icon_default); - } - return defaultMarker; - } - - private Icon fromInputStream(@NonNull InputStream is) { - Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); - return fromBitmap(bitmap); - } - - /** - * Creates an Icon using the name of a Bitmap image in the assets directory. - * - * @param assetName The name of a Bitmap image in the assets directory. - * @return The Icon that was loaded from the asset or null if failed to load. - */ - public Icon fromAsset(@NonNull String assetName) { - InputStream is; - try { - is = context.getAssets().open(assetName); - } catch (IOException ioException) { - MapStrictMode.strictModeViolation(ioException); - return null; - } - return fromInputStream(is); - } - - /** - * Creates an Icon using the absolute file path of a Bitmap image. - * - * @param absolutePath The absolute path of the Bitmap image. - * @return The Icon that was loaded from the absolute path or null if failed to load. - */ - public Icon fromPath(@NonNull String absolutePath) { - Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, options); - return fromBitmap(bitmap); - } - - /** - * Create an Icon using the name of a Bitmap image file located in the internal storage. - * In particular, this calls Context#openFileInput(String). - * - * @param fileName The name of the Bitmap image file. - * @return The Icon that was loaded from the asset or null if failed to load. - * @see - * Using the Internal Storage - */ - public Icon fromFile(@NonNull String fileName) { - FileInputStream is; - try { - is = context.openFileInput(fileName); - } catch (FileNotFoundException fileNotFoundException) { - MapStrictMode.strictModeViolation(fileNotFoundException); - return null; - } - return fromInputStream(is); - } - - /** - * Create an Icon using a previously created icon identifier along with a provided Bitmap. - * - * @param iconId The Icon identifier you'd like to recreate. - * @param bitmap a Bitmap used to replace the current one. - * @return The Icon using the new Bitmap. - */ - public static Icon recreate(@NonNull String iconId, @NonNull Bitmap bitmap) { - return new Icon(iconId, bitmap); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java deleted file mode 100644 index 5bd9aaef13..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ /dev/null @@ -1,351 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.content.res.Resources; -import android.graphics.PointF; -import android.os.Build; -import android.support.annotation.LayoutRes; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.widget.TextView; - -import com.mapbox.mapboxsdk.R; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; - -import java.lang.ref.WeakReference; - -/** - * {@code InfoWindow} is a tooltip shown when a {@link Marker} is tapped. Only - * one info window is displayed at a time. When the user clicks on a marker, the currently open info - * window will be closed and the new info window will be displayed. If the user clicks the same - * marker while its info window is currently open, the info window will be closed. - *

- * The info window is drawn oriented against the device's screen, centered above its associated - * marker by default. The default info window contains the title in bold and snippet text below the title. - * While either the title and - * snippet are optional, at least one is required to open the info window. - *

- * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public class InfoWindow { - - private WeakReference boundMarker; - private WeakReference mapboxMap; - protected WeakReference view; - - private float markerHeightOffset; - private float markerWidthOffset; - private float viewWidthOffset; - private float viewHeightOffset; - private PointF coordinates; - private boolean isVisible; - - @LayoutRes - private int layoutRes; - - InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) { - layoutRes = layoutResId; - View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false); - initialize(view, mapboxMap); - } - - InfoWindow(@NonNull View view, MapboxMap mapboxMap) { - initialize(view, mapboxMap); - } - - private void initialize(@NonNull View view, MapboxMap mapboxMap) { - this.mapboxMap = new WeakReference<>(mapboxMap); - isVisible = false; - this.view = new WeakReference<>(view); - - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - MapboxMap mapboxMap = InfoWindow.this.mapboxMap.get(); - if (mapboxMap != null) { - MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener = mapboxMap.getOnInfoWindowClickListener(); - boolean handledDefaultClick = false; - if (onInfoWindowClickListener != null) { - handledDefaultClick = onInfoWindowClickListener.onInfoWindowClick(getBoundMarker()); - } - - if (!handledDefaultClick) { - // default behavior: close it when clicking on the tooltip: - closeInfoWindow(); - } - } - } - }); - - view.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - MapboxMap mapboxMap = InfoWindow.this.mapboxMap.get(); - if (mapboxMap != null) { - MapboxMap.OnInfoWindowLongClickListener listener = mapboxMap.getOnInfoWindowLongClickListener(); - if (listener != null) { - listener.onInfoWindowLongClick(getBoundMarker()); - } - } - return true; - } - }); - } - - private void closeInfoWindow() { - MapboxMap mapbox = mapboxMap.get(); - Marker marker = boundMarker.get(); - if (marker != null && mapbox != null) { - mapbox.deselectMarker(marker); - } - close(); - } - - /** - * Open the info window at the specified position. - * - * @param boundMarker The marker on which is hooked the view. - * @param position to place the window on the map. - * @param offsetX The offset of the view to the position, in pixels. This allows to offset - * the view from the object position. - * @param offsetY The offset of the view to the position, in pixels. This allows to offset - * the view from the object position. - * @return this {@link InfoWindow}. - */ - @NonNull - InfoWindow open(@NonNull MapView mapView, Marker boundMarker, @NonNull LatLng position, int offsetX, int offsetY) { - setBoundMarker(boundMarker); - - MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, - MapView.LayoutParams.WRAP_CONTENT); - - MapboxMap mapboxMap = this.mapboxMap.get(); - View view = this.view.get(); - if (view != null && mapboxMap != null) { - view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); - - markerHeightOffset = offsetY; - markerWidthOffset = -offsetX; - - // Calculate default Android x,y coordinate - coordinates = mapboxMap.getProjection().toScreenLocation(position); - float x = coordinates.x - (view.getMeasuredWidth() / 2) + offsetX; - float y = coordinates.y - view.getMeasuredHeight() + offsetY; - - if (view instanceof BubbleLayout) { - // only apply repositioning/margin for InfoWindowView - Resources resources = mapView.getContext().getResources(); - - // get right/left popup window - float rightSideInfowWindow = x + view.getMeasuredWidth(); - float leftSideInfoWindow = x; - - // get right/left map view - final float mapRight = mapView.getRight(); - final float mapLeft = mapView.getLeft(); - - float marginHorizontal = resources.getDimension(R.dimen.mapbox_infowindow_margin); - float tipViewOffset = resources.getDimension(R.dimen.mapbox_infowindow_tipview_width) / 2; - float tipViewMarginLeft = view.getMeasuredWidth() / 2 - tipViewOffset; - - boolean outOfBoundsLeft = false; - boolean outOfBoundsRight = false; - - // only optimise margins if view is inside current viewport - if (coordinates.x >= 0 && coordinates.x <= mapView.getWidth() - && coordinates.y >= 0 && coordinates.y <= mapView.getHeight()) { - - // if out of bounds right - if (rightSideInfowWindow > mapRight) { - outOfBoundsRight = true; - x -= rightSideInfowWindow - mapRight; - tipViewMarginLeft += rightSideInfowWindow - mapRight + tipViewOffset; - rightSideInfowWindow = x + view.getMeasuredWidth(); - } - - // fit screen left - if (leftSideInfoWindow < mapLeft) { - outOfBoundsLeft = true; - x += mapLeft - leftSideInfoWindow; - tipViewMarginLeft -= mapLeft - leftSideInfoWindow + tipViewOffset; - leftSideInfoWindow = x; - } - - // Add margin right - if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) { - x -= marginHorizontal - (mapRight - rightSideInfowWindow); - tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset; - leftSideInfoWindow = x; - } - - // Add margin left - if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) { - x += marginHorizontal - (leftSideInfoWindow - mapLeft); - tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset; - } - } - - // Adjust tipView - ((BubbleLayout) view).setArrowPosition(tipViewMarginLeft); - } - - // set anchor popupwindowview - view.setX(x); - view.setY(y); - - // Calculate x-offset and y-offset for update method - viewWidthOffset = x - coordinates.x - offsetX; - viewHeightOffset = -view.getMeasuredHeight() + offsetY; - - - close(); // if it was already opened - mapView.addView(view, lp); - isVisible = true; - } - return this; - } - - /** - * Close this {@link InfoWindow} if it is visible, otherwise calling this will do nothing. - * - * @return This {@link InfoWindow} - */ - @NonNull - InfoWindow close() { - MapboxMap mapboxMap = this.mapboxMap.get(); - if (isVisible && mapboxMap != null) { - isVisible = false; - View view = this.view.get(); - if (view != null && view.getParent() != null) { - ((ViewGroup) view.getParent()).removeView(view); - } - - Marker marker = getBoundMarker(); - MapboxMap.OnInfoWindowCloseListener listener = mapboxMap.getOnInfoWindowCloseListener(); - if (listener != null) { - listener.onInfoWindowClose(marker); - } - - setBoundMarker(null); - } - return this; - } - - /** - * Constructs the view that is displayed when the InfoWindow opens. This retrieves data from - * overlayItem and shows it in the tooltip. - * - * @param overlayItem the tapped overlay item - */ - void adaptDefaultMarker(@NonNull Marker overlayItem, MapboxMap mapboxMap, @NonNull MapView mapView) { - View view = this.view.get(); - if (view == null) { - view = LayoutInflater.from(mapView.getContext()).inflate(layoutRes, mapView, false); - initialize(view, mapboxMap); - } - this.mapboxMap = new WeakReference<>(mapboxMap); - String title = overlayItem.getTitle(); - TextView titleTextView = ((TextView) view.findViewById(R.id.infowindow_title)); - if (!TextUtils.isEmpty(title)) { - titleTextView.setText(title); - titleTextView.setVisibility(View.VISIBLE); - } else { - titleTextView.setVisibility(View.GONE); - } - - String snippet = overlayItem.getSnippet(); - TextView snippetTextView = ((TextView) view.findViewById(R.id.infowindow_description)); - if (!TextUtils.isEmpty(snippet)) { - snippetTextView.setText(snippet); - snippetTextView.setVisibility(View.VISIBLE); - } else { - snippetTextView.setVisibility(View.GONE); - } - } - - @NonNull - InfoWindow setBoundMarker(Marker boundMarker) { - this.boundMarker = new WeakReference<>(boundMarker); - return this; - } - - @Nullable - Marker getBoundMarker() { - if (boundMarker == null) { - return null; - } - return boundMarker.get(); - } - - /** - * Will result in getting this {@link InfoWindow} and updating the view being displayed. - */ - public void update() { - MapboxMap mapboxMap = this.mapboxMap.get(); - Marker marker = boundMarker.get(); - View view = this.view.get(); - if (mapboxMap != null && marker != null && view != null) { - coordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); - - if (view instanceof BubbleLayout) { - view.setX(coordinates.x + viewWidthOffset - markerWidthOffset); - } else { - view.setX(coordinates.x - (view.getMeasuredWidth() / 2) - markerWidthOffset); - } - view.setY(coordinates.y + viewHeightOffset); - } - } - - void onContentUpdate() { - //recalculate y-offset and update position - View view = this.view.get(); - if (view != null) { - ViewTreeObserver viewTreeObserver = view.getViewTreeObserver(); - if (viewTreeObserver.isAlive()) { - viewTreeObserver.addOnGlobalLayoutListener(contentUpdateListener); - } - } - } - - @Nullable - private final ViewTreeObserver.OnGlobalLayoutListener contentUpdateListener = - new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - View view = InfoWindow.this.view.get(); - if (view != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } else { - view.getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - viewHeightOffset = -view.getMeasuredHeight() + markerHeightOffset; - update(); - } - } - }; - - /** - * Retrieve this {@link InfoWindow}'s current view being used. - * - * @return This {@link InfoWindow}'s current View. - */ - @Nullable - public View getView() { - return view != null ? view.get() : null; - } - - boolean isVisible() { - return isVisible; - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java deleted file mode 100644 index c26af94366..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java +++ /dev/null @@ -1,278 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.support.annotation.Keep; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.view.View; - -import com.mapbox.mapboxsdk.R; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; - -/** - * Marker is an annotation that shows an icon image at a geographical location. The default marker - * uses a provided icon. This icon can be customized using {@link IconFactory} to generate an - * {@link Icon} using a provided image. Markers are added to the map by first giving a - * {@link LatLng} and using {@link MapboxMap#addMarker(MarkerOptions)}. The marker icon will be - * centered at this position so it is common to add padding to the icon image before usage. - *

- * Markers are designed to be interactive. They receive click events by default, and are often used - * with event listeners to bring up info windows. An {@link InfoWindow} is displayed by default when - * either a title or snippet is provided. - *

- * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public class Marker extends Annotation { - - @Keep - private LatLng position; - private String snippet; - @Nullable - private Icon icon; - //Redundantly stored for JNI access - @Nullable - @Keep - private String iconId; - private String title; - - @Nullable - private InfoWindow infoWindow; - private boolean infoWindowShown; - - private int topOffsetPixels; - private int rightOffsetPixels; - - /** - * Constructor - */ - Marker() { - super(); - } - - /** - * Creates a instance of {@link Marker} using the builder of Marker. - * - * @param baseMarkerOptions The builder used to construct the Marker. - */ - public Marker(BaseMarkerOptions baseMarkerOptions) { - this(baseMarkerOptions.position, baseMarkerOptions.icon, baseMarkerOptions.title, baseMarkerOptions.snippet); - } - - Marker(LatLng position, Icon icon, String title, String snippet) { - this.position = position; - this.title = title; - this.snippet = snippet; - setIcon(icon); - } - - /** - * Returns the position of the marker. - * - * @return A {@link LatLng} object specifying the marker's current position. - */ - public LatLng getPosition() { - return position; - } - - /** - * Gets the snippet of the marker. - * - * @return A string containing the marker's snippet. - */ - public String getSnippet() { - return snippet; - } - - /** - * Gets the snippet of the marker. - * - * @return A string containing the marker's snippet. - */ - public String getTitle() { - return title; - } - - /** - * Do not use this method, used internally by the SDK. - */ - public void hideInfoWindow() { - if (infoWindow != null) { - infoWindow.close(); - } - infoWindowShown = false; - } - - /** - * Do not use this method, used internally by the SDK. - * - * @return true if the infoWindow is shown - */ - public boolean isInfoWindowShown() { - return infoWindowShown; - } - - /** - * Sets the location of the marker. - * - * @param position A {@link LatLng} defining the marker position. - */ - public void setPosition(LatLng position) { - this.position = position; - MapboxMap map = getMapboxMap(); - if (map != null) { - map.updateMarker(this); - } - } - - /** - * Sets the snippet of the marker. - * - * @param snippet A String used in the marker info window. If {@code null}, the snippet is - * cleared. - */ - public void setSnippet(String snippet) { - this.snippet = snippet; - refreshInfoWindowContent(); - } - - /** - * Sets the icon of the marker. - * - * @param icon The {@link Icon} to be used as Marker image - */ - public void setIcon(@Nullable Icon icon) { - this.icon = icon; - this.iconId = icon != null ? icon.getId() : null; - MapboxMap map = getMapboxMap(); - if (map != null) { - map.updateMarker(this); - } - } - - /** - * Gets the {@link Icon} currently used for the marker. If no Icon was set for the marker, the - * default icon will be returned. - * - * @return The {@link Icon} the marker is using. - */ - @Nullable - public Icon getIcon() { - return icon; - } - - /** - * Sets the title of the marker. - * - * @param title A String used in the marker info window. If {@code null}, the title is - * cleared. - */ - public void setTitle(String title) { - this.title = title; - refreshInfoWindowContent(); - } - - /** - * Gets the {@link InfoWindow} the marker is using. If the marker hasn't had an info window - * defined, this will return {@code null}. - * - * @return The info window the marker is using. - */ - @Nullable - public InfoWindow getInfoWindow() { - return infoWindow; - } - - /** - * Update only for default Marker's InfoWindow content for Title and Snippet - */ - private void refreshInfoWindowContent() { - if (isInfoWindowShown() && mapView != null && mapboxMap != null && mapboxMap.getInfoWindowAdapter() == null) { - InfoWindow infoWindow = getInfoWindow(mapView); - if (mapView.getContext() != null) { - infoWindow.adaptDefaultMarker(this, mapboxMap, mapView); - } - MapboxMap map = getMapboxMap(); - if (map != null) { - map.updateMarker(this); - } - infoWindow.onContentUpdate(); - } - } - - /** - * Do not use this method, used internally by the SDK. Use {@link MapboxMap#selectMarker(Marker)} - * if you want to programmatically display the markers info window. - * - * @param mapboxMap The hosting mapbox map. - * @param mapView The hosting map view. - * @return The info window that was shown. - */ - @Nullable - public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView) { - setMapboxMap(mapboxMap); - setMapView(mapView); - MapboxMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter(); - if (infoWindowAdapter != null) { - // end developer is using a custom InfoWindowAdapter - View content = infoWindowAdapter.getInfoWindow(this); - if (content != null) { - infoWindow = new InfoWindow(content, mapboxMap); - showInfoWindow(infoWindow, mapView); - return infoWindow; - } - } - - InfoWindow infoWindow = getInfoWindow(mapView); - if (mapView.getContext() != null) { - infoWindow.adaptDefaultMarker(this, mapboxMap, mapView); - } - return showInfoWindow(infoWindow, mapView); - } - - @NonNull - private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) { - iw.open(mapView, this, getPosition(), rightOffsetPixels, topOffsetPixels); - infoWindowShown = true; - return iw; - } - - @Nullable - private InfoWindow getInfoWindow(@NonNull MapView mapView) { - if (infoWindow == null && mapView.getContext() != null) { - infoWindow = new InfoWindow(mapView, R.layout.mapbox_infowindow_content, getMapboxMap()); - } - return infoWindow; - } - - /** - * Do not use this method, used internally by the SDK. - * - * @param topOffsetPixels the top offset pixels. - */ - public void setTopOffsetPixels(int topOffsetPixels) { - this.topOffsetPixels = topOffsetPixels; - } - - /** - * Do not use this method, used internally by the SDK. - * - * @param rightOffsetPixels the right offset pixels. - */ - public void setRightOffsetPixels(int rightOffsetPixels) { - this.rightOffsetPixels = rightOffsetPixels; - } - - /** - * Returns a String with the marker position. - * - * @return A String with the marker position. - */ - @Override - public String toString() { - return "Marker [position[" + getPosition() + "]]"; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java deleted file mode 100644 index 62c3d378e4..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.Bitmap; -import android.os.Parcel; -import android.os.Parcelable; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; -import com.mapbox.mapboxsdk.geometry.LatLng; - -/** - *

- * Builder for composing {@link Marker} objects. See {@link Marker} for additional information. - *

- *

Example

- *
- * mapView.addMarker(new MarkerOptions()
- *   .title("Intersection")
- *   .snippet("H St NW with 15th St NW")
- *   .position(new LatLng(38.9002073, -77.03364419)));
- * 
- * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public final class MarkerOptions extends BaseMarkerOptions implements Parcelable { - - /** - * Defines options for a Marker. - */ - public MarkerOptions() { - } - - protected MarkerOptions(Parcel in) { - position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); - snippet(in.readString()); - title(in.readString()); - if (in.readByte() != 0) { - // this means we have an icon - String iconId = in.readString(); - Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); - Icon icon = new Icon(iconId, iconBitmap); - icon(icon); - } - } - - @NonNull - @Override - public MarkerOptions getThis() { - return this; - } - - /** - * Describe the kinds of special objects contained in this Parcelable's - * marshalled representation. - * - * @return integer 0. - */ - @Override - public int describeContents() { - return 0; - } - - /** - * Flatten this object in to a Parcel. - * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. May be 0 or - * {@link #PARCELABLE_WRITE_RETURN_VALUE}. - */ - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeParcelable(getPosition(), flags); - out.writeString(getSnippet()); - out.writeString(getTitle()); - Icon icon = getIcon(); - out.writeByte((byte) (icon != null ? 1 : 0)); - if (icon != null) { - out.writeString(getIcon().getId()); - out.writeParcelable(getIcon().getBitmap(), flags); - } - } - - /** - * Do not use this method. Used internally by the SDK. - * - * @return Marker The build marker - */ - public Marker getMarker() { - if (position == null) { - throw new InvalidMarkerPositionException(); - } - - return new Marker(position, icon, title, snippet); - } - - /** - * Returns the position set for this {@link MarkerOptions} object. - * - * @return A {@link LatLng} object specifying the marker's current position. - */ - public LatLng getPosition() { - return position; - } - - /** - * Gets the snippet set for this {@link MarkerOptions} object. - * - * @return A string containing the marker's snippet. - */ - public String getSnippet() { - return snippet; - } - - /** - * Gets the title set for this {@link MarkerOptions} object. - * - * @return A string containing the marker's title. - */ - public String getTitle() { - return title; - } - - /** - * Gets the custom icon set for this {@link MarkerOptions} object. - * - * @return A {@link Icon} object that the marker is using. If the icon wasn't set, default icon - * will return. - */ - public Icon getIcon() { - return icon; - } - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - public MarkerOptions createFromParcel(@NonNull Parcel in) { - return new MarkerOptions(in); - } - - public MarkerOptions[] newArray(int size) { - return new MarkerOptions[size]; - } - }; - - /** - * Compares this {@link MarkerOptions} object with another {@link MarkerOptions} and - * determines if their properties match. - * - * @param o Another {@link MarkerOptions} to compare with this object. - * @return True if marker properties match this {@link MarkerOptions} object. - * Else, false. - */ - @Override - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - MarkerOptions marker = (MarkerOptions) o; - - if (getPosition() != null ? !getPosition().equals(marker.getPosition()) : marker.getPosition() != null) { - return false; - } - if (getSnippet() != null ? !getSnippet().equals(marker.getSnippet()) : marker.getSnippet() != null) { - return false; - } - if (getIcon() != null ? !getIcon().equals(marker.getIcon()) : marker.getIcon() != null) { - return false; - } - return !(getTitle() != null ? !getTitle().equals(marker.getTitle()) : marker.getTitle() != null); - } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getPosition() != null ? getPosition().hashCode() : 0); - result = 31 * result + (getSnippet() != null ? getSnippet().hashCode() : 0); - result = 31 * result + (getIcon() != null ? getIcon().hashCode() : 0); - result = 31 * result + (getTitle() != null ? getTitle().hashCode() : 0); - return result; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java deleted file mode 100644 index 5f6cef8d40..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.Color; -import android.support.annotation.Keep; - -import android.support.annotation.NonNull; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapboxMap; - -import java.util.ArrayList; -import java.util.List; - -/** - * Polygon is a geometry annotation that's a closed loop of coordinates. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public final class Polygon extends BasePointCollection { - - @Keep - private int fillColor = Color.BLACK; // default fillColor is black - @Keep - private int strokeColor = Color.BLACK; // default strokeColor is black - @Keep - private List> holes; - - Polygon() { - super(); - holes = new ArrayList<>(); - } - - /** - * Get the color of the fill region of the polygon. - * - * @return The color of the fill. - */ - public int getFillColor() { - return fillColor; - } - - /** - * Get the color of the stroke of the polygon. - * - * @return The color of the stroke. - */ - public int getStrokeColor() { - return strokeColor; - } - - /** - * Returns a copy of the holes. - * - * @return A {@link List} of {@link List} of {@link LatLng} points making up the holes. - */ - public List> getHoles() { - return new ArrayList<>(holes); - } - - /** - * Sets the color of the fill region of the polygon. - * - * @param color The color in ARGB format. - */ - public void setFillColor(int color) { - fillColor = color; - update(); - } - - /** - * Sets the color of the stroke of the polygon. - * - * @param color The color in ARGB format. - */ - public void setStrokeColor(int color) { - strokeColor = color; - update(); - } - - /** - * Sets the holes of this polygon. This method will take a copy of the holes, so further - * mutations to holes will have no effect on this polygon. - * - * @param holes A {@link List} of {@link List} of {@link LatLng} points making up the holes. - */ - public void setHoles(@NonNull List> holes) { - this.holes = new ArrayList<>(holes); - update(); - } - - /** - * Add a hole to the polygon. - * - * @param hole A {@link List} of {@link List} of {@link LatLng} points making up the hole to be added. - */ - void addHole(List hole) { - holes.add(hole); - update(); - } - - @Override - void update() { - MapboxMap mapboxMap = getMapboxMap(); - if (mapboxMap != null) { - mapboxMap.updatePolygon(this); - } - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java deleted file mode 100644 index 452420fcbd..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java +++ /dev/null @@ -1,308 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - - -import android.os.Parcel; -import android.os.Parcelable; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import java.util.ArrayList; -import java.util.List; - -/** - * Builder for composing {@link Polygon} objects. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public final class PolygonOptions implements Parcelable { - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - public PolygonOptions createFromParcel(@NonNull Parcel in) { - return new PolygonOptions(in); - } - - public PolygonOptions[] newArray(int size) { - return new PolygonOptions[size]; - } - }; - - private PolygonOptions(Parcel in) { - polygon = new Polygon(); - List pointsList = new ArrayList<>(); - in.readList(pointsList, LatLng.class.getClassLoader()); - addAll(pointsList); - List> holes = new ArrayList<>(); - in.readList(holes, LatLng.class.getClassLoader()); - addAllHoles(holes); - alpha(in.readFloat()); - fillColor(in.readInt()); - strokeColor(in.readInt()); - } - - /** - * Describe the kinds of special objects contained in this Parcelable's - * marshalled representation. - * - * @return integer 0. - */ - @Override - public int describeContents() { - return 0; - } - - /** - * Flatten this object in to a Parcel. - * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. May be 0 or - * {@link #PARCELABLE_WRITE_RETURN_VALUE}. - */ - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeList(getPoints()); - out.writeList(getHoles()); - out.writeFloat(getAlpha()); - out.writeInt(getFillColor()); - out.writeInt(getStrokeColor()); - } - - private Polygon polygon; - - /** - * Defines options for a polygon. - */ - public PolygonOptions() { - polygon = new Polygon(); - } - - /** - * Adds a vertex to the outline of the polygon being built. - * - * @param point {@link LatLng} point to be added to polygon geometry. - * @return This {@link PolygonOptions} object with the given point added to the outline. - */ - @NonNull - public PolygonOptions add(LatLng point) { - polygon.addPoint(point); - return this; - } - - /** - * Adds vertices to the outline of the polygon being built. - * - * @param points {@link LatLng} points to be added to polygon geometry. - * @return This {@link PolygonOptions} object with the given points added to the outline. - */ - @NonNull - public PolygonOptions add(LatLng... points) { - for (LatLng point : points) { - add(point); - } - return this; - } - - /** - * Adds vertices to the outline of the polygon being built. - * - * @param points {@link Iterable} list made up of {@link LatLng} points defining the polygon - * geometry - * @return This {@link PolygonOptions} object with the given points added to the outline. - */ - @NonNull - public PolygonOptions addAll(Iterable points) { - for (LatLng point : points) { - add(point); - } - return this; - } - - /** - * Adds a hole to the outline of the polygon being built. - * - * @param hole {@link List} list made up of {@link LatLng} points defining the hole - * @return This {@link PolygonOptions} object with the given hole added to the outline. - */ - @NonNull - public PolygonOptions addHole(List hole) { - polygon.addHole(hole); - return this; - } - - /** - * Adds holes to the outline of the polygon being built. - * - * @param holes {@link List} list made up of {@link LatLng} holes to be added to polygon geometry - * @return This {@link PolygonOptions} object with the given holes added to the outline. - */ - @NonNull - public PolygonOptions addHole(List... holes) { - for (List hole : holes) { - addHole(hole); - } - return this; - } - - /** - * Adds holes to the outline of the polygon being built. - * - * @param holes {@link Iterable} list made up of {@link List} list of {@link LatLng} holes defining the hole geometry - * @return This {@link PolygonOptions} object with the given holes added to the outline. - */ - @NonNull - public PolygonOptions addAllHoles(Iterable> holes) { - for (List hole : holes) { - addHole(hole); - } - return this; - } - - /** - * Set the alpha value of the polyline. - * - * @param alpha float value between 0 (not visible) and 1. - * @return This {@link PolygonOptions} object with the given polygon alpha value. - */ - @NonNull - public PolygonOptions alpha(float alpha) { - polygon.setAlpha(alpha); - return this; - } - - /** - * Gets the alpha set for this {@link PolygonOptions} object. - * - * @return float value between 0 and 1 defining the alpha. - */ - public float getAlpha() { - return polygon.getAlpha(); - } - - /** - * Specifies the polygon's fill color, as 32-bit ARGB. The default color is black. - * - * @param color 32-bit ARGB color. - * @return This {@link PolylineOptions} object with a new color set. - */ - @NonNull - public PolygonOptions fillColor(int color) { - polygon.setFillColor(color); - return this; - } - - /** - * Gets the fill color set for this {@link PolygonOptions} object. - * - * @return The fill color of the polygon in ARGB format. - */ - public int getFillColor() { - return polygon.getFillColor(); - } - - /** - * Do not use this method. Used internally by the SDK. - * - * @return Polygon the Polygon to return - */ - public Polygon getPolygon() { - return polygon; - } - - /** - * Specifies the polygon's stroke color, as 32-bit ARGB. The default color is black. - * - * @param color 32-bit ARGB color. - * @return This {@link PolygonOptions} object with a new stroke color set. - */ - @NonNull - public PolygonOptions strokeColor(int color) { - polygon.setStrokeColor(color); - return this; - } - - /** - * Gets the stroke color set for this {@link PolygonOptions} object. - * - * @return The stroke color of the polygon in ARGB format. - */ - public int getStrokeColor() { - return polygon.getStrokeColor(); - } - - /** - * Gets the points set for this {@link PolygonOptions} object. - * - * @return The list made up of {@link LatLng} points defining the polygon. - */ - public List getPoints() { - // the getter gives us a copy, which is the safe thing to do... - return polygon.getPoints(); - } - - /** - * Gets the holes set for this {@link PolygonOptions} object. - * - * @return The list made up of {@link List} of {@link List} of {@link LatLng} points defining the holes. - */ - public List> getHoles() { - return polygon.getHoles(); - } - - - /** - * Compares this {@link PolygonOptions} object with another {@link PolygonOptions} and - * determines if their color, alpha, stroke color, and vertices match. - * - * @param o Another {@link PolygonOptions} to compare with this object. - * @return True if color, alpha, stroke color, vertices and holes match this {@link PolygonOptions} - * {@link PolygonOptions} object. Else, false. - */ - @Override - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - PolygonOptions polygon = (PolygonOptions) o; - - if (Float.compare(polygon.getAlpha(), getAlpha()) != 0) { - return false; - } - if (getFillColor() != polygon.getFillColor()) { - return false; - } - if (getStrokeColor() != polygon.getStrokeColor()) { - return false; - } - if (getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null) { - return false; - } - return !(getHoles() != null ? !getHoles().equals(polygon.getHoles()) : polygon.getHoles() != null); - } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getAlpha() != +0.0f ? Float.floatToIntBits(getAlpha()) : 0); - result = 31 * result + getFillColor(); - result = 31 * result + getStrokeColor(); - result = 31 * result + (getPoints() != null ? getPoints().hashCode() : 0); - result = 31 * result + (getHoles() != null ? getHoles().hashCode() : 0); - return result; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java deleted file mode 100644 index 76ea15215d..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.Color; -import android.support.annotation.Keep; - -import com.mapbox.mapboxsdk.maps.MapboxMap; - -/** - * Polyline is a geometry feature with an unclosed list of coordinates drawn as a line - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public final class Polyline extends BasePointCollection { - - @Keep - private int color = Color.BLACK; // default color is black - @Keep - private float width = 10; // As specified by Google API Docs (in pixels) - - Polyline() { - super(); - } - - /** - * Gets the color of this polyline. - * - * @return The color in ARGB format. - */ - public int getColor() { - return color; - } - - /** - * Gets the width of this polyline. - * - * @return The width in screen pixels. - */ - public float getWidth() { - return width; - } - - /** - * Sets the color of the polyline. - * - * @param color - the color in ARGB format - */ - public void setColor(int color) { - this.color = color; - update(); - } - - /** - * Sets the width of the polyline. - * - * @param width in pixels - */ - public void setWidth(float width) { - this.width = width; - update(); - } - - @Override - void update() { - MapboxMap mapboxMap = getMapboxMap(); - if (mapboxMap != null) { - mapboxMap.updatePolyline(this); - } - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java deleted file mode 100644 index 6a54f948b7..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java +++ /dev/null @@ -1,250 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.os.Parcel; -import android.os.Parcelable; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import java.util.ArrayList; -import java.util.List; - -/** - * Builder for composing {@link Polyline} objects. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ -@Deprecated -public final class PolylineOptions implements Parcelable { - - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - public PolylineOptions createFromParcel(@NonNull Parcel in) { - return new PolylineOptions(in); - } - - public PolylineOptions[] newArray(int size) { - return new PolylineOptions[size]; - } - }; - - private PolylineOptions(Parcel in) { - polyline = new Polyline(); - ArrayList pointsList = new ArrayList<>(); - in.readList(pointsList, LatLng.class.getClassLoader()); - addAll(pointsList); - alpha(in.readFloat()); - color(in.readInt()); - width(in.readFloat()); - } - - /** - * Describe the kinds of special objects contained in this Parcelable's - * marshalled representation. - * - * @return integer 0. - */ - @Override - public int describeContents() { - return 0; - } - - /** - * Flatten this object in to a Parcel. - * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. May be 0 or - * {@link #PARCELABLE_WRITE_RETURN_VALUE}. - */ - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeList(getPoints()); - out.writeFloat(getAlpha()); - out.writeInt(getColor()); - out.writeFloat(getWidth()); - } - - private Polyline polyline; - - /** - * Defines options for a polyline. - */ - public PolylineOptions() { - polyline = new Polyline(); - } - - /** - * Adds a vertex to the end of the polyline being built. - * - * @param point {@link LatLng} point to be added to polyline geometry. - * @return This {@link PolylineOptions} object with the given point on the end. - */ - @NonNull - public PolylineOptions add(LatLng point) { - polyline.addPoint(point); - return this; - } - - /** - * Adds vertices to the end of the polyline being built. - * - * @param points {@link LatLng} points defining the polyline geometry. - * @return This {@link PolylineOptions} object with the given point on the end. - */ - @NonNull - public PolylineOptions add(LatLng... points) { - for (LatLng point : points) { - add(point); - } - return this; - } - - /** - * Adds vertices to the end of the polyline being built. - * - * @param points {@link Iterable} list made up of {@link LatLng} points defining the polyline - * geometry - * @return This {@link PolylineOptions} object with the given points on the end. - */ - @NonNull - public PolylineOptions addAll(Iterable points) { - for (LatLng point : points) { - add(point); - } - return this; - } - - /** - * Set the alpha value of the polyline. - * - * @param alpha float value between 0 (not visible) and 1. - * @return This {@link PolylineOptions} object with the given polyline alpha value. - */ - @NonNull - public PolylineOptions alpha(float alpha) { - polyline.setAlpha(alpha); - return this; - } - - /** - * Gets the alpha set for this {@link PolylineOptions} object. - * - * @return float value between 0 and 1 defining the alpha. - */ - public float getAlpha() { - return polyline.getAlpha(); - } - - /** - * Sets the color of the polyline as a 32-bit ARGB color. The default color is black. - * - * @param color 32-bit ARGB color. - * @return This {@link PolylineOptions} object with a new color set. - */ - @NonNull - public PolylineOptions color(int color) { - polyline.setColor(color); - return this; - } - - /** - * Gets the color set for this {@link PolylineOptions} object. - * - * @return The color of the polyline in ARGB format. - */ - public int getColor() { - return polyline.getColor(); - } - - /** - * Do not use this method. Used internally by the SDK. - * - * @return PolyLine The polyline build by this class. - */ - public Polyline getPolyline() { - return polyline; - } - - /** - * Gets the width set for this {@link PolylineOptions} object. - * - * @return The width of the polyline in screen pixels. - */ - public float getWidth() { - return polyline.getWidth(); - } - - /** - * Sets the width of the polyline in screen pixels. The default is 10. - * - * @param width float value defining width of polyline using unit pixels. - * @return This {@link PolylineOptions} object with a new width set. - */ - @NonNull - public PolylineOptions width(float width) { - polyline.setWidth(width); - return this; - } - - /** - * Gets the points set for this {@link PolylineOptions} object. - * - * @return a {@link List} of {@link LatLng}s specifying the vertices of the polyline. - */ - public List getPoints() { - // the getter gives us a copy, which is the safe thing to do... - return polyline.getPoints(); - } - - /** - * Compares this {@link PolylineOptions} object with another {@link PolylineOptions} and - * determines if their color, alpha, width, and vertices match. - * - * @param o Another {@link PolylineOptions} to compare with this object. - * @return True if color, alpha, width, and vertices match this {@link PolylineOptions} object. - * Else, false. - */ - @Override - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - PolylineOptions polyline = (PolylineOptions) o; - - if (Float.compare(polyline.getAlpha(), getAlpha()) != 0) { - return false; - } - if (getColor() != polyline.getColor()) { - return false; - } - if (Float.compare(polyline.getWidth(), getWidth()) != 0) { - return false; - } - return !(getPoints() != null ? !getPoints().equals(polyline.getPoints()) : polyline.getPoints() != null); - } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getAlpha() != +0.0f ? Float.floatToIntBits(getAlpha()) : 0); - result = 31 * result + getColor(); - result = 31 * result + (getWidth() != +0.0f ? Float.floatToIntBits(getWidth()) : 0); - result = 31 * result + (getPoints() != null ? getPoints().hashCode() : 0); - return result; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/package-info.java deleted file mode 100644 index 1e2dc542fa..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains the Mapbox Maps Android Annotation API classes. - */ -package com.mapbox.mapboxsdk.annotations; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java deleted file mode 100644 index 1f6b0efc4d..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mapbox.mapboxsdk.exceptions; - -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.maps.MapView; - -/** - *

- * An IconBitmapChangedException is thrown by MapView when a Marker is added - * that has an Icon with a Bitmap that has been modified since the creation of the Icon. - *

- * You cannot modify a {@code Icon} after it has been added to the map in a {@code Marker} - * - * @see MapView - * @see Icon - * @see Marker - */ -public class IconBitmapChangedException extends RuntimeException { - - public IconBitmapChangedException() { - super("The added Marker has an Icon with a bitmap that has been modified. An Icon cannot be modified" - + "after it has been added to the map in a Marker."); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidMarkerPositionException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidMarkerPositionException.java deleted file mode 100644 index 44ee83265d..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidMarkerPositionException.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mapbox.mapboxsdk.exceptions; - -/** - * A InvalidMarkerPositionException is thrown when a Marker object is created with an invalid LatLng position. - */ -public class InvalidMarkerPositionException extends RuntimeException { - - /** - * Creates a invalid marker position exception thrown when a Marker object is created with an invalid LatLng position. - */ - public InvalidMarkerPositionException() { - super("Adding an invalid Marker to a Map. " - + "Missing the required position field. " - + "Provide a non null LatLng as position to the Marker."); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TooManyIconsException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TooManyIconsException.java deleted file mode 100644 index bffc10dc04..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TooManyIconsException.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mapbox.mapboxsdk.exceptions; - -import com.mapbox.mapboxsdk.annotations.IconFactory; - -/** - *

- * A TooManyIconsException is thrown by IconFactory when it - * cannot create a Icon because there are already too many icons created. - *

- * You should try to reuse Icon objects whenever possible. - * - * @see IconFactory - */ -public class TooManyIconsException extends RuntimeException { - - public TooManyIconsException() { - super("Cannot create an Icon because there are already too many. Try reusing Icon objects whenever possible."); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationContainer.java deleted file mode 100644 index e5bf512791..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationContainer.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - - -import android.support.annotation.NonNull; -import android.support.v4.util.LongSparseArray; - -import com.mapbox.mapboxsdk.annotations.Annotation; - -import java.util.ArrayList; -import java.util.List; - -/** - * Encapsulates {@link Annotation}'s functionality.. - */ -class AnnotationContainer implements Annotations { - - private final NativeMap nativeMap; - private final LongSparseArray annotations; - - AnnotationContainer(NativeMap nativeMap, LongSparseArray annotations) { - this.nativeMap = nativeMap; - this.annotations = annotations; - } - - @Override - public Annotation obtainBy(long id) { - return annotations.get(id); - } - - @NonNull - @Override - public List obtainAll() { - List annotations = new ArrayList<>(); - for (int i = 0; i < this.annotations.size(); i++) { - annotations.add(this.annotations.get(this.annotations.keyAt(i))); - } - return annotations; - } - - @Override - public void removeBy(long id) { - if (nativeMap != null) { - nativeMap.removeAnnotation(id); - } - annotations.remove(id); - } - - @Override - public void removeBy(@NonNull Annotation annotation) { - long id = annotation.getId(); - removeBy(id); - } - - @Override - public void removeBy(@NonNull List annotationList) { - int count = annotationList.size(); - long[] ids = new long[count]; - for (int i = 0; i < count; i++) { - ids[i] = annotationList.get(i).getId(); - } - - removeNativeAnnotations(ids); - - for (long id : ids) { - annotations.remove(id); - } - } - - @Override - public void removeAll() { - int count = annotations.size(); - long[] ids = new long[count]; - for (int i = 0; i < count; i++) { - ids[i] = annotations.keyAt(i); - } - - removeNativeAnnotations(ids); - - annotations.clear(); - } - - private void removeNativeAnnotations(long[] ids) { - if (nativeMap != null) { - nativeMap.removeAnnotations(ids); - } - } -} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java deleted file mode 100644 index 8875e7164b..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ /dev/null @@ -1,519 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.Bitmap; -import android.graphics.PointF; -import android.graphics.Rect; -import android.graphics.RectF; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.util.LongSparseArray; -import android.view.View; -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.R; -import com.mapbox.mapboxsdk.annotations.Annotation; -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.log.Logger; - -import java.util.ArrayList; -import java.util.List; - -/** - * Responsible for managing and tracking state of Annotations linked to Map. All events related to - * annotations that occur on {@link MapboxMap} are forwarded to this class. - *

- * Responsible for referencing {@link InfoWindowManager}. - *

- *

- * Exposes convenience methods to add/remove/update all subtypes of annotations found in - * com.mapbox.mapboxsdk.annotations. - *

- */ -class AnnotationManager { - - private static final String TAG = "Mbgl-AnnotationManager"; - - private static final long NO_ANNOTATION_ID = -1; - - @NonNull - private final MapView mapView; - private final IconManager iconManager; - private final InfoWindowManager infoWindowManager = new InfoWindowManager(); - private final LongSparseArray annotationsArray; - private final List selectedMarkers = new ArrayList<>(); - - private MapboxMap mapboxMap; - @Nullable - private MapboxMap.OnMarkerClickListener onMarkerClickListener; - @Nullable - private MapboxMap.OnPolygonClickListener onPolygonClickListener; - @Nullable - private MapboxMap.OnPolylineClickListener onPolylineClickListener; - - private Annotations annotations; - private ShapeAnnotations shapeAnnotations; - private Markers markers; - private Polygons polygons; - private Polylines polylines; - - AnnotationManager(@NonNull MapView mapView, LongSparseArray annotationsArray, - IconManager iconManager, Annotations annotations, Markers markers, Polygons polygons, - Polylines polylines, ShapeAnnotations shapeAnnotations) { - this.mapView = mapView; - this.annotationsArray = annotationsArray; - this.iconManager = iconManager; - this.annotations = annotations; - this.markers = markers; - this.polygons = polygons; - this.polylines = polylines; - this.shapeAnnotations = shapeAnnotations; - } - - // TODO refactor MapboxMap out for Projection and Transform - // Requires removing MapboxMap from Annotations by using Peer model from #6912 - @NonNull - AnnotationManager bind(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; - return this; - } - - void update() { - infoWindowManager.update(); - } - - // - // Annotations - // - - Annotation getAnnotation(long id) { - return annotations.obtainBy(id); - } - - List getAnnotations() { - return annotations.obtainAll(); - } - - void removeAnnotation(long id) { - annotations.removeBy(id); - } - - void removeAnnotation(@NonNull Annotation annotation) { - if (annotation instanceof Marker) { - Marker marker = (Marker) annotation; - marker.hideInfoWindow(); - if (selectedMarkers.contains(marker)) { - selectedMarkers.remove(marker); - } - // do icon cleanup - iconManager.iconCleanup(marker.getIcon()); - } - annotations.removeBy(annotation); - } - - void removeAnnotations(@NonNull List annotationList) { - for (Annotation annotation : annotationList) { - if (annotation instanceof Marker) { - Marker marker = (Marker) annotation; - marker.hideInfoWindow(); - if (selectedMarkers.contains(marker)) { - selectedMarkers.remove(marker); - } - iconManager.iconCleanup(marker.getIcon()); - } - } - annotations.removeBy(annotationList); - } - - void removeAnnotations() { - Annotation annotation; - int count = annotationsArray.size(); - long[] ids = new long[count]; - selectedMarkers.clear(); - for (int i = 0; i < count; i++) { - ids[i] = annotationsArray.keyAt(i); - annotation = annotationsArray.get(ids[i]); - if (annotation instanceof Marker) { - Marker marker = (Marker) annotation; - marker.hideInfoWindow(); - iconManager.iconCleanup(marker.getIcon()); - } - } - annotations.removeAll(); - } - - // - // Markers - // - - Marker addMarker(@NonNull BaseMarkerOptions markerOptions, @NonNull MapboxMap mapboxMap) { - return markers.addBy(markerOptions, mapboxMap); - } - - List addMarkers(@NonNull List markerOptionsList, @NonNull MapboxMap mapboxMap) { - return markers.addBy(markerOptionsList, mapboxMap); - } - - void updateMarker(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap) { - if (!isAddedToMap(updatedMarker)) { - logNonAdded(updatedMarker); - return; - } - markers.update(updatedMarker, mapboxMap); - } - - List getMarkers() { - return markers.obtainAll(); - } - - @NonNull - List getMarkersInRect(@NonNull RectF rectangle) { - return markers.obtainAllIn(rectangle); - } - - void reloadMarkers() { - markers.reload(); - } - - // - // Polygons - // - - Polygon addPolygon(@NonNull PolygonOptions polygonOptions, @NonNull MapboxMap mapboxMap) { - return polygons.addBy(polygonOptions, mapboxMap); - } - - List addPolygons(@NonNull List polygonOptionsList, @NonNull MapboxMap mapboxMap) { - return polygons.addBy(polygonOptionsList, mapboxMap); - } - - void updatePolygon(@NonNull Polygon polygon) { - if (!isAddedToMap(polygon)) { - logNonAdded(polygon); - return; - } - polygons.update(polygon); - } - - List getPolygons() { - return polygons.obtainAll(); - } - - // - // Polylines - // - - Polyline addPolyline(@NonNull PolylineOptions polylineOptions, @NonNull MapboxMap mapboxMap) { - return polylines.addBy(polylineOptions, mapboxMap); - } - - List addPolylines(@NonNull List polylineOptionsList, @NonNull MapboxMap mapboxMap) { - return polylines.addBy(polylineOptionsList, mapboxMap); - } - - void updatePolyline(@NonNull Polyline polyline) { - if (!isAddedToMap(polyline)) { - logNonAdded(polyline); - return; - } - polylines.update(polyline); - } - - List getPolylines() { - return polylines.obtainAll(); - } - - // TODO Refactor from here still in progress - void setOnMarkerClickListener(@Nullable MapboxMap.OnMarkerClickListener listener) { - onMarkerClickListener = listener; - } - - void setOnPolygonClickListener(@Nullable MapboxMap.OnPolygonClickListener listener) { - onPolygonClickListener = listener; - } - - void setOnPolylineClickListener(@Nullable MapboxMap.OnPolylineClickListener listener) { - onPolylineClickListener = listener; - } - - void selectMarker(@NonNull Marker marker) { - if (selectedMarkers.contains(marker)) { - return; - } - - // Need to deselect any currently selected annotation first - if (!infoWindowManager.isAllowConcurrentMultipleOpenInfoWindows()) { - deselectMarkers(); - } - - if (infoWindowManager.isInfoWindowValidForMarker(marker) || infoWindowManager.getInfoWindowAdapter() != null) { - infoWindowManager.add(marker.showInfoWindow(mapboxMap, mapView)); - } - - // only add to selected markers if user didn't handle the click event themselves #3176 - selectedMarkers.add(marker); - } - - void deselectMarkers() { - if (selectedMarkers.isEmpty()) { - return; - } - - for (Marker marker : selectedMarkers) { - if (marker != null) { - if (marker.isInfoWindowShown()) { - marker.hideInfoWindow(); - } - } - } - - // Removes all selected markers from the list - selectedMarkers.clear(); - } - - void deselectMarker(@NonNull Marker marker) { - if (!selectedMarkers.contains(marker)) { - return; - } - - if (marker.isInfoWindowShown()) { - marker.hideInfoWindow(); - } - selectedMarkers.remove(marker); - } - - @NonNull - List getSelectedMarkers() { - return selectedMarkers; - } - - @NonNull - InfoWindowManager getInfoWindowManager() { - return infoWindowManager; - } - - void adjustTopOffsetPixels(@NonNull MapboxMap mapboxMap) { - int count = annotationsArray.size(); - for (int i = 0; i < count; i++) { - Annotation annotation = annotationsArray.get(i); - if (annotation instanceof Marker) { - Marker marker = (Marker) annotation; - marker.setTopOffsetPixels( - iconManager.getTopOffsetPixelsForIcon(marker.getIcon())); - } - } - - for (Marker marker : selectedMarkers) { - if (marker.isInfoWindowShown()) { - marker.hideInfoWindow(); - marker.showInfoWindow(mapboxMap, mapView); - } - } - } - - private boolean isAddedToMap(@Nullable Annotation annotation) { - return annotation != null && annotation.getId() != -1 && annotationsArray.indexOfKey(annotation.getId()) > -1; - } - - private void logNonAdded(@NonNull Annotation annotation) { - Logger.w(TAG, String.format( - "Attempting to update non-added %s with value %s", annotation.getClass().getCanonicalName(), annotation) - ); - } - - // - // Click event - // - - boolean onTap(@NonNull PointF tapPoint) { - MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint); - long markerId = new MarkerHitResolver(mapboxMap).execute(markerHit); - if (markerId != NO_ANNOTATION_ID) { - if (isClickHandledForMarker(markerId)) { - return true; - } - } - - ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint); - Annotation annotation = new ShapeAnnotationHitResolver(shapeAnnotations).execute(shapeAnnotationHit); - return annotation != null && handleClickForShapeAnnotation(annotation); - } - - private ShapeAnnotationHit getShapeAnnotationHitFromTap(PointF tapPoint) { - float touchTargetSide = Mapbox.getApplicationContext().getResources().getDimension(R.dimen.mapbox_eight_dp); - RectF tapRect = new RectF( - tapPoint.x - touchTargetSide, - tapPoint.y - touchTargetSide, - tapPoint.x + touchTargetSide, - tapPoint.y + touchTargetSide - ); - return new ShapeAnnotationHit(tapRect); - } - - private boolean handleClickForShapeAnnotation(Annotation annotation) { - if (annotation instanceof Polygon && onPolygonClickListener != null) { - onPolygonClickListener.onPolygonClick((Polygon) annotation); - return true; - } else if (annotation instanceof Polyline && onPolylineClickListener != null) { - onPolylineClickListener.onPolylineClick((Polyline) annotation); - return true; - } - return false; - } - - private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) { - int touchSurfaceWidth = (int) (iconManager.getHighestIconHeight() * 1.5); - int touchSurfaceHeight = (int) (iconManager.getHighestIconWidth() * 1.5); - final RectF tapRect = new RectF(tapPoint.x - touchSurfaceWidth, - tapPoint.y - touchSurfaceHeight, - tapPoint.x + touchSurfaceWidth, - tapPoint.y + touchSurfaceHeight - ); - return new MarkerHit(tapRect, getMarkersInRect(tapRect)); - } - - private boolean isClickHandledForMarker(long markerId) { - Marker marker = (Marker) getAnnotation(markerId); - boolean handledDefaultClick = onClickMarker(marker); - if (!handledDefaultClick) { - toggleMarkerSelectionState(marker); - } - return true; - } - - private boolean onClickMarker(@NonNull Marker marker) { - return onMarkerClickListener != null && onMarkerClickListener.onMarkerClick(marker); - } - - private void toggleMarkerSelectionState(@NonNull Marker marker) { - if (!selectedMarkers.contains(marker)) { - selectMarker(marker); - } else { - deselectMarker(marker); - } - } - - private static class ShapeAnnotationHitResolver { - - private ShapeAnnotations shapeAnnotations; - - ShapeAnnotationHitResolver(ShapeAnnotations shapeAnnotations) { - this.shapeAnnotations = shapeAnnotations; - } - - @Nullable - public Annotation execute(@NonNull ShapeAnnotationHit shapeHit) { - Annotation foundAnnotation = null; - List annotations = shapeAnnotations.obtainAllIn(shapeHit.tapPoint); - if (annotations.size() > 0) { - foundAnnotation = annotations.get(0); - } - return foundAnnotation; - } - } - - private static class MarkerHitResolver { - - @NonNull - private final Projection projection; - private final int minimalTouchSize; - - @Nullable - private View view; - - private Bitmap bitmap; - private int bitmapWidth; - private int bitmapHeight; - private PointF markerLocation; - - @NonNull - private Rect hitRectView = new Rect(); - @NonNull - private RectF hitRectMarker = new RectF(); - @NonNull - private RectF highestSurfaceIntersection = new RectF(); - - private long closestMarkerId = NO_ANNOTATION_ID; - - MarkerHitResolver(@NonNull MapboxMap mapboxMap) { - this.projection = mapboxMap.getProjection(); - this.minimalTouchSize = (int) (32 * Mapbox.getApplicationContext().getResources().getDisplayMetrics().density); - } - - public long execute(@NonNull MarkerHit markerHit) { - resolveForMarkers(markerHit); - return closestMarkerId; - } - - private void resolveForMarkers(MarkerHit markerHit) { - for (Marker marker : markerHit.markers) { - resolveForMarker(markerHit, marker); - } - } - - private void resolveForMarker(@NonNull MarkerHit markerHit, Marker marker) { - markerLocation = projection.toScreenLocation(marker.getPosition()); - bitmap = marker.getIcon().getBitmap(); - - bitmapHeight = bitmap.getHeight(); - if (bitmapHeight < minimalTouchSize) { - bitmapHeight = minimalTouchSize; - } - - bitmapWidth = bitmap.getWidth(); - if (bitmapWidth < minimalTouchSize) { - bitmapWidth = minimalTouchSize; - } - - hitRectMarker.set(0, 0, bitmapWidth, bitmapHeight); - hitRectMarker.offsetTo( - markerLocation.x - bitmapWidth / 2, - markerLocation.y - bitmapHeight / 2 - ); - hitTestMarker(markerHit, marker, hitRectMarker); - } - - private void hitTestMarker(MarkerHit markerHit, @NonNull Marker marker, RectF hitRectMarker) { - if (hitRectMarker.contains(markerHit.getTapPointX(), markerHit.getTapPointY())) { - hitRectMarker.intersect(markerHit.tapRect); - if (isRectangleHighestSurfaceIntersection(hitRectMarker)) { - highestSurfaceIntersection = new RectF(hitRectMarker); - closestMarkerId = marker.getId(); - } - } - } - - private boolean isRectangleHighestSurfaceIntersection(RectF rectF) { - return rectF.width() * rectF.height() > highestSurfaceIntersection.width() * highestSurfaceIntersection.height(); - } - } - - private static class ShapeAnnotationHit { - private final RectF tapPoint; - - ShapeAnnotationHit(RectF tapPoint) { - this.tapPoint = tapPoint; - } - } - - private static class MarkerHit { - private final RectF tapRect; - private final List markers; - - MarkerHit(RectF tapRect, List markers) { - this.tapRect = tapRect; - this.markers = markers; - } - - float getTapPointX() { - return tapRect.centerX(); - } - - float getTapPointY() { - return tapRect.centerY(); - } - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Annotations.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Annotations.java deleted file mode 100644 index ae41cbb0cb..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Annotations.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - - -import android.support.annotation.NonNull; - -import com.mapbox.mapboxsdk.annotations.Annotation; - -import java.util.List; - -/** - * Interface that defines convenient methods for working with a {@link Annotation}'s collection. - */ -interface Annotations { - Annotation obtainBy(long id); - - List obtainAll(); - - void removeBy(long id); - - void removeBy(@NonNull Annotation annotation); - - void removeBy(@NonNull List annotationList); - - void removeAll(); -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java deleted file mode 100644 index 3a0824ad11..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.Bitmap; - -import android.support.annotation.NonNull; -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.IconFactory; -import com.mapbox.mapboxsdk.annotations.Marker; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Responsible for managing icons added to the Map. - *

- * Maintains a {@link List} of {@link Icon} and is responsible for initialising default markers. - *

- *

- * Keep track of icons added and the resulting average icon size. This is used internally by our - * gestures detection to calculate the size of a touch target. - *

- */ -class IconManager { - - private final Map iconMap = new HashMap<>(); - - private NativeMap nativeMap; - private int highestIconWidth; - private int highestIconHeight; - - IconManager(NativeMap nativeMap) { - this.nativeMap = nativeMap; - } - - Icon loadIconForMarker(@NonNull Marker marker) { - Icon icon = marker.getIcon(); - if (icon == null) { - // TODO replace with anchor implementation, we are faking an anchor by adding extra pixels and diving height by 2 - icon = loadDefaultIconForMarker(marker); - } else { - updateHighestIconSize(icon); - } - addIcon(icon); - return icon; - } - - int getTopOffsetPixelsForIcon(@NonNull Icon icon) { - return (int) (nativeMap.getTopOffsetPixelsForAnnotationSymbol(icon.getId()) * nativeMap.getPixelRatio()); - } - - int getHighestIconWidth() { - return highestIconWidth; - } - - int getHighestIconHeight() { - return highestIconHeight; - } - - private Icon loadDefaultIconForMarker(Marker marker) { - Icon icon = IconFactory.getInstance(Mapbox.getApplicationContext()).defaultMarker(); - Bitmap bitmap = icon.getBitmap(); - updateHighestIconSize(bitmap.getWidth(), bitmap.getHeight() / 2); - marker.setIcon(icon); - return icon; - } - - private void addIcon(@NonNull Icon icon) { - addIcon(icon, true); - } - - private void addIcon(@NonNull Icon icon, boolean addIconToMap) { - if (!iconMap.keySet().contains(icon)) { - iconMap.put(icon, 1); - if (addIconToMap) { - loadIcon(icon); - } - } else { - iconMap.put(icon, iconMap.get(icon) + 1); - } - } - - private void updateHighestIconSize(Icon icon) { - updateHighestIconSize(icon.getBitmap()); - } - - private void updateHighestIconSize(Bitmap bitmap) { - updateHighestIconSize(bitmap.getWidth(), bitmap.getHeight()); - } - - private void updateHighestIconSize(int width, int height) { - if (width > highestIconWidth) { - highestIconWidth = width; - } - - if (height > highestIconHeight) { - highestIconHeight = height; - } - } - - private void loadIcon(Icon icon) { - Bitmap bitmap = icon.getBitmap(); - nativeMap.addAnnotationIcon(icon.getId(), - bitmap.getWidth(), - bitmap.getHeight(), - icon.getScale(), - icon.toBytes()); - } - - void reloadIcons() { - for (Icon icon : iconMap.keySet()) { - loadIcon(icon); - } - } - - void ensureIconLoaded(@NonNull Marker marker, @NonNull MapboxMap mapboxMap) { - Icon icon = marker.getIcon(); - if (icon == null) { - icon = loadDefaultIconForMarker(marker); - } - addIcon(icon); - setTopOffsetPixels(marker, mapboxMap, icon); - } - - private void setTopOffsetPixels(Marker marker, @NonNull MapboxMap mapboxMap, @NonNull Icon icon) { - // this seems to be a costly operation according to the profiler so I'm trying to save some calls - Marker previousMarker = marker.getId() != -1 ? (Marker) mapboxMap.getAnnotation(marker.getId()) : null; - if (previousMarker == null || previousMarker.getIcon() == null || previousMarker.getIcon() != marker.getIcon()) { - marker.setTopOffsetPixels(getTopOffsetPixelsForIcon(icon)); - } - } - - void iconCleanup(@NonNull Icon icon) { - Integer refCounter = iconMap.get(icon); - if (refCounter != null) { - refCounter--; - if (refCounter == 0) { - remove(icon); - } else { - updateIconRefCounter(icon, refCounter); - } - } - } - - private void remove(Icon icon) { - nativeMap.removeAnnotationIcon(icon.getId()); - iconMap.remove(icon); - } - - private void updateIconRefCounter(Icon icon, int refCounter) { - iconMap.put(icon, refCounter); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java deleted file mode 100644 index 434244a7c1..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.support.annotation.Nullable; -import android.text.TextUtils; - -import com.mapbox.mapboxsdk.annotations.InfoWindow; -import com.mapbox.mapboxsdk.annotations.Marker; - -import java.util.ArrayList; -import java.util.List; - -/** - * Responsible for managing InfoWindows shown on the Map. - *

- * Maintains a {@link List} of opened {@link InfoWindow} and tracks configurations as - * allowConcurrentMultipleInfoWindows which allows to have multiple {@link InfoWindow} open at the - * same time. Responsible for managing listeners as - * {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowClickListener} and - * {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowLongClickListener}. - *

- */ -class InfoWindowManager { - - private final List infoWindows = new ArrayList<>(); - - @Nullable - private MapboxMap.InfoWindowAdapter infoWindowAdapter; - private boolean allowConcurrentMultipleInfoWindows; - - @Nullable - private MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener; - @Nullable - private MapboxMap.OnInfoWindowLongClickListener onInfoWindowLongClickListener; - @Nullable - private MapboxMap.OnInfoWindowCloseListener onInfoWindowCloseListener; - - void update() { - if (!infoWindows.isEmpty()) { - for (InfoWindow infoWindow : infoWindows) { - infoWindow.update(); - } - } - } - - void setInfoWindowAdapter(@Nullable MapboxMap.InfoWindowAdapter infoWindowAdapter) { - this.infoWindowAdapter = infoWindowAdapter; - } - - @Nullable - MapboxMap.InfoWindowAdapter getInfoWindowAdapter() { - return infoWindowAdapter; - } - - void setAllowConcurrentMultipleOpenInfoWindows(boolean allow) { - allowConcurrentMultipleInfoWindows = allow; - } - - boolean isAllowConcurrentMultipleOpenInfoWindows() { - return allowConcurrentMultipleInfoWindows; - } - - boolean isInfoWindowValidForMarker(@Nullable Marker marker) { - return marker != null && (!TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet())); - } - - void setOnInfoWindowClickListener(@Nullable MapboxMap.OnInfoWindowClickListener listener) { - onInfoWindowClickListener = listener; - } - - @Nullable - MapboxMap.OnInfoWindowClickListener getOnInfoWindowClickListener() { - return onInfoWindowClickListener; - } - - void setOnInfoWindowLongClickListener(@Nullable MapboxMap.OnInfoWindowLongClickListener listener) { - onInfoWindowLongClickListener = listener; - } - - @Nullable - MapboxMap.OnInfoWindowLongClickListener getOnInfoWindowLongClickListener() { - return onInfoWindowLongClickListener; - } - - void setOnInfoWindowCloseListener(@Nullable MapboxMap.OnInfoWindowCloseListener listener) { - onInfoWindowCloseListener = listener; - } - - @Nullable - MapboxMap.OnInfoWindowCloseListener getOnInfoWindowCloseListener() { - return onInfoWindowCloseListener; - } - - public void add(InfoWindow infoWindow) { - infoWindows.add(infoWindow); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index b9550ec607..5bd3102672 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -40,7 +40,6 @@ final class MapGestureDetector { private final Transform transform; private final Projection projection; private final UiSettings uiSettings; - private final AnnotationManager annotationManager; private final CameraChangeDispatcher cameraChangeDispatcher; // new map touch API @@ -88,8 +87,7 @@ final class MapGestureDetector { private Handler animationsTimeoutHandler = new Handler(); MapGestureDetector(@Nullable Context context, Transform transform, Projection projection, UiSettings uiSettings, - AnnotationManager annotationManager, CameraChangeDispatcher cameraChangeDispatcher) { - this.annotationManager = annotationManager; + CameraChangeDispatcher cameraChangeDispatcher) { this.transform = transform; this.projection = projection; this.uiSettings = uiSettings; @@ -315,18 +313,7 @@ final class MapGestureDetector { @Override public boolean onSingleTapConfirmed(MotionEvent motionEvent) { - PointF tapPoint = new PointF(motionEvent.getX(), motionEvent.getY()); - boolean tapHandled = annotationManager.onTap(tapPoint); - - if (!tapHandled) { - if (uiSettings.isDeselectMarkersOnTap()) { - // deselect any selected marker - annotationManager.deselectMarkers(); - } - - notifyOnMapClickListeners(tapPoint); - } - + notifyOnMapClickListeners(new PointF(motionEvent.getX(), motionEvent.getY())); return true; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 42c607360d..9d3b24163a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -10,7 +10,6 @@ import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.UiThread; -import android.support.v4.util.LongSparseArray; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -23,7 +22,6 @@ import com.mapbox.android.gestures.AndroidGesturesManager; import com.mapbox.mapboxsdk.MapStrictMode; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.R; -import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException; import com.mapbox.mapboxsdk.location.LocationComponent; @@ -157,24 +155,13 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { // setup components for MapboxMap creation Projection proj = new Projection(nativeMapView, this); UiSettings uiSettings = new UiSettings(proj, focalInvalidator, compassView, attrView, logoView, getPixelRatio()); - LongSparseArray annotationsArray = new LongSparseArray<>(); - IconManager iconManager = new IconManager(nativeMapView); - Annotations annotations = new AnnotationContainer(nativeMapView, annotationsArray); - Markers markers = new MarkerContainer(nativeMapView, annotationsArray, iconManager); - Polygons polygons = new PolygonContainer(nativeMapView, annotationsArray); - Polylines polylines = new PolylineContainer(nativeMapView, annotationsArray); - ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(nativeMapView, annotationsArray); - AnnotationManager annotationManager = new AnnotationManager(this, annotationsArray, iconManager, - annotations, markers, polygons, polylines, shapeAnnotations); Transform transform = new Transform(this, nativeMapView, cameraDispatcher); // MapboxMap mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener, cameraDispatcher); - mapboxMap.injectAnnotationManager(annotationManager); // user input - mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, - annotationManager, cameraDispatcher); + mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, cameraDispatcher); mapKeyListener = new MapKeyListener(transform, uiSettings, mapGestureDetector); // compass @@ -1158,17 +1145,13 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } private class MapCallback implements OnDidFinishLoadingStyleListener, - OnDidFinishRenderingFrameListener, OnDidFinishLoadingMapListener, - OnCameraIsChangingListener, OnCameraDidChangeListener, OnDidFailLoadingMapListener { + OnDidFinishRenderingFrameListener, OnDidFailLoadingMapListener { private final List onMapReadyCallbackList = new ArrayList<>(); MapCallback() { addOnDidFinishLoadingStyleListener(this); addOnDidFinishRenderingFrameListener(this); - addOnDidFinishLoadingMapListener(this); - addOnCameraIsChangingListener(this); - addOnCameraDidChangeListener(this); addOnDidFailLoadingMapListener(this); } @@ -1203,9 +1186,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { onMapReadyCallbackList.clear(); removeOnDidFinishLoadingStyleListener(this); removeOnDidFinishRenderingFrameListener(this); - removeOnDidFinishLoadingMapListener(this); - removeOnCameraIsChangingListener(this); - removeOnCameraDidChangeListener(this); removeOnDidFailLoadingMapListener(this); } @@ -1229,27 +1209,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { mapboxMap.onUpdateFullyRendered(); } } - - @Override - public void onDidFinishLoadingMap() { - if (mapboxMap != null) { - mapboxMap.onUpdateRegionChange(); - } - } - - @Override - public void onCameraIsChanging() { - if (mapboxMap != null) { - mapboxMap.onUpdateRegionChange(); - } - } - - @Override - public void onCameraDidChange(boolean animated) { - if (mapboxMap != null) { - mapboxMap.onUpdateRegionChange(); - } - } } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index e03358158f..55943f7e4e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -11,7 +11,6 @@ import android.support.annotation.Nullable; import android.support.annotation.Size; import android.support.annotation.UiThread; import android.text.TextUtils; -import android.view.View; import com.mapbox.android.gestures.AndroidGesturesManager; import com.mapbox.android.gestures.MoveGestureDetector; import com.mapbox.android.gestures.RotateGestureDetector; @@ -20,14 +19,6 @@ import com.mapbox.android.gestures.StandardScaleGestureDetector; import com.mapbox.geojson.Feature; import com.mapbox.geojson.Geometry; import com.mapbox.mapboxsdk.MapStrictMode; -import com.mapbox.mapboxsdk.annotations.Annotation; -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdate; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; @@ -35,7 +26,6 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.location.LocationComponent; -import com.mapbox.mapboxsdk.log.Logger; import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition; import com.mapbox.mapboxsdk.style.expressions.Expression; @@ -68,7 +58,6 @@ public final class MapboxMap { private Style.OnStyleLoaded styleLoadedCallback; private LocationComponent locationComponent; - private AnnotationManager annotationManager; @Nullable private MapboxMap.OnFpsChangedListener onFpsChangedListener; @@ -186,8 +175,6 @@ public final class MapboxMap { */ void onPreMapReady() { transform.invalidateCameraPosition(); - annotationManager.reloadMarkers(); - annotationManager.adjustTopOffsetPixels(this); } /** @@ -215,13 +202,6 @@ public final class MapboxMap { styleLoadedCallback = null; } - /** - * Called when the region is changing or has changed. - */ - void onUpdateRegionChange() { - annotationManager.update(); - } - /** * Called when the map frame is fully rendered. */ @@ -858,520 +838,6 @@ public final class MapboxMap { awaitingStyleGetters.clear(); } - // - // Annotations - // - - /** - *

- * Adds a marker to this map. - *

- * The marker's icon is rendered on the map at the location {@code Marker.position}. - * If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet. - * - * @param markerOptions A marker options object that defines how to render the marker - * @return The {@code Marker} that was added to the map - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public Marker addMarker(@NonNull MarkerOptions markerOptions) { - return annotationManager.addMarker(markerOptions, this); - } - - /** - *

- * Adds a marker to this map. - *

- * The marker's icon is rendered on the map at the location {@code Marker.position}. - * If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet. - * - * @param markerOptions A marker options object that defines how to render the marker - * @return The {@code Marker} that was added to the map - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public Marker addMarker(@NonNull BaseMarkerOptions markerOptions) { - return annotationManager.addMarker(markerOptions, this); - } - - /** - *

- * Adds multiple markers to this map. - *

- * The marker's icon is rendered on the map at the location {@code Marker.position}. - * If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet. - * - * @param markerOptionsList A list of marker options objects that defines how to render the markers - * @return A list of the {@code Marker}s that were added to the map - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public List addMarkers(@NonNull List markerOptionsList) { - return annotationManager.addMarkers(markerOptionsList, this); - } - - /** - *

- * Updates a marker on this map. Does nothing if the marker isn't already added. - *

- * - * @param updatedMarker An updated marker object - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void updateMarker(@NonNull Marker updatedMarker) { - annotationManager.updateMarker(updatedMarker, this); - } - - /** - * Adds a polyline to this map. - * - * @param polylineOptions A polyline options object that defines how to render the polyline - * @return The {@code Polyine} that was added to the map - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public Polyline addPolyline(@NonNull PolylineOptions polylineOptions) { - return annotationManager.addPolyline(polylineOptions, this); - } - - /** - * Adds multiple polylines to this map. - * - * @param polylineOptionsList A list of polyline options objects that defines how to render the polylines. - * @return A list of the {@code Polyline}s that were added to the map. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public List addPolylines(@NonNull List polylineOptionsList) { - return annotationManager.addPolylines(polylineOptionsList, this); - } - - /** - * Update a polyline on this map. - * - * @param polyline An updated polyline object. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void updatePolyline(@NonNull Polyline polyline) { - annotationManager.updatePolyline(polyline); - } - - /** - * Adds a polygon to this map. - * - * @param polygonOptions A polygon options object that defines how to render the polygon. - * @return The {@code Polygon} that was added to the map. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public Polygon addPolygon(@NonNull PolygonOptions polygonOptions) { - return annotationManager.addPolygon(polygonOptions, this); - } - - /** - * Adds multiple polygons to this map. - * - * @param polygonOptionsList A list of polygon options objects that defines how to render the polygons - * @return A list of the {@code Polygon}s that were added to the map - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public List addPolygons(@NonNull List polygonOptionsList) { - return annotationManager.addPolygons(polygonOptionsList, this); - } - - /** - * Update a polygon on this map. - * - * @param polygon An updated polygon object - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void updatePolygon(@NonNull Polygon polygon) { - annotationManager.updatePolygon(polygon); - } - - /** - *

- * Convenience method for removing a Marker from the map. - *

- * Calls removeAnnotation() internally. - * - * @param marker Marker to remove - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void removeMarker(@NonNull Marker marker) { - annotationManager.removeAnnotation(marker); - } - - /** - *

- * Convenience method for removing a Polyline from the map. - *

- * Calls removeAnnotation() internally. - * - * @param polyline Polyline to remove - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void removePolyline(@NonNull Polyline polyline) { - annotationManager.removeAnnotation(polyline); - } - - /** - *

- * Convenience method for removing a Polygon from the map. - *

- * Calls removeAnnotation() internally. - * - * @param polygon Polygon to remove - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void removePolygon(@NonNull Polygon polygon) { - annotationManager.removeAnnotation(polygon); - } - - /** - * Removes an annotation from the map. - * - * @param annotation The annotation object to remove. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void removeAnnotation(@NonNull Annotation annotation) { - annotationManager.removeAnnotation(annotation); - } - - /** - * Removes an annotation from the map - * - * @param id The identifier associated to the annotation to be removed - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void removeAnnotation(long id) { - annotationManager.removeAnnotation(id); - } - - /** - * Removes multiple annotations from the map. - * - * @param annotationList A list of annotation objects to remove. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void removeAnnotations(@NonNull List annotationList) { - annotationManager.removeAnnotations(annotationList); - } - - /** - * Removes all annotations from the map. - * - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void removeAnnotations() { - annotationManager.removeAnnotations(); - } - - /** - * Removes all markers, polylines, polygons, overlays, etc from the map. - * - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void clear() { - annotationManager.removeAnnotations(); - } - - /** - * Return a annotation based on its id. - * - * @param id the id used to look up an annotation - * @return An annotation with a matched id, null is returned if no match was found - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @Nullable - public Annotation getAnnotation(long id) { - return annotationManager.getAnnotation(id); - } - - /** - * Returns a list of all the annotations on the map. - * - * @return A list of all the annotation objects. The returned object is a copy so modifying this - * list will not update the map - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public List getAnnotations() { - return annotationManager.getAnnotations(); - } - - /** - * Returns a list of all the markers on the map. - * - * @return A list of all the markers objects. The returned object is a copy so modifying this - * list will not update the map. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public List getMarkers() { - return annotationManager.getMarkers(); - } - - /** - * Returns a list of all the polygons on the map. - * - * @return A list of all the polygon objects. The returned object is a copy so modifying this - * list will not update the map. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public List getPolygons() { - return annotationManager.getPolygons(); - } - - /** - * Returns a list of all the polylines on the map. - * - * @return A list of all the polylines objects. The returned object is a copy so modifying this - * list will not update the map. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public List getPolylines() { - return annotationManager.getPolylines(); - } - - /** - * Sets a callback that's invoked when the user clicks on a marker. - * - * @param listener The callback that's invoked when the user clicks on a marker. - * To unset the callback, use null. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void setOnMarkerClickListener(@Nullable OnMarkerClickListener listener) { - annotationManager.setOnMarkerClickListener(listener); - } - - /** - * Sets a callback that's invoked when the user clicks on a polygon. - * - * @param listener The callback that's invoked when the user clicks on a polygon. - * To unset the callback, use null. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void setOnPolygonClickListener(@Nullable OnPolygonClickListener listener) { - annotationManager.setOnPolygonClickListener(listener); - } - - /** - * Sets a callback that's invoked when the user clicks on a polyline. - * - * @param listener The callback that's invoked when the user clicks on a polyline. - * To unset the callback, use null. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void setOnPolylineClickListener(@Nullable OnPolylineClickListener listener) { - annotationManager.setOnPolylineClickListener(listener); - } - - /** - *

- * Selects a marker. The selected marker will have it's info window opened. - * Any other open info windows will be closed unless isAllowConcurrentMultipleOpenInfoWindows() - * is true. - *

- * Selecting an already selected marker will have no effect. - * - * @param marker The marker to select. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void selectMarker(@NonNull Marker marker) { - if (marker == null) { - Logger.w(TAG, "marker was null, so just returning"); - return; - } - annotationManager.selectMarker(marker); - } - - /** - * Deselects any currently selected marker. All markers will have it's info window closed. - * - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void deselectMarkers() { - annotationManager.deselectMarkers(); - } - - /** - * Deselects a currently selected marker. The selected marker will have it's info window closed. - * - * @param marker the marker to deselect - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void deselectMarker(@NonNull Marker marker) { - annotationManager.deselectMarker(marker); - } - - /** - * Gets the currently selected marker. - * - * @return The currently selected marker. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @NonNull - public List getSelectedMarkers() { - return annotationManager.getSelectedMarkers(); - } - - // - // InfoWindow - // - - /** - *

- * Sets a custom renderer for the contents of info window. - *

- * When set your callback is invoked when an info window is about to be shown. By returning - * a custom {@link View}, the default info window will be replaced. - * - * @param infoWindowAdapter The callback to be invoked when an info window will be shown. - * To unset the callback, use null. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void setInfoWindowAdapter(@Nullable InfoWindowAdapter infoWindowAdapter) { - annotationManager.getInfoWindowManager().setInfoWindowAdapter(infoWindowAdapter); - } - - /** - * Gets the callback to be invoked when an info window will be shown. - * - * @return The callback to be invoked when an info window will be shown. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - @Nullable - public InfoWindowAdapter getInfoWindowAdapter() { - return annotationManager.getInfoWindowManager().getInfoWindowAdapter(); - } - - /** - * Changes whether the map allows concurrent multiple infowindows to be shown. - * - * @param allow If true, map allows concurrent multiple infowindows to be shown. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public void setAllowConcurrentMultipleOpenInfoWindows(boolean allow) { - annotationManager.getInfoWindowManager().setAllowConcurrentMultipleOpenInfoWindows(allow); - } - - /** - * Returns whether the map allows concurrent multiple infowindows to be shown. - * - * @return If true, map allows concurrent multiple infowindows to be shown. - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public boolean isAllowConcurrentMultipleOpenInfoWindows() { - return annotationManager.getInfoWindowManager().isAllowConcurrentMultipleOpenInfoWindows(); - } - // // LatLngBounds // @@ -1807,66 +1273,6 @@ public final class MapboxMap { onGesturesManagerInteractionListener.onRemoveMapLongClickListener(listener); } - /** - * Sets a callback that's invoked when the user clicks on an info window. - * - * @param listener The callback that's invoked when the user clicks on an info window. - * To unset the callback, use null. - */ - public void setOnInfoWindowClickListener(@Nullable OnInfoWindowClickListener listener) { - annotationManager.getInfoWindowManager().setOnInfoWindowClickListener(listener); - } - - /** - * Return the InfoWindow click listener - * - * @return Current active InfoWindow Click Listener - */ - @Nullable - public OnInfoWindowClickListener getOnInfoWindowClickListener() { - return annotationManager.getInfoWindowManager().getOnInfoWindowClickListener(); - } - - /** - * Sets a callback that's invoked when a marker's info window is long pressed. - * - * @param listener The callback that's invoked when a marker's info window is long pressed. To unset the callback, - * use null. - */ - public void setOnInfoWindowLongClickListener(@Nullable OnInfoWindowLongClickListener - listener) { - annotationManager.getInfoWindowManager().setOnInfoWindowLongClickListener(listener); - } - - /** - * Return the InfoWindow long click listener - * - * @return Current active InfoWindow long Click Listener - */ - @Nullable - public OnInfoWindowLongClickListener getOnInfoWindowLongClickListener() { - return annotationManager.getInfoWindowManager().getOnInfoWindowLongClickListener(); - } - - /** - * Set an callback to be invoked when an InfoWindow closes. - * - * @param listener callback invoked when an InfoWindow closes - */ - public void setOnInfoWindowCloseListener(@Nullable OnInfoWindowCloseListener listener) { - annotationManager.getInfoWindowManager().setOnInfoWindowCloseListener(listener); - } - - /** - * Return the InfoWindow close listener - * - * @return Current active InfoWindow Close Listener - */ - @Nullable - public OnInfoWindowCloseListener getOnInfoWindowCloseListener() { - return annotationManager.getInfoWindowManager().getOnInfoWindowCloseListener(); - } - // // Invalidate // @@ -1954,9 +1360,6 @@ public final class MapboxMap { this.locationComponent = locationComponent; } - void injectAnnotationManager(AnnotationManager annotationManager) { - this.annotationManager = annotationManager.bind(this); - } /** * Returns the {@link LocationComponent} that can be used to display user's location on the map. @@ -2194,127 +1597,6 @@ public final class MapboxMap { boolean onMapLongClick(@NonNull LatLng point); } - /** - * Interface definition for a callback to be invoked when the user clicks on a marker. - * - * @see MapboxMap#setOnMarkerClickListener(OnMarkerClickListener) - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public interface OnMarkerClickListener { - /** - * Called when the user clicks on a marker. - * - * @param marker The marker the user clicked on. - * @return If true the listener has consumed the event and the info window will not be shown. - */ - boolean onMarkerClick(@NonNull Marker marker); - } - - /** - * Interface definition for a callback to be invoked when the user clicks on a polygon. - * - * @see MapboxMap#setOnPolygonClickListener(OnPolygonClickListener) - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public interface OnPolygonClickListener { - /** - * Called when the user clicks on a polygon. - * - * @param polygon The polygon the user clicked on. - */ - void onPolygonClick(@NonNull Polygon polygon); - } - - /** - * Interface definition for a callback to be invoked when the user clicks on a polyline. - * - * @see MapboxMap#setOnPolylineClickListener(OnPolylineClickListener) - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public interface OnPolylineClickListener { - /** - * Called when the user clicks on a polyline. - * - * @param polyline The polyline the user clicked on. - */ - void onPolylineClick(@NonNull Polyline polyline); - } - - /** - * Interface definition for a callback to be invoked when the user clicks on an info window. - * - * @see MapboxMap#setOnInfoWindowClickListener(OnInfoWindowClickListener) - */ - public interface OnInfoWindowClickListener { - /** - * Called when the user clicks on an info window. - * - * @param marker The marker of the info window the user clicked on. - * @return If true the listener has consumed the event and the info window will not be closed. - */ - boolean onInfoWindowClick(@NonNull Marker marker); - } - - /** - * Interface definition for a callback to be invoked when the user long presses on a marker's info window. - * - * @see MapboxMap#setOnInfoWindowClickListener(OnInfoWindowClickListener) - */ - public interface OnInfoWindowLongClickListener { - - /** - * Called when the user makes a long-press gesture on the marker's info window. - * - * @param marker The marker were the info window is attached to - */ - void onInfoWindowLongClick(@NonNull Marker marker); - } - - /** - * Interface definition for a callback to be invoked when a marker's info window is closed. - * - * @see MapboxMap#setOnInfoWindowCloseListener(OnInfoWindowCloseListener) - */ - public interface OnInfoWindowCloseListener { - - /** - * Called when the marker's info window is closed. - * - * @param marker The marker of the info window that was closed. - */ - void onInfoWindowClose(@NonNull Marker marker); - } - - /** - * Interface definition for a callback to be invoked when an info window will be shown. - * - * @see MapboxMap#setInfoWindowAdapter(InfoWindowAdapter) - * @deprecated As of 7.0.0, - * use - * Mapbox Annotation Plugin instead - */ - @Deprecated - public interface InfoWindowAdapter { - /** - * Called when an info window will be shown as a result of a marker click. - * - * @param marker The marker the user clicked on. - * @return View to be shown as a info window. If null is returned the default - * info window will be shown. - */ - @Nullable - View getInfoWindow(@NonNull Marker marker); - } - /** * Interface definition for a callback to be invoked when a task is complete or cancelled. */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java deleted file mode 100644 index b408d9f5c5..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.RectF; -import android.support.annotation.NonNull; -import android.support.v4.util.LongSparseArray; - -import com.mapbox.mapboxsdk.annotations.Annotation; -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.Marker; - -import java.util.ArrayList; -import java.util.List; - -/** - * Encapsulates {@link Marker}'s functionality. - */ -class MarkerContainer implements Markers { - - private final NativeMap nativeMapView; - private final LongSparseArray annotations; - private final IconManager iconManager; - - MarkerContainer(NativeMap nativeMapView, LongSparseArray annotations, IconManager iconManager) { - this.nativeMapView = nativeMapView; - this.annotations = annotations; - this.iconManager = iconManager; - } - - @Override - public Marker addBy(@NonNull BaseMarkerOptions markerOptions, @NonNull MapboxMap mapboxMap) { - Marker marker = prepareMarker(markerOptions); - long id = nativeMapView != null ? nativeMapView.addMarker(marker) : 0; - marker.setMapboxMap(mapboxMap); - marker.setId(id); - annotations.put(id, marker); - return marker; - } - - @NonNull - @Override - public List addBy(@NonNull List markerOptionsList, @NonNull MapboxMap - mapboxMap) { - int count = markerOptionsList.size(); - List markers = new ArrayList<>(count); - if (nativeMapView != null && count > 0) { - BaseMarkerOptions markerOptions; - Marker marker; - for (int i = 0; i < count; i++) { - markerOptions = markerOptionsList.get(i); - marker = prepareMarker(markerOptions); - markers.add(marker); - } - - if (markers.size() > 0) { - long[] ids = nativeMapView.addMarkers(markers); - for (int i = 0; i < ids.length; i++) { - Marker createdMarker = markers.get(i); - createdMarker.setMapboxMap(mapboxMap); - createdMarker.setId(ids[i]); - annotations.put(ids[i], createdMarker); - } - } - } - return markers; - } - - @Override - public void update(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap) { - ensureIconLoaded(updatedMarker, mapboxMap); - nativeMapView.updateMarker(updatedMarker); - annotations.setValueAt(annotations.indexOfKey(updatedMarker.getId()), updatedMarker); - } - - @NonNull - @Override - public List obtainAll() { - List markers = new ArrayList<>(); - Annotation annotation; - for (int i = 0; i < annotations.size(); i++) { - annotation = annotations.get(annotations.keyAt(i)); - if (annotation instanceof Marker) { - markers.add((Marker) annotation); - } - } - return markers; - } - - @NonNull - @Override - public List obtainAllIn(@NonNull RectF rectangle) { - RectF rect = nativeMapView.getDensityDependantRectangle(rectangle); - long[] ids = nativeMapView.queryPointAnnotations(rect); - List idsList = new ArrayList<>(ids.length); - for (long id : ids) { - idsList.add(id); - } - - List annotations = new ArrayList<>(ids.length); - List annotationList = obtainAnnotations(); - int count = annotationList.size(); - for (int i = 0; i < count; i++) { - Annotation annotation = annotationList.get(i); - if (annotation instanceof com.mapbox.mapboxsdk.annotations.Marker && idsList.contains(annotation.getId())) { - annotations.add((com.mapbox.mapboxsdk.annotations.Marker) annotation); - } - } - - return new ArrayList<>(annotations); - } - - @Override - public void reload() { - iconManager.reloadIcons(); - int count = annotations.size(); - for (int i = 0; i < count; i++) { - Annotation annotation = annotations.get(i); - if (annotation instanceof Marker) { - Marker marker = (Marker) annotation; - nativeMapView.removeAnnotation(annotation.getId()); - long newId = nativeMapView.addMarker(marker); - marker.setId(newId); - } - } - } - - private Marker prepareMarker(BaseMarkerOptions markerOptions) { - Marker marker = markerOptions.getMarker(); - Icon icon = iconManager.loadIconForMarker(marker); - marker.setTopOffsetPixels(iconManager.getTopOffsetPixelsForIcon(icon)); - return marker; - } - - private void ensureIconLoaded(Marker marker, @NonNull MapboxMap mapboxMap) { - iconManager.ensureIconLoaded(marker, mapboxMap); - } - - @NonNull - private List obtainAnnotations() { - List annotations = new ArrayList<>(); - for (int i = 0; i < this.annotations.size(); i++) { - annotations.add(this.annotations.get(this.annotations.keyAt(i))); - } - return annotations; - } -} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Markers.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Markers.java deleted file mode 100644 index 62859d58a8..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Markers.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.RectF; -import android.support.annotation.NonNull; - -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; - -import java.util.List; - -/** - * Interface that defines convenient methods for working with a {@link Marker}'s collection. - */ -interface Markers { - Marker addBy(@NonNull BaseMarkerOptions markerOptions, @NonNull MapboxMap mapboxMap); - - List addBy(@NonNull List markerOptionsList, @NonNull MapboxMap mapboxMap); - - void update(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap); - - List obtainAll(); - - @NonNull - List obtainAllIn(@NonNull RectF rectangle); - - void reload(); -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java index 66038e4d45..c9ddbed1c4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java @@ -8,9 +8,6 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.mapbox.geojson.Feature; import com.mapbox.geojson.Geometry; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.Polyline; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; @@ -218,47 +215,6 @@ interface NativeMap { float getPixelRatio(); - // - // Deprecated Annotations API - // - - long addMarker(Marker marker); - - @NonNull - long[] addMarkers(@NonNull List markers); - - long addPolyline(Polyline polyline); - - @NonNull - long[] addPolylines(@NonNull List polylines); - - long addPolygon(Polygon polygon); - - @NonNull - long[] addPolygons(@NonNull List polygons); - - void updateMarker(@NonNull Marker marker); - - void updatePolygon(@NonNull Polygon polygon); - - void updatePolyline(@NonNull Polyline polyline); - - void removeAnnotation(long id); - - void removeAnnotations(long[] ids); - - double getTopOffsetPixelsForAnnotationSymbol(String symbolName); - - void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels); - - void removeAnnotationIcon(String symbol); - - @NonNull - long[] queryPointAnnotations(RectF rectF); - - @NonNull - long[] queryShapeAnnotations(RectF rectF); - @NonNull RectF getDensityDependantRectangle(RectF rectangle); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 328b5f6bcb..12321abe64 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -14,10 +14,6 @@ import com.mapbox.geojson.Feature; import com.mapbox.geojson.Geometry; import com.mapbox.mapboxsdk.LibraryLoader; import com.mapbox.mapboxsdk.MapStrictMode; -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.Polyline; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.exceptions.CalledFromWorkerThreadException; import com.mapbox.mapboxsdk.geometry.LatLng; @@ -432,137 +428,6 @@ final class NativeMapView implements NativeMap { nativeResetNorth(); } - @Override - public long addMarker(Marker marker) { - if (checkState("addMarker")) { - return 0; - } - Marker[] markers = {marker}; - return nativeAddMarkers(markers)[0]; - } - - @Override - @NonNull - public long[] addMarkers(@NonNull List markers) { - if (checkState("addMarkers")) { - return new long[] {}; - } - return nativeAddMarkers(markers.toArray(new Marker[markers.size()])); - } - - @Override - public long addPolyline(Polyline polyline) { - if (checkState("addPolyline")) { - return 0; - } - Polyline[] polylines = {polyline}; - return nativeAddPolylines(polylines)[0]; - } - - @Override - @NonNull - public long[] addPolylines(@NonNull List polylines) { - if (checkState("addPolylines")) { - return new long[] {}; - } - return nativeAddPolylines(polylines.toArray(new Polyline[polylines.size()])); - } - - @Override - public long addPolygon(Polygon polygon) { - if (checkState("addPolygon")) { - return 0; - } - Polygon[] polygons = {polygon}; - return nativeAddPolygons(polygons)[0]; - } - - @Override - @NonNull - public long[] addPolygons(@NonNull List polygons) { - if (checkState("addPolygons")) { - return new long[] {}; - } - return nativeAddPolygons(polygons.toArray(new Polygon[polygons.size()])); - } - - @Override - public void updateMarker(@NonNull Marker marker) { - if (checkState("updateMarker")) { - return; - } - LatLng position = marker.getPosition(); - Icon icon = marker.getIcon(); - nativeUpdateMarker(marker.getId(), position.getLatitude(), position.getLongitude(), icon.getId()); - } - - @Override - public void updatePolygon(@NonNull Polygon polygon) { - if (checkState("updatePolygon")) { - return; - } - nativeUpdatePolygon(polygon.getId(), polygon); - } - - @Override - public void updatePolyline(@NonNull Polyline polyline) { - if (checkState("updatePolyline")) { - return; - } - nativeUpdatePolyline(polyline.getId(), polyline); - } - - @Override - public void removeAnnotation(long id) { - if (checkState("removeAnnotation")) { - return; - } - long[] ids = {id}; - removeAnnotations(ids); - } - - @Override - public void removeAnnotations(long[] ids) { - if (checkState("removeAnnotations")) { - return; - } - nativeRemoveAnnotations(ids); - } - - @Override - @NonNull - public long[] queryPointAnnotations(RectF rect) { - if (checkState("queryPointAnnotations") || !mapRenderer.hasSurface()) { - return new long[] {}; - } - return nativeQueryPointAnnotations(rect); - } - - @Override - @NonNull - public long[] queryShapeAnnotations(RectF rectF) { - if (checkState("queryShapeAnnotations") || !mapRenderer.hasSurface()) { - return new long[] {}; - } - return nativeQueryShapeAnnotations(rectF); - } - - @Override - public void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels) { - if (checkState("addAnnotationIcon")) { - return; - } - nativeAddAnnotationIcon(symbol, width, height, scale, pixels); - } - - @Override - public void removeAnnotationIcon(String symbol) { - if (checkState("removeAnnotationIcon")) { - return; - } - nativeRemoveAnnotationIcon(symbol); - } - @Override public void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) { if (checkState("setVisibleCoordinateBounds")) { @@ -663,14 +528,6 @@ final class NativeMapView implements NativeMap { return nativeLatLngForPixel(pixel.x / pixelRatio, pixel.y / pixelRatio); } - @Override - public double getTopOffsetPixelsForAnnotationSymbol(String symbolName) { - if (checkState("getTopOffsetPixelsForAnnotationSymbol")) { - return 0; - } - return nativeGetTopOffsetPixelsForAnnotationSymbol(symbolName); - } - @Override public void jumpTo(@NonNull LatLng center, double zoom, double pitch, double angle) { if (checkState("jumpTo")) { @@ -1178,38 +1035,6 @@ final class NativeMapView implements NativeMap { @Keep private native void nativeResetNorth(); - @Keep - private native void nativeUpdateMarker(long markerId, double lat, double lon, String iconId); - - @NonNull - @Keep - private native long[] nativeAddMarkers(Marker[] markers); - - @NonNull - @Keep - private native long[] nativeAddPolylines(Polyline[] polylines); - - @NonNull - @Keep - private native long[] nativeAddPolygons(Polygon[] polygons); - - @Keep - private native void nativeRemoveAnnotations(long[] id); - - @NonNull - @Keep - private native long[] nativeQueryPointAnnotations(RectF rect); - - @NonNull - @Keep - private native long[] nativeQueryShapeAnnotations(RectF rect); - - @Keep - private native void nativeAddAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels); - - @Keep - private native void nativeRemoveAnnotationIcon(String symbol); - @Keep private native void nativeSetVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration); @@ -1339,12 +1164,6 @@ final class NativeMapView implements NativeMap { @Keep private native Bitmap nativeGetImage(String name); - @Keep - private native void nativeUpdatePolygon(long polygonId, Polygon polygon); - - @Keep - private native void nativeUpdatePolyline(long polylineId, Polyline polyline); - @Keep private native void nativeTakeSnapshot(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java deleted file mode 100644 index a7e2ace061..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - - -import android.support.annotation.NonNull; -import android.support.v4.util.LongSparseArray; - -import com.mapbox.mapboxsdk.annotations.Annotation; -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; - -import java.util.ArrayList; -import java.util.List; - -/** - * Encapsulates {@link Polygon}'s functionality. - */ -class PolygonContainer implements Polygons { - - private final NativeMap nativeMap; - private final LongSparseArray annotations; - - PolygonContainer(NativeMap nativeMap, LongSparseArray annotations) { - this.nativeMap = nativeMap; - this.annotations = annotations; - } - - @Override - public Polygon addBy(@NonNull PolygonOptions polygonOptions, @NonNull MapboxMap mapboxMap) { - Polygon polygon = polygonOptions.getPolygon(); - if (!polygon.getPoints().isEmpty()) { - long id = nativeMap != null ? nativeMap.addPolygon(polygon) : 0; - polygon.setId(id); - polygon.setMapboxMap(mapboxMap); - annotations.put(id, polygon); - } - return polygon; - } - - @NonNull - @Override - public List addBy(@NonNull List polygonOptionsList, @NonNull MapboxMap mapboxMap) { - int count = polygonOptionsList.size(); - - Polygon polygon; - List polygons = new ArrayList<>(count); - if (nativeMap != null && count > 0) { - for (PolygonOptions polygonOptions : polygonOptionsList) { - polygon = polygonOptions.getPolygon(); - if (!polygon.getPoints().isEmpty()) { - polygons.add(polygon); - } - } - - long[] ids = nativeMap.addPolygons(polygons); - for (int i = 0; i < ids.length; i++) { - polygon = polygons.get(i); - polygon.setMapboxMap(mapboxMap); - polygon.setId(ids[i]); - annotations.put(ids[i], polygon); - } - } - return polygons; - } - - @Override - public void update(@NonNull Polygon polygon) { - nativeMap.updatePolygon(polygon); - annotations.setValueAt(annotations.indexOfKey(polygon.getId()), polygon); - } - - @NonNull - @Override - public List obtainAll() { - List polygons = new ArrayList<>(); - Annotation annotation; - for (int i = 0; i < annotations.size(); i++) { - annotation = annotations.get(annotations.keyAt(i)); - if (annotation instanceof Polygon) { - polygons.add((Polygon) annotation); - } - } - return polygons; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Polygons.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Polygons.java deleted file mode 100644 index 2a0190b5ba..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Polygons.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - - -import android.support.annotation.NonNull; - -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; - -import java.util.List; - -/** - * Interface that defines convenient methods for working with a {@link Polygon}'s collection. - */ -interface Polygons { - Polygon addBy(@NonNull PolygonOptions polygonOptions, @NonNull MapboxMap mapboxMap); - - List addBy(@NonNull List polygonOptionsList, @NonNull MapboxMap mapboxMap); - - void update(Polygon polygon); - - List obtainAll(); -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java deleted file mode 100644 index e11da26e08..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - - -import android.support.annotation.NonNull; -import android.support.v4.util.LongSparseArray; - -import com.mapbox.mapboxsdk.annotations.Annotation; -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; - -import java.util.ArrayList; -import java.util.List; - -/** - * Encapsulates {@link Polyline}'s functionality. - */ -class PolylineContainer implements Polylines { - - private final NativeMap nativeMap; - private final LongSparseArray annotations; - - PolylineContainer(NativeMap nativeMap, LongSparseArray annotations) { - this.nativeMap = nativeMap; - this.annotations = annotations; - } - - @Override - public Polyline addBy(@NonNull PolylineOptions polylineOptions, @NonNull MapboxMap mapboxMap) { - Polyline polyline = polylineOptions.getPolyline(); - if (!polyline.getPoints().isEmpty()) { - long id = nativeMap != null ? nativeMap.addPolyline(polyline) : 0; - polyline.setMapboxMap(mapboxMap); - polyline.setId(id); - annotations.put(id, polyline); - } - return polyline; - } - - @NonNull - @Override - public List addBy(@NonNull List polylineOptionsList, @NonNull MapboxMap mapboxMap) { - int count = polylineOptionsList.size(); - Polyline polyline; - List polylines = new ArrayList<>(count); - if (nativeMap != null && count > 0) { - for (PolylineOptions options : polylineOptionsList) { - polyline = options.getPolyline(); - if (!polyline.getPoints().isEmpty()) { - polylines.add(polyline); - } - } - - long[] ids = nativeMap.addPolylines(polylines); - for (int i = 0; i < ids.length; i++) { - Polyline polylineCreated = polylines.get(i); - polylineCreated.setMapboxMap(mapboxMap); - polylineCreated.setId(ids[i]); - annotations.put(ids[i], polylineCreated); - } - } - return polylines; - } - - @Override - public void update(@NonNull Polyline polyline) { - nativeMap.updatePolyline(polyline); - annotations.setValueAt(annotations.indexOfKey(polyline.getId()), polyline); - } - - @NonNull - @Override - public List obtainAll() { - List polylines = new ArrayList<>(); - Annotation annotation; - for (int i = 0; i < annotations.size(); i++) { - annotation = annotations.get(annotations.keyAt(i)); - if (annotation instanceof Polyline) { - polylines.add((Polyline) annotation); - } - } - return polylines; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Polylines.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Polylines.java deleted file mode 100644 index c9a865cdd0..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Polylines.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - - -import android.support.annotation.NonNull; - -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; - -import java.util.List; - -/** - * Interface that defines convenient methods for working with a {@link Polyline}'s collection. - */ -interface Polylines { - Polyline addBy(@NonNull PolylineOptions polylineOptions, @NonNull MapboxMap mapboxMap); - - List addBy(@NonNull List polylineOptionsList, @NonNull MapboxMap mapboxMap); - - void update(Polyline polyline); - - List obtainAll(); -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotationContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotationContainer.java deleted file mode 100644 index 9c2b97b6a5..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotationContainer.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.RectF; -import android.support.annotation.NonNull; -import android.support.v4.util.LongSparseArray; - -import com.mapbox.mapboxsdk.annotations.Annotation; - -import java.util.ArrayList; -import java.util.List; - -class ShapeAnnotationContainer implements ShapeAnnotations { - - private final NativeMap nativeMapView; - private final LongSparseArray annotations; - - ShapeAnnotationContainer(NativeMap nativeMapView, LongSparseArray annotations) { - this.nativeMapView = nativeMapView; - this.annotations = annotations; - } - - @NonNull - @Override - public List obtainAllIn(@NonNull RectF rectangle) { - RectF rect = nativeMapView.getDensityDependantRectangle(rectangle); - long[] annotationIds = nativeMapView.queryShapeAnnotations(rect); - return getAnnotationsFromIds(annotationIds); - } - - @NonNull - private List getAnnotationsFromIds(long[] annotationIds) { - List shapeAnnotations = new ArrayList<>(); - for (long annotationId : annotationIds) { - Annotation annotation = annotations.get(annotationId); - if (annotation != null) { - shapeAnnotations.add(annotation); - } - } - return shapeAnnotations; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotations.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotations.java deleted file mode 100644 index f9b2ca10db..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotations.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.RectF; - -import com.mapbox.mapboxsdk.annotations.Annotation; - -import java.util.List; - -interface ShapeAnnotations { - - List obtainAllIn(RectF rectF); - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_marker_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_marker_icon_default.png deleted file mode 100644 index 8b0af4c6ab..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_marker_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_markerview_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_markerview_icon_default.png deleted file mode 100644 index 651482f3ee..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_markerview_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_marker_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_marker_icon_default.png deleted file mode 100644 index b112096c18..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_marker_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_markerview_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_markerview_icon_default.png deleted file mode 100644 index 63cb7b5f4b..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_markerview_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_marker_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_marker_icon_default.png deleted file mode 100644 index d05c82bfe2..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_marker_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_markerview_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_markerview_icon_default.png deleted file mode 100644 index 175f88ff88..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_markerview_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_marker_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_marker_icon_default.png deleted file mode 100644 index 703b172c15..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_marker_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_markerview_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_markerview_icon_default.png deleted file mode 100644 index be782e1d4b..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_markerview_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_marker_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_marker_icon_default.png deleted file mode 100644 index 8331ffef71..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_marker_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_markerview_icon_default.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_markerview_icon_default.png deleted file mode 100644 index fe1c486518..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_markerview_icon_default.png and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml deleted file mode 100644 index 3a35396257..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_view_image_marker.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_view_image_marker.xml deleted file mode 100644 index 51eb46e1d5..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_view_image_marker.xml +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/AnnotationTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/AnnotationTest.java deleted file mode 100644 index 0c61b01be6..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/AnnotationTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.support.annotation.NonNull; -import com.mapbox.mapboxsdk.maps.MapboxMap; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -public class AnnotationTest { - - @InjectMocks - private MapboxMap mapboxMap = mock(MapboxMap.class); - private Annotation annotation; - @NonNull - private Annotation compare = new Annotation() { - @Override - public long getId() { - return 1; - } - }; - - @Before - public void beforeTest() { - annotation = new Annotation() { - // empty child - }; - } - - @Test - public void testSanity() { - assertNotNull("markerOptions should not be null", annotation); - } - - @Test - public void testRemove() { - annotation.setId(1); - annotation.setMapboxMap(mapboxMap); - annotation.remove(); - verify(mapboxMap, times(1)).removeAnnotation(annotation); - } - - @Test - public void testRemoveUnboundMapboxMap() { - annotation.setId(1); - annotation.remove(); - verify(mapboxMap, times(0)).removeAnnotation(annotation); - } - - @Test - public void testCompareToEqual() { - annotation.setId(1); - assertEquals("conparable equal", 0, annotation.compareTo(compare)); - } - - @Test - public void testCompareToHigher() { - annotation.setId(3); - assertEquals("conparable higher", -1, annotation.compareTo(compare)); - } - - @Test - public void testCompareTolower() { - annotation.setId(0); - assertEquals("conparable lower", 1, annotation.compareTo(compare)); - } - - @Test - public void testEquals() { - Annotation holder = null; - assertFalse(annotation.equals(holder)); - holder = annotation; - assertTrue(annotation.equals(holder)); - assertFalse(annotation.equals(new Object())); - } - - @Test - public void testHashcode() { - int id = 1; - annotation.setId(id); - assertSame("hashcode should match", annotation.hashCode(), id); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java deleted file mode 100644 index e56ca559d4..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.Bitmap; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotSame; -import static org.mockito.Mockito.when; - -public class IconTest { - - @Mock - Bitmap bitmap; - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - when(bitmap.getConfig()).thenReturn(Bitmap.Config.ARGB_8888); - } - - @Test - public void testId() { - String id = "test"; - Icon icon = IconFactory.recreate(id, Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8)); - assertEquals("id should match", id, icon.getId()); - } - - @Test - public void testBitmap() { - Icon icon = IconFactory.recreate("test", bitmap); - assertEquals("bitmap should match", bitmap, icon.getBitmap()); - } - - @Test - public void testEquals() { - Icon icon1 = IconFactory.recreate("test", bitmap); - Icon icon2 = IconFactory.recreate("test", bitmap); - assertEquals("icons should not match", icon1, icon2); - } - - @Test - public void testEqualsObject() { - Icon icon = IconFactory.recreate("test", Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8)); - assertNotSame("icon should not match", new Object(), icon); - } - - @Test - public void testHashcode() { - Icon icon = IconFactory.recreate("test", bitmap); - long expectedHashcode = 31 * bitmap.hashCode() + "test".hashCode(); - assertEquals("hashcode should match", expectedHashcode, icon.hashCode()); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java deleted file mode 100644 index 94b629860e..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.PointF; - -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Projection; - -import org.junit.Test; -import org.mockito.InjectMocks; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class InfoWindowTest { - - @InjectMocks - MapView mMapView = mock(MapView.class); - - @InjectMocks - MapboxMap mMapboxMap = mock(MapboxMap.class); - - @Test - public void testSanity() { - InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap); - assertNotNull("infoWindow should exist", infoWindow); - } - - @Test - public void testBoundMarker() { - MarkerOptions markerOptions = new MarkerOptions(); - Marker marker = markerOptions.position(new LatLng()).getMarker(); - InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap).setBoundMarker(marker); - assertEquals("marker should match", marker, infoWindow.getBoundMarker()); - } - - @Test - public void testClose() { - InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap); - infoWindow.close(); - assertEquals("infowindow should not be visible", false, infoWindow.isVisible()); - } - - - @Test - public void testOpen() { - LatLng latLng = new LatLng(0, 0); - Projection projection = mock(Projection.class); - when(mMapboxMap.getProjection()).thenReturn(projection); - when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0)); - - InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap); - infoWindow.open(mMapView, new MarkerOptions().position(new LatLng()).getMarker(), latLng, 0, 0); - assertEquals("infowindow should not be visible", true, infoWindow.isVisible()); - } - - @Test - public void testOpenClose() { - LatLng latLng = new LatLng(0, 0); - Projection projection = mock(Projection.class); - when(mMapboxMap.getProjection()).thenReturn(projection); - when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0)); - - InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap); - infoWindow.open(mMapView, new MarkerOptions().position(new LatLng()).getMarker(), latLng, 0, 0); - infoWindow.close(); - assertEquals("infowindow should not be visible", false, infoWindow.isVisible()); - } - - - @Test - public void testUpdate() { - LatLng latLng = new LatLng(0, 0); - Projection projection = mock(Projection.class); - when(mMapboxMap.getProjection()).thenReturn(projection); - when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0)); - - InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap); - infoWindow.open(mMapView, new MarkerOptions().position(latLng).getMarker(), latLng, 0, 0); - infoWindow.update(); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java deleted file mode 100644 index fa571e06b1..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.Bitmap; -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.utils.MockParcel; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; - -public class MarkerTest { - - @Test - public void testSanity() { - MarkerOptions markerOptions = new MarkerOptions(); - assertNotNull("markerOptions should not be null", markerOptions); - } - - @Test - public void testMarker() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - assertNotNull("marker should not be null", markerOptions.getMarker()); - } - - @Test(expected = InvalidMarkerPositionException.class) - public void testInvalidMarker() { - new MarkerOptions().getMarker(); - } - - @Test - public void testPosition() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12)); - Marker marker = markerOptions.getMarker(); - assertEquals(marker.getPosition(), new LatLng(10, 12)); - assertEquals(markerOptions.getPosition(), new LatLng(10, 12)); - } - - @Test - public void testTitle() { - MarkerOptions markerOptions = new MarkerOptions().title("Mapbox").position(new LatLng()); - Marker marker = markerOptions.getMarker(); - assertEquals(marker.getTitle(), "Mapbox"); - assertEquals(markerOptions.getTitle(), "Mapbox"); - } - - @Test - public void testSnippet() { - MarkerOptions markerOptions = new MarkerOptions().snippet("Mapbox").position(new LatLng()); - Marker marker = markerOptions.getMarker(); - assertEquals(marker.getSnippet(), "Mapbox"); - } - - @Test - public void testBuilder() { - Marker marker = new MarkerOptions().title("title").snippet("snippet").position(new LatLng(10, 12)).getMarker(); - assertEquals(marker.getSnippet(), "snippet"); - - assertEquals(marker.getPosition(), new LatLng(10, 12)); - } - - @Test - public void testIcon() { - Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444); - Icon icon = IconFactory.recreate("test", bitmap); - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).icon(icon); - Marker marker = markerOptions.getMarker(); - assertEquals("Icon should match", icon, marker.getIcon()); - assertEquals("Icon should match", icon, markerOptions.getIcon()); - } - - @Test - public void testHashCode() { - Marker marker = new MarkerOptions().position(new LatLng()).getMarker(); - assertEquals("hash code should match", marker.hashCode(), 0); - } - - @Test - public void testHashCodeBuilder() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12)); - assertEquals("hash code should match", markerOptions.hashCode(), 579999617); - } - - @Test - public void testEquals() { - Marker markerOne = new MarkerOptions().position(new LatLng(0, 0)).getMarker(); - Marker markerTwo = new MarkerOptions().position(new LatLng(0, 0)).getMarker(); - assertEquals(markerOne, markerTwo); - } - - @Test - public void testEqualityDifferentLocation() { - MarkerOptions marker = new MarkerOptions().position(new LatLng(0, 0)); - MarkerOptions other = new MarkerOptions().position(new LatLng(1, 0)); - assertNotEquals("Should not match", other, marker); - } - - - @Test - public void testEqualityDifferentSnippet() { - MarkerOptions marker = new MarkerOptions().snippet("s"); - MarkerOptions other = new MarkerOptions(); - assertNotEquals("Should not match", other, marker); - } - - @Test - public void testEqualityDifferentIcon() { - MarkerOptions marker = new MarkerOptions().icon(mock(Icon.class)); - MarkerOptions other = new MarkerOptions(); - assertNotEquals("Should not match", other, marker); - } - - @Test - public void testEqualityDifferentTitle() { - MarkerOptions marker = new MarkerOptions().title("t"); - MarkerOptions other = new MarkerOptions(); - assertNotEquals("Should not match", other, marker); - } - - @Test - public void testEqualsItself() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(0, 0)); - Marker marker = markerOptions.getMarker(); - assertEquals("Marker should match", marker, marker); - assertEquals("MarkerOptions should match", markerOptions, markerOptions); - } - - @Test - public void testNotEquals() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(0, 0)); - Marker marker = markerOptions.getMarker(); - assertNotEquals("MarkerOptions should match", markerOptions, new Object()); - assertNotEquals("Marker should match", marker, new Object()); - } - - @Test - public void testEqualityBuilder() { - MarkerOptions markerOne = new MarkerOptions().position(new LatLng(0, 0)); - MarkerOptions markerTwo = new MarkerOptions().position(new LatLng(0, 0)); - assertEquals(markerOne, markerTwo); - } - - @Test - public void testToString() { - Marker marker = new MarkerOptions().position(new LatLng(0, 0)).getMarker(); - assertEquals(marker.toString(), "Marker [position[" + "LatLng [latitude=0.0, longitude=0.0, altitude=0.0]" + "]]"); - } - - @Test - public void testParcelable() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).title("t").snippet("s"); - Parcelable parcelable = MockParcel.obtain(markerOptions); - assertEquals("Parcel should match original object", parcelable, markerOptions); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/PolygonTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/PolygonTest.java deleted file mode 100644 index 3933c68887..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/PolygonTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import com.mapbox.mapboxsdk.geometry.LatLng; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class PolygonTest { - - @Test - public void testSanity() { - PolygonOptions polygonOptions = new PolygonOptions(); - assertNotNull("polygonOptions should not be null", polygonOptions); - } - - @Test - public void testPolygon() { - Polygon polygon = new PolygonOptions().getPolygon(); - assertNotNull("polyline should not be null", polygon); - } - - @Test - public void testAlpha() { - Polygon polygon = new PolygonOptions().alpha(0.5f).getPolygon(); - assertEquals(0.5f, polygon.getAlpha(), 0.0f); - } - - @Test - public void testStrokeColor() { - Polygon polygon = new PolygonOptions().strokeColor(1).getPolygon(); - assertEquals(1, polygon.getStrokeColor()); - } - - @Test - public void testFillColor() { - Polygon polygon = new PolygonOptions().fillColor(1).getPolygon(); - assertEquals(1, polygon.getFillColor()); - } - - @Test - public void testLatLng() { - Polygon polygon = new PolygonOptions().add(new LatLng(0, 0)).getPolygon(); - assertNotNull("points should not be null", polygon.getPoints()); - assertEquals(new LatLng(0, 0), polygon.getPoints().get(0)); - } - - @Test - public void testAddAllLatLng() { - List coordinates = new ArrayList<>(); - coordinates.add(new LatLng(0, 0)); - Polygon polygon = new PolygonOptions().addAll(coordinates).getPolygon(); - assertNotNull(polygon.getPoints()); - assertEquals(new LatLng(0, 0), polygon.getPoints().get(0)); - } - - @Test - public void testBuilder() { - PolylineOptions polylineOptions = new PolylineOptions(); - polylineOptions.width(1.0f); - polylineOptions.color(2); - polylineOptions.add(new LatLng(0, 0)); - - Polyline polyline = polylineOptions.getPolyline(); - assertEquals(1.0f, polyline.getWidth(), 0); - assertEquals(2, polyline.getColor()); - assertNotNull("Points should not be null", polyline.getPoints()); - assertEquals(new LatLng(0, 0), polyline.getPoints().get(0)); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/PolylineTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/PolylineTest.java deleted file mode 100644 index 54bb0e8cf4..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/PolylineTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import com.mapbox.mapboxsdk.geometry.LatLng; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class PolylineTest { - - @Test - public void testSanity() { - PolylineOptions polylineOptions = new PolylineOptions(); - assertNotNull("polylineOptions should not be null", polylineOptions); - } - - @Test - public void testPolyline() { - Polyline polyline = new PolylineOptions().getPolyline(); - assertNotNull("polyline should not be null", polyline); - } - - @Test - public void testAlpha() { - Polyline polyline = new PolylineOptions().alpha(0.2f).getPolyline(); - assertEquals(0.2f, polyline.getAlpha(), 0.0f); - } - - @Test - public void testWidth() { - Polyline polyline = new PolylineOptions().width(1).getPolyline(); - assertEquals(1.0f, polyline.getWidth(), 0); - } - - @Test - public void testColor() { - Polyline polyline = new PolylineOptions().color(1).getPolyline(); - assertEquals(1, polyline.getColor()); - } - - @Test - public void testAddLatLng() { - Polyline polyline = new PolylineOptions().add(new LatLng(0, 0)).getPolyline(); - assertNotNull("Points should not be null", polyline.getPoints()); - assertEquals(new LatLng(0, 0), polyline.getPoints().get(0)); - } - - @Test - public void testAddAllLatLng() { - List coordinates = new ArrayList<>(); - coordinates.add(new LatLng(0, 0)); - Polyline polyline = new PolylineOptions().addAll(coordinates).getPolyline(); - assertNotNull(polyline.getPoints()); - assertEquals(new LatLng(0, 0), polyline.getPoints().get(0)); - } - - @Test - public void testBuilder() { - PolylineOptions polylineOptions = new PolylineOptions(); - polylineOptions.width(1.0f); - polylineOptions.color(2); - polylineOptions.add(new LatLng(0, 0)); - - Polyline polyline = polylineOptions.getPolyline(); - assertEquals(1.0f, polyline.getWidth(), 0); - assertEquals(2, polyline.getColor()); - assertNotNull("Points should not be null", polyline.getPoints()); - assertEquals(new LatLng(0, 0), polyline.getPoints().get(0)); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java deleted file mode 100644 index fd59f52a55..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.support.v4.util.LongSparseArray; - -import com.mapbox.mapboxsdk.annotations.Annotation; -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import org.junit.Test; -import org.mockito.ArgumentMatchers; - -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class AnnotationManagerTest { - - @Test - public void checksAddAMarker() throws Exception { - NativeMap aNativeMapView = mock(NativeMapView.class); - MapView aMapView = mock(MapView.class); - LongSparseArray annotationsArray = new LongSparseArray<>(); - IconManager aIconManager = mock(IconManager.class); - Annotations annotations = new AnnotationContainer(aNativeMapView, annotationsArray); - Markers markers = new MarkerContainer(aNativeMapView, annotationsArray, aIconManager); - Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray); - Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray); - ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray); - AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray, - aIconManager, annotations, markers, polygons, polylines, shapeAnnotations); - Marker aMarker = mock(Marker.class); - long aId = 5L; - when(aNativeMapView.addMarker(aMarker)).thenReturn(aId); - BaseMarkerOptions aMarkerOptions = mock(BaseMarkerOptions.class); - MapboxMap aMapboxMap = mock(MapboxMap.class); - when(aMarkerOptions.getMarker()).thenReturn(aMarker); - - annotationManager.addMarker(aMarkerOptions, aMapboxMap); - - assertEquals(aMarker, annotationManager.getAnnotations().get(0)); - assertEquals(aMarker, annotationManager.getAnnotation(aId)); - } - - @Test - public void checksAddMarkers() throws Exception { - NativeMapView aNativeMapView = mock(NativeMapView.class); - MapView aMapView = mock(MapView.class); - LongSparseArray annotationsArray = new LongSparseArray<>(); - IconManager aIconManager = mock(IconManager.class); - Annotations annotations = new AnnotationContainer(aNativeMapView, annotationsArray); - Markers markers = new MarkerContainer(aNativeMapView, annotationsArray, aIconManager); - Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray); - Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray); - ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray); - AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray, - aIconManager, annotations, markers, polygons, polylines, shapeAnnotations); - - long firstId = 1L; - long secondId = 2L; - List markerList = new ArrayList<>(); - MarkerOptions firstMarkerOption = new MarkerOptions().position(new LatLng()).title("first"); - MarkerOptions secondMarkerOption = new MarkerOptions().position(new LatLng()).title("second"); - - markerList.add(firstMarkerOption); - markerList.add(secondMarkerOption); - MapboxMap aMapboxMap = mock(MapboxMap.class); - when(aNativeMapView.addMarker(any(Marker.class))).thenReturn(firstId, secondId); - - when(aNativeMapView.addMarkers(ArgumentMatchers.anyList())) - .thenReturn(new long[] {firstId, secondId}); - - annotationManager.addMarkers(markerList, aMapboxMap); - - assertEquals(2, annotationManager.getAnnotations().size()); - assertEquals("first", ((Marker) annotationManager.getAnnotations().get(0)).getTitle()); - assertEquals("second", ((Marker) annotationManager.getAnnotations().get(1)).getTitle()); - assertEquals("first", ((Marker) annotationManager.getAnnotation(firstId)).getTitle()); - assertEquals("second", ((Marker) annotationManager.getAnnotation(secondId)).getTitle()); - } -} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java index cb097c283d..6224e67ed4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java @@ -1,14 +1,12 @@ package com.mapbox.mapboxsdk.maps; import android.graphics.PointF; - import android.support.annotation.Nullable; import com.mapbox.android.gestures.MoveGestureDetector; import com.mapbox.android.gestures.RotateGestureDetector; import com.mapbox.android.gestures.ShoveGestureDetector; import com.mapbox.android.gestures.StandardScaleGestureDetector; import com.mapbox.mapboxsdk.geometry.LatLng; - import org.junit.Before; import org.junit.Test; @@ -32,7 +30,7 @@ public class MapTouchListenersTest { Projection projection = mock(Projection.class); when(projection.fromScreenLocation(pointF)).thenReturn(latLng); mapGestureDetector = new MapGestureDetector(null, - null, projection, null, null, null); + null, projection, null, null); } @Test diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/IconManagerResolver.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/IconManagerResolver.java deleted file mode 100644 index 3e226a7ec5..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/IconManagerResolver.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import com.mapbox.mapboxsdk.annotations.Icon; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -import timber.log.Timber; - -public class IconManagerResolver { - - private IconManager iconManager; - - public IconManagerResolver(MapboxMap mapboxMap) { - try { - Field annotationManagerField = MapboxMap.class.getDeclaredField("annotationManager"); - annotationManagerField.setAccessible(true); - AnnotationManager annotationManager = (AnnotationManager) annotationManagerField.get(mapboxMap); - - Field iconManagerField = AnnotationManager.class.getDeclaredField("iconManager"); - iconManagerField.setAccessible(true); - iconManager = (IconManager) iconManagerField.get(annotationManager); - } catch (Exception exception) { - Timber.e(exception, "Could not create IconManagerResolver, unable to reflect."); - } - } - - @SuppressWarnings("unchecked") - public Map getIconMap() { - try { - Field field = IconManager.class.getDeclaredField("iconMap"); - field.setAccessible(true); - return (Map) field.get(iconManager); - } catch (NoSuchFieldException exception) { - Timber.e(exception, "Could not getIconMap, unable to reflect."); - } catch (IllegalAccessException exception) { - Timber.e(exception, "Could not getIconMap, unable to reflect."); - } - return new HashMap<>(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java deleted file mode 100644 index 00ec1fe601..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java +++ /dev/null @@ -1,477 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.Color; -import android.support.test.espresso.UiController; -import android.support.test.espresso.ViewAction; -import android.view.View; -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.EspressoTest; -import org.hamcrest.Matcher; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; -import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertNotNull; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * This test is responsible for testing the public API. - *

- * Methods executed on MapboxMap are called from a ViewAction to ensure correct synchronisation - * with the application UI-thread. - *

- * @deprecated remove this file when removing deprecated annotations - */ -@Deprecated -public class MapboxMapTest extends EspressoTest { - - // - // InfoWindow - // - - @Test - public void testConcurrentInfoWindowEnabled() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true); - assertTrue("ConcurrentWindows should be true", mapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); - })); - } - - @Test - public void testConcurrentInfoWindowDisabled() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false); - assertFalse("ConcurrentWindows should be false", mapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); - })); - } - - @Test - public void testInfoWindowAdapter() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MapboxMap.InfoWindowAdapter infoWindowAdapter = marker -> null; - mapboxMap.setInfoWindowAdapter(infoWindowAdapter); - assertEquals("InfoWindowAdpter should be the same", infoWindowAdapter, mapboxMap.getInfoWindowAdapter()); - })); - } - - // - // Annotations - // - - @Test - public void testAddMarker() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mapboxMap.addMarker(markerOptions); - assertTrue("Marker should be contained", mapboxMap.getMarkers().contains(marker)); - })); - } - - @Test(expected = InvalidMarkerPositionException.class) - public void testAddMarkerInvalidPosition() { - new MarkerOptions().getMarker(); - } - - @Test - public void testAddMarkers() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng()).title("a"); - MarkerOptions markerOptions2 = new MarkerOptions().position(new LatLng()).title("b"); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - List markers = mapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 2", 2, mapboxMap.getMarkers().size()); - assertTrue(mapboxMap.getMarkers().contains(markers.get(0))); - assertTrue(mapboxMap.getMarkers().contains(markers.get(1))); - })); - } - - @Test - public void testAddMarkersEmpty() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List markerList = new ArrayList<>(); - mapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 0", 0, mapboxMap.getMarkers().size()); - })); - } - - @Test - public void testAddMarkersSingleMarker() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List markerList = new ArrayList<>(); - MarkerOptions markerOptions = new MarkerOptions().title("a").position(new LatLng()); - markerList.add(markerOptions); - List markers = mapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 1", 1, mapboxMap.getMarkers().size()); - assertTrue(mapboxMap.getMarkers().contains(markers.get(0))); - })); - } - - @Test - public void testAddPolygon() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - PolygonOptions polygonOptions = new PolygonOptions().add(new LatLng()); - Polygon polygon = mapboxMap.addPolygon(polygonOptions); - assertTrue("Polygon should be contained", mapboxMap.getPolygons().contains(polygon)); - })); - } - - @Test - public void testAddEmptyPolygon() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - PolygonOptions polygonOptions = new PolygonOptions(); - Polygon polygon = mapboxMap.addPolygon(polygonOptions); - assertTrue("Polygon should be ignored", !mapboxMap.getPolygons().contains(polygon)); - })); - } - - @Test - public void testAddPolygons() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List polygonList = new ArrayList<>(); - PolygonOptions polygonOptions1 = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng()); - PolygonOptions polygonOptions2 = new PolygonOptions().fillColor(Color.WHITE).add(new LatLng()); - PolygonOptions polygonOptions3 = new PolygonOptions(); - polygonList.add(polygonOptions1); - polygonList.add(polygonOptions2); - polygonList.add(polygonOptions3); - mapboxMap.addPolygons(polygonList); - assertEquals("Polygons size should be 2", 2, mapboxMap.getPolygons().size()); - assertTrue(mapboxMap.getPolygons().contains(polygonOptions1.getPolygon())); - assertTrue(mapboxMap.getPolygons().contains(polygonOptions2.getPolygon())); - assertTrue("Polygon should be ignored", !mapboxMap.getPolygons().contains(polygonOptions3.getPolygon())); - })); - } - - @Test - public void addPolygonsEmpty() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - mapboxMap.addPolygons(new ArrayList()); - assertEquals("Polygons size should be 0", 0, mapboxMap.getPolygons().size()); - })); - } - - @Test - public void addPolygonsSingle() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List polygonList = new ArrayList<>(); - PolygonOptions polygonOptions = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng()); - polygonList.add(polygonOptions); - mapboxMap.addPolygons(polygonList); - assertEquals("Polygons size should be 1", 1, mapboxMap.getPolygons().size()); - assertTrue(mapboxMap.getPolygons().contains(polygonOptions.getPolygon())); - })); - } - - @Test - public void testAddPolyline() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - PolylineOptions polylineOptions = new PolylineOptions().add(new LatLng()); - Polyline polyline = mapboxMap.addPolyline(polylineOptions); - assertTrue("Polyline should be contained", mapboxMap.getPolylines().contains(polyline)); - })); - } - - @Test - public void testAddEmptyPolyline() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - PolylineOptions polylineOptions = new PolylineOptions(); - Polyline polyline = mapboxMap.addPolyline(polylineOptions); - assertTrue("Polyline should be ignored", !mapboxMap.getPolylines().contains(polyline)); - })); - } - - @Test - public void testAddPolylines() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List polylineList = new ArrayList<>(); - PolylineOptions polygonOptions1 = new PolylineOptions().color(Color.BLACK).add(new LatLng()); - PolylineOptions polygonOptions2 = new PolylineOptions().color(Color.WHITE).add(new LatLng()); - PolylineOptions polygonOptions3 = new PolylineOptions(); - polylineList.add(polygonOptions1); - polylineList.add(polygonOptions2); - polylineList.add(polygonOptions3); - mapboxMap.addPolylines(polylineList); - assertEquals("Polygons size should be 2", 2, mapboxMap.getPolylines().size()); - assertTrue(mapboxMap.getPolylines().contains(polygonOptions1.getPolyline())); - assertTrue(mapboxMap.getPolylines().contains(polygonOptions2.getPolyline())); - assertTrue( - "Polyline should be ignored", !mapboxMap.getPolylines().contains(polygonOptions3.getPolyline()) - ); - })); - } - - @Test - public void testAddPolylinesEmpty() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - mapboxMap.addPolylines(new ArrayList()); - assertEquals("Polygons size should be 0", 0, mapboxMap.getPolylines().size()); - })); - } - - @Test - public void testAddPolylinesSingle() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List polylineList = new ArrayList<>(); - PolylineOptions polygonOptions = new PolylineOptions().color(Color.BLACK).add(new LatLng()); - polylineList.add(polygonOptions); - mapboxMap.addPolylines(polylineList); - assertEquals("Polygons size should be 1", 1, mapboxMap.getPolylines().size()); - assertTrue(mapboxMap.getPolylines().contains(polygonOptions.getPolyline())); - })); - } - - @Test - public void testRemoveMarker() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mapboxMap.addMarker(markerOptions); - mapboxMap.removeMarker(marker); - assertTrue("Markers should be empty", mapboxMap.getMarkers().isEmpty()); - })); - } - - @Test - public void testRemovePolygon() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - PolygonOptions polygonOptions = new PolygonOptions(); - Polygon polygon = mapboxMap.addPolygon(polygonOptions); - mapboxMap.removePolygon(polygon); - assertTrue("Polygons should be empty", mapboxMap.getPolylines().isEmpty()); - })); - } - - @Test - public void testRemovePolyline() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - PolylineOptions polylineOptions = new PolylineOptions(); - Polyline polyline = mapboxMap.addPolyline(polylineOptions); - mapboxMap.removePolyline(polyline); - assertTrue("Polylines should be empty", mapboxMap.getPolylines().isEmpty()); - })); - } - - @Test - public void testRemoveAnnotation() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mapboxMap.addMarker(markerOptions); - mapboxMap.removeAnnotation(marker); - assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty()); - })); - } - - @Test - public void testRemoveAnnotationById() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - mapboxMap.addMarker(markerOptions); - // id will always be 0 in unit tests - mapboxMap.removeAnnotation(0); - assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty()); - })); - } - - @Test - public void testRemoveAnnotations() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - mapboxMap.addMarkers(markerList); - mapboxMap.removeAnnotations(); - assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty()); - })); - } - - @Test - public void testClear() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - mapboxMap.addMarkers(markerList); - mapboxMap.clear(); - assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty()); - })); - } - - @Test - public void testRemoveAnnotationsByList() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - List markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - List markers = mapboxMap.addMarkers(markerList); - Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng()).title("c")); - mapboxMap.removeAnnotations(markers); - assertTrue("Annotations should not be empty", mapboxMap.getAnnotations().size() == 1); - assertTrue("Marker should be contained", mapboxMap.getAnnotations().contains(marker)); - })); - } - - @Test - public void testGetAnnotationById() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker initialMarker = mapboxMap.addMarker(markerOptions); - Marker retrievedMarker = (Marker) mapboxMap.getAnnotation(0); - assertEquals("Markers should match", initialMarker, retrievedMarker); - })); - } - - @Test - public void testGetAnnotations() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform( - new MapboxMapAction((uiController, view) -> - assertNotNull("Annotations should be non null", mapboxMap.getAnnotations())) - ); - } - - @Test - public void testGetMarkers() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform( - new MapboxMapAction((uiController, view) -> - assertNotNull("Markers should be non null", mapboxMap.getMarkers())) - ); - } - - @Test - public void testGetPolygons() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> - assertNotNull("Polygons should be non null", mapboxMap.getPolygons())) - ); - } - - @Test - public void testGetPolylines() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> - assertNotNull("Polylines should be non null", mapboxMap.getPolylines())) - ); - } - - @Test - public void testGetSelectedMarkers() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> - assertNotNull("Selected markers should be non null", mapboxMap.getSelectedMarkers())) - ); - } - - @Test - public void testSelectMarker() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mapboxMap.addMarker(markerOptions); - mapboxMap.selectMarker(marker); - assertTrue("Marker should be contained", mapboxMap.getSelectedMarkers().contains(marker)); - })); - } - - @Test - public void testDeselectMarker() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mapboxMap.addMarker(markerOptions); - mapboxMap.selectMarker(marker); - mapboxMap.deselectMarker(marker); - assertTrue("Selected markers should be empty", mapboxMap.getSelectedMarkers().isEmpty()); - })); - } - - @Test - public void testDeselectMarkers() { - validateTestSetup(); - onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker1 = mapboxMap.addMarker(markerOptions); - Marker marker2 = mapboxMap.addMarker(markerOptions); - mapboxMap.selectMarker(marker1); - mapboxMap.selectMarker(marker2); - mapboxMap.deselectMarkers(); - assertTrue("Selected markers should be empty", mapboxMap.getSelectedMarkers().isEmpty()); - })); - } - - public class MapboxMapAction implements ViewAction { - - private InvokeViewAction invokeViewAction; - - MapboxMapAction(InvokeViewAction invokeViewAction) { - this.invokeViewAction = invokeViewAction; - } - - @Override - public Matcher getConstraints() { - return isDisplayed(); - } - - @Override - public String getDescription() { - return getClass().getSimpleName(); - } - - @Override - public void perform(UiController uiController, View view) { - invokeViewAction.onViewAction(uiController, view); - } - } - - interface InvokeViewAction { - void onViewAction(UiController uiController, View view); - } -} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java deleted file mode 100644 index 559213af3d..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.annotations; - -import android.app.Activity; -import android.support.test.annotation.UiThreadTest; -import android.support.v4.content.res.ResourcesCompat; -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.IconFactory; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.IconManagerResolver; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.EspressoTest; -import com.mapbox.mapboxsdk.testapp.utils.IconUtils; -import org.junit.Before; -import org.junit.Test; - -import java.util.Map; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.assertTrue; - -/** - * Tests integration between Icons and Markers - */ -public class IconTest extends EspressoTest { - - private Map iconMap; - - @Before - public void beforeTest() { - super.beforeTest(); - iconMap = new IconManagerResolver(mapboxMap).getIconMap(); - } - - @Test - @UiThreadTest - public void testAddSameIconMarker() { - validateTestSetup(); - Icon defaultMarker = IconFactory.getInstance(rule.getActivity()).defaultMarker(); - mapboxMap.addMarker(new MarkerOptions().position(new LatLng())); - mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); - assertEquals(1, iconMap.size()); - assertEquals(2, iconMap.get(defaultMarker), 0); - } - - @Test - @UiThreadTest - public void testAddDifferentIconMarker() { - validateTestSetup(); - Icon icon = IconFactory.getInstance(rule.getActivity()).fromResource(R.drawable.mapbox_logo_icon); - mapboxMap.addMarker(new MarkerOptions().icon(icon).position(new LatLng())); - mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); - assertEquals(iconMap.size(), 2); - assertTrue(iconMap.containsKey(icon)); - assertTrue(iconMap.get(icon) == 1); - } - - @Test - @UiThreadTest - public void testAddRemoveIconMarker() { - validateTestSetup(); - Icon icon = IconFactory.getInstance(rule.getActivity()).fromResource(R.drawable.mapbox_logo_icon); - Marker marker = mapboxMap.addMarker(new MarkerOptions().icon(icon).position(new LatLng())); - mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); - assertEquals(iconMap.size(), 2); - assertTrue(iconMap.containsKey(icon)); - assertTrue(iconMap.get(icon) == 1); - - mapboxMap.removeMarker(marker); - assertEquals(iconMap.size(), 1); - assertFalse(iconMap.containsKey(icon)); - } - - @Test - @UiThreadTest - public void testAddRemoveDefaultMarker() { - validateTestSetup(); - Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); - assertEquals(iconMap.size(), 1); - - mapboxMap.removeMarker(marker); - assertEquals(iconMap.size(), 0); - - mapboxMap.addMarker(new MarkerOptions().position(new LatLng())); - assertEquals(iconMap.size(), 1); - } - - @Test - @UiThreadTest - public void testAddRemoveMany() { - validateTestSetup(); - Activity activity = rule.getActivity(); - IconFactory iconFactory = IconFactory.getInstance(activity); - - // add 2 default icon markers - Marker defaultMarkerOne = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); - Marker defaultMarkerTwo = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(2, 1))); - - // add 4 unique icon markers - mapboxMap.addMarker(new MarkerOptions() - .icon(iconFactory.fromResource(R.drawable.mapbox_logo_icon)) - .position(new LatLng(3, 1)) - ); - mapboxMap.addMarker(new MarkerOptions() - .icon(iconFactory.fromResource(R.drawable.mapbox_compass_icon)) - .position(new LatLng(4, 1)) - ); - mapboxMap.addMarker(new MarkerOptions() - .icon(IconUtils.drawableToIcon(activity, R.drawable.ic_stars, - ResourcesCompat.getColor(activity.getResources(), - R.color.blueAccent, activity.getTheme()))) - .position(new LatLng(5, 1)) - ); - mapboxMap.addMarker(new MarkerOptions() - .icon(iconFactory.fromResource(R.drawable.ic_android)) - .position(new LatLng(6, 1)) - ); - - assertEquals("Amount of icons should match 5", 5, iconMap.size()); - assertEquals("Refcounter of default marker should match 2", 2, iconMap.get(iconFactory.defaultMarker()), 0); - - mapboxMap.removeMarker(defaultMarkerOne); - - assertEquals("Amount of icons should match 5", 5, iconMap.size()); - assertEquals("Refcounter of default marker should match 1", 1, iconMap.get(iconFactory.defaultMarker()), 0); - - mapboxMap.removeMarker(defaultMarkerTwo); - - assertEquals("Amount of icons should match 4", 4, iconMap.size()); - assertNull("DefaultMarker shouldn't exist anymore", iconMap.get(iconFactory.defaultMarker())); - - mapboxMap.clear(); - assertEquals("Amount of icons should match 0", 0, iconMap.size()); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerTest.java deleted file mode 100644 index 2328023a3d..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.annotations; - -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; -import com.mapbox.mapboxsdk.testapp.activity.EspressoTest; -import com.mapbox.mapboxsdk.testapp.utils.TestConstants; - -import org.junit.Ignore; -import org.junit.Test; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; -import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; -import static org.junit.Assert.assertEquals; - -public class MarkerTest extends EspressoTest { - - private Marker marker; - - @Test - @Ignore - public void addMarkerTest() { - validateTestSetup(); - MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> { - assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size()); - - MarkerOptions options = new MarkerOptions(); - options.setPosition(new LatLng()); - options.setSnippet(TestConstants.TEXT_MARKER_SNIPPET); - options.setTitle(TestConstants.TEXT_MARKER_TITLE); - marker = mapboxMap.addMarker(options); - - assertEquals("Markers size should be 1, ", 1, mapboxMap.getMarkers().size()); - assertEquals("Marker id should be 0", 0, marker.getId()); - assertEquals("Marker target should match", new LatLng(), marker.getPosition()); - assertEquals("Marker snippet should match", TestConstants.TEXT_MARKER_SNIPPET, marker.getSnippet()); - assertEquals("Marker target should match", TestConstants.TEXT_MARKER_TITLE, marker.getTitle()); - mapboxMap.clear(); - assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size()); - }); - } - - @Test - @Ignore - public void showInfoWindowTest() { - validateTestSetup(); - invoke(mapboxMap, (uiController, mapboxMap) -> { - final MarkerOptions options = new MarkerOptions(); - options.setPosition(new LatLng()); - options.setSnippet(TestConstants.TEXT_MARKER_SNIPPET); - options.setTitle(TestConstants.TEXT_MARKER_TITLE); - marker = mapboxMap.addMarker(options); - mapboxMap.selectMarker(marker); - }); - onView(withText(TestConstants.TEXT_MARKER_TITLE)).check(matches(isDisplayed())); - onView(withText(TestConstants.TEXT_MARKER_SNIPPET)).check(matches(isDisplayed())); - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/PolygonTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/PolygonTest.java deleted file mode 100644 index b604bb7da1..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/PolygonTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.annotations; - -import android.graphics.Color; - -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.testapp.activity.EspressoTest; - -import org.junit.Ignore; -import org.junit.Test; - -import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; -import static org.junit.Assert.assertEquals; - -public class PolygonTest extends EspressoTest { - - @Test - @Ignore - public void addPolygonTest() { - validateTestSetup(); - invoke(mapboxMap, (uiController, mapboxMap) -> { - LatLng latLngOne = new LatLng(); - LatLng latLngTwo = new LatLng(1, 0); - LatLng latLngThree = new LatLng(1, 1); - - assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size()); - - final PolygonOptions options = new PolygonOptions(); - options.strokeColor(Color.BLUE); - options.fillColor(Color.RED); - options.add(latLngOne); - options.add(latLngTwo); - options.add(latLngThree); - Polygon polygon = mapboxMap.addPolygon(options); - - assertEquals("Polygons should be 1", 1, mapboxMap.getPolygons().size()); - assertEquals("Polygon id should be 0", 0, polygon.getId()); - assertEquals("Polygon points size should match", 3, polygon.getPoints().size()); - assertEquals("Polygon stroke color should match", Color.BLUE, polygon.getStrokeColor()); - assertEquals("Polygon target should match", Color.RED, polygon.getFillColor()); - mapboxMap.clear(); - assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size()); - }); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/PolylineTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/PolylineTest.java deleted file mode 100644 index f977e25981..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/PolylineTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.annotations; - -import android.graphics.Color; - -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.testapp.activity.EspressoTest; - -import org.junit.Ignore; -import org.junit.Test; - -import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; -import static org.junit.Assert.assertEquals; - -public class PolylineTest extends EspressoTest { - - @Test - @Ignore - public void addPolylineTest() { - validateTestSetup(); - invoke(mapboxMap, (uiController, mapboxMap) -> { - LatLng latLngOne = new LatLng(); - LatLng latLngTwo = new LatLng(1, 0); - - assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size()); - - final PolylineOptions options = new PolylineOptions(); - options.color(Color.BLUE); - options.add(latLngOne); - options.add(latLngTwo); - Polyline polyline = mapboxMap.addPolyline(options); - - assertEquals("Polylines should be 1", 1, mapboxMap.getPolylines().size()); - assertEquals("Polyline id should be 0", 0, polyline.getId()); - assertEquals("Polyline points size should match", 2, polyline.getPoints().size()); - assertEquals("Polyline stroke color should match", Color.BLUE, polyline.getColor()); - mapboxMap.clear(); - assertEquals("Polyline should be empty", 0, mapboxMap.getPolylines().size()); - }); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 18fbf33cc8..84adacd2f5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -26,52 +26,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - randomCars = new ArrayList<>(); - private GeoJsonSource randomCarSource; - private Car taxi; - private GeoJsonSource taxiSource; - private LatLng passenger; - - private List animators = new ArrayList<>(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_animated_marker); - - mapView = findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(map -> { - this.mapboxMap = map; - map.setStyle(Style.MAPBOX_STREETS, style -> { - this.style = style; - setupCars(); - animateRandomRoutes(); - animateTaxi(); - }); - }); - } - - private void setupCars() { - addRandomCars(); - addPassenger(); - addMainCar(); - } - - private void animateRandomRoutes() { - final Car longestDrive = getLongestDrive(); - final Random random = new Random(); - for (final Car car : randomCars) { - final boolean isLongestDrive = longestDrive.equals(car); - ValueAnimator valueAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), car.current, car.next); - valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - - private LatLng latLng; - - @Override - public void onAnimationUpdate(ValueAnimator animation) { - latLng = (LatLng) animation.getAnimatedValue(); - car.current = latLng; - if (isLongestDrive) { - updateRandomCarSource(); - } - } - }); - - if (isLongestDrive) { - valueAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - updateRandomDestinations(); - animateRandomRoutes(); - } - }); - } - - valueAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animation) { - super.onAnimationStart(animation); - car.feature.properties().addProperty("bearing", Car.getBearing(car.current, car.next)); - } - }); - - int offset = random.nextInt(2) == 0 ? 0 : random.nextInt(1000) + 250; - valueAnimator.setStartDelay(offset); - valueAnimator.setDuration(car.duration - offset); - valueAnimator.setInterpolator(new LinearInterpolator()); - valueAnimator.start(); - - animators.add(valueAnimator); - } - } - - private void animateTaxi() { - ValueAnimator valueAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), taxi.current, taxi.next); - valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - - private LatLng latLng; - - @Override - public void onAnimationUpdate(ValueAnimator animation) { - latLng = (LatLng) animation.getAnimatedValue(); - taxi.current = latLng; - updateTaxiSource(); - } - }); - - valueAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - updatePassenger(); - animateTaxi(); - } - }); - - valueAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animation) { - super.onAnimationStart(animation); - taxi.feature.properties().addProperty("bearing", Car.getBearing(taxi.current, taxi.next)); - } - }); - - valueAnimator.setDuration((long) (7 * taxi.current.distanceTo(taxi.next))); - valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); - valueAnimator.start(); - - animators.add(valueAnimator); - } - - private void updatePassenger() { - passenger = getLatLngInBounds(); - updatePassengerSource(); - taxi.setNext(passenger); - } - - private void updatePassengerSource() { - GeoJsonSource source = style.getSourceAs(PASSENGER_SOURCE); - FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] { - Feature.fromGeometry( - Point.fromLngLat( - passenger.getLongitude(), - passenger.getLatitude() - ) - ) - }); - source.setGeoJson(featureCollection); - } - - private void updateTaxiSource() { - taxi.updateFeature(); - taxiSource.setGeoJson(taxi.feature); - } - - private void updateRandomDestinations() { - for (Car randomCar : randomCars) { - randomCar.setNext(getLatLngInBounds()); - } - } - - private Car getLongestDrive() { - Car longestDrive = null; - for (Car randomCar : randomCars) { - if (longestDrive == null) { - longestDrive = randomCar; - } else if (longestDrive.duration < randomCar.duration) { - longestDrive = randomCar; - } - } - return longestDrive; - } - - private void updateRandomCarSource() { - for (Car randomCarsRoute : randomCars) { - randomCarsRoute.updateFeature(); - } - randomCarSource.setGeoJson(featuresFromRoutes()); - } - - private FeatureCollection featuresFromRoutes() { - List features = new ArrayList<>(); - for (Car randomCarsRoute : randomCars) { - features.add(randomCarsRoute.feature); - } - return FeatureCollection.fromFeatures(features); - } - - private long getDuration() { - return random.nextInt(DURATION_RANDOM_MAX) + DURATION_BASE; - } - - private void addRandomCars() { - LatLng latLng; - LatLng next; - for (int i = 0; i < 10; i++) { - latLng = getLatLngInBounds(); - next = getLatLngInBounds(); - - JsonObject properties = new JsonObject(); - properties.addProperty(PROPERTY_BEARING, Car.getBearing(latLng, next)); - - Feature feature = Feature.fromGeometry( - Point.fromLngLat( - latLng.getLongitude(), - latLng.getLatitude() - ), properties); - - randomCars.add( - new Car(feature, next, getDuration()) - ); - } - - randomCarSource = new GeoJsonSource(RANDOM_CAR_SOURCE, featuresFromRoutes()); - style.addSource(randomCarSource); - style.addImage(RANDOM_CAR_IMAGE_ID, - ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_car_top)).getBitmap()); - - SymbolLayer symbolLayer = new SymbolLayer(RANDOM_CAR_LAYER, RANDOM_CAR_SOURCE); - symbolLayer.withProperties( - iconImage(RANDOM_CAR_IMAGE_ID), - iconAllowOverlap(true), - iconRotate(get(PROPERTY_BEARING)), - iconIgnorePlacement(true) - ); - - style.addLayerBelow(symbolLayer, WATERWAY_LAYER_ID); - } - - private void addPassenger() { - passenger = getLatLngInBounds(); - FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] { - Feature.fromGeometry( - Point.fromLngLat( - passenger.getLongitude(), - passenger.getLatitude() - ) - ) - }); - - style.addImage(PASSENGER, - ((BitmapDrawable) getResources().getDrawable(R.drawable.icon_burned)).getBitmap()); - - GeoJsonSource geoJsonSource = new GeoJsonSource(PASSENGER_SOURCE, featureCollection); - style.addSource(geoJsonSource); - - SymbolLayer symbolLayer = new SymbolLayer(PASSENGER_LAYER, PASSENGER_SOURCE); - symbolLayer.withProperties( - iconImage(PASSENGER), - iconIgnorePlacement(true), - iconAllowOverlap(true) - ); - style.addLayerBelow(symbolLayer, RANDOM_CAR_LAYER); - } - - private void addMainCar() { - LatLng latLng = getLatLngInBounds(); - JsonObject properties = new JsonObject(); - properties.addProperty(PROPERTY_BEARING, Car.getBearing(latLng, passenger)); - Feature feature = Feature.fromGeometry( - Point.fromLngLat( - latLng.getLongitude(), - latLng.getLatitude()), properties); - FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] {feature}); - - taxi = new Car(feature, passenger, getDuration()); - style.addImage(TAXI, - ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_taxi_top)).getBitmap()); - taxiSource = new GeoJsonSource(TAXI_SOURCE, featureCollection); - style.addSource(taxiSource); - - SymbolLayer symbolLayer = new SymbolLayer(TAXI_LAYER, TAXI_SOURCE); - symbolLayer.withProperties( - iconImage(TAXI), - iconRotate(get(PROPERTY_BEARING)), - iconAllowOverlap(true), - iconIgnorePlacement(true) - - ); - style.addLayer(symbolLayer); - } - - private LatLng getLatLngInBounds() { - LatLngBounds bounds = mapboxMap.getProjection().getVisibleRegion().latLngBounds; - Random generator = new Random(); - double randomLat = bounds.getLatSouth() + generator.nextDouble() - * (bounds.getLatNorth() - bounds.getLatSouth()); - double randomLon = bounds.getLonWest() + generator.nextDouble() - * (bounds.getLonEast() - bounds.getLonWest()); - return new LatLng(randomLat, randomLon); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - - for (Animator animator : animators) { - if (animator != null) { - animator.removeAllListeners(); - animator.cancel(); - } - } - - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - /** - * Evaluator for LatLng pairs - */ - private static class LatLngEvaluator implements TypeEvaluator { - - private LatLng latLng = new LatLng(); - - @Override - public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { - latLng.setLatitude(startValue.getLatitude() - + ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); - latLng.setLongitude(startValue.getLongitude() - + ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); - return latLng; - } - } - - - private static class Car { - private Feature feature; - private LatLng next; - private LatLng current; - private long duration; - - Car(Feature feature, LatLng next, long duration) { - this.feature = feature; - Point point = ((Point) feature.geometry()); - this.current = new LatLng(point.latitude(), point.longitude()); - this.duration = duration; - this.next = next; - } - - void setNext(LatLng next) { - this.next = next; - } - - void updateFeature() { - feature = Feature.fromGeometry(Point.fromLngLat( - current.getLongitude(), - current.getLatitude()) - ); - feature.properties().addProperty("bearing", getBearing(current, next)); - } - - private static float getBearing(LatLng from, LatLng to) { - return (float) TurfMeasurement.bearing( - Point.fromLngLat(from.getLongitude(), from.getLatitude()), - Point.fromLngLat(to.getLongitude(), to.getLatitude()) - ); - } - } -} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java deleted file mode 100644 index 05337081dc..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.annotation; - -import android.app.ProgressDialog; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.AppCompatActivity; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Spinner; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil; -import timber.log.Timber; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -/** - * Test activity showcasing adding a large amount of Markers. - */ -public class BulkMarkerActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { - - private MapboxMap mapboxMap; - private MapView mapView; - private List locations; - private ProgressDialog progressDialog; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_marker_bulk); - - mapView = findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(this::initMap); - } - - private void initMap(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; - mapboxMap.setStyle(Style.MAPBOX_STREETS); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - ArrayAdapter spinnerAdapter = ArrayAdapter.createFromResource( - this, R.array.bulk_marker_list, android.R.layout.simple_spinner_item); - spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - getMenuInflater().inflate(R.menu.menu_bulk_marker, menu); - MenuItem item = menu.findItem(R.id.spinner); - Spinner spinner = (Spinner) MenuItemCompat.getActionView(item); - spinner.setAdapter(spinnerAdapter); - spinner.setOnItemSelectedListener(BulkMarkerActivity.this); - return true; - } - - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - int amount = Integer.valueOf(getResources().getStringArray(R.array.bulk_marker_list)[position]); - if (locations == null) { - progressDialog = ProgressDialog.show(this, "Loading", "Fetching markers", false); - new LoadLocationTask(this, amount).execute(); - } else { - showMarkers(amount); - } - } - - private void onLatLngListLoaded(List latLngs, int amount) { - progressDialog.hide(); - locations = latLngs; - showMarkers(amount); - } - - private void showMarkers(int amount) { - if (mapboxMap == null || locations == null || mapView.isDestroyed()) { - return; - } - - mapboxMap.clear(); - if (locations.size() < amount) { - amount = locations.size(); - } - - showGlMarkers(amount); - } - - private void showGlMarkers(int amount) { - List markerOptionsList = new ArrayList<>(); - DecimalFormat formatter = new DecimalFormat("#.#####"); - Random random = new Random(); - int randomIndex; - - for (int i = 0; i < amount; i++) { - randomIndex = random.nextInt(locations.size()); - LatLng latLng = locations.get(randomIndex); - markerOptionsList.add(new MarkerOptions() - .position(latLng) - .title(String.valueOf(i)) - .snippet(formatter.format(latLng.getLatitude()) + ", " + formatter.format(latLng.getLongitude()))); - } - - mapboxMap.addMarkers(markerOptionsList); - } - - @Override - public void onNothingSelected(AdapterView parent) { - // nothing selected, nothing to do! - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - private static class LoadLocationTask extends AsyncTask> { - - private WeakReference activity; - private int amount; - - private LoadLocationTask(BulkMarkerActivity activity, int amount) { - this.amount = amount; - this.activity = new WeakReference<>(activity); - } - - @Override - protected List doInBackground(Void... params) { - BulkMarkerActivity activity = this.activity.get(); - if (activity != null) { - String json = null; - try { - json = GeoParseUtil.loadStringFromAssets(activity.getApplicationContext(), "points.geojson"); - } catch (IOException exception) { - Timber.e(exception, "Could not add markers"); - } - - if (json != null) { - return GeoParseUtil.parseGeoJsonCoordinates(json); - } - } - return null; - } - - @Override - protected void onPostExecute(List locations) { - super.onPostExecute(locations); - BulkMarkerActivity activity = this.activity.get(); - if (activity != null) { - activity.onLatLngListLoaded(locations, amount); - } - } - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java deleted file mode 100644 index b10332dd6d..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.annotation; - -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.content.ContextCompat; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v7.app.AppCompatActivity; - -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.utils.IconUtils; - -/** - * Test activity showcasing updating a Marker position, title, icon and snippet. - */ -public class DynamicMarkerChangeActivity extends AppCompatActivity { - - private static final LatLng LAT_LNG_CHELSEA = new LatLng(51.481670, -0.190849); - private static final LatLng LAT_LNG_ARSENAL = new LatLng(51.555062, -0.108417); - - private MapView mapView; - private MapboxMap mapboxMap; - private Marker marker; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_dynamic_marker); - - mapView = findViewById(R.id.mapView); - mapView.setTag(false); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(mapboxMap -> { - mapboxMap.setStyle(Style.MAPBOX_STREETS); - - DynamicMarkerChangeActivity.this.mapboxMap = mapboxMap; - // Create marker - MarkerOptions markerOptions = new MarkerOptions() - .position(LAT_LNG_CHELSEA) - .icon(IconUtils.drawableToIcon(DynamicMarkerChangeActivity.this, R.drawable.ic_stars, - ResourcesCompat.getColor(getResources(), R.color.blueAccent, getTheme()))) - .title(getString(R.string.dynamic_marker_chelsea_title)) - .snippet(getString(R.string.dynamic_marker_chelsea_snippet)); - marker = mapboxMap.addMarker(markerOptions); - }); - - FloatingActionButton fab = findViewById(R.id.fab); - fab.setColorFilter(ContextCompat.getColor(this, R.color.primary)); - fab.setOnClickListener(view -> { - if (mapboxMap != null) { - updateMarker(); - } - }); - } - - private void updateMarker() { - // update model - boolean first = (boolean) mapView.getTag(); - mapView.setTag(!first); - - // update marker - marker.setPosition(first ? LAT_LNG_CHELSEA : LAT_LNG_ARSENAL); - marker.setIcon(IconUtils.drawableToIcon(this, R.drawable.ic_stars, first - ? ResourcesCompat.getColor(getResources(), R.color.blueAccent, getTheme()) : - ResourcesCompat.getColor(getResources(), R.color.redAccent, getTheme()) - )); - - marker.setTitle(first - ? getString(R.string.dynamic_marker_chelsea_title) : getString(R.string.dynamic_marker_arsenal_title)); - marker.setSnippet(first - ? getString(R.string.dynamic_marker_chelsea_snippet) : getString(R.string.dynamic_marker_arsenal_snippet)); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java deleted file mode 100644 index fe71020eb2..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.annotation; - -import android.graphics.Color; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.Toast; - -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.MapboxMapOptions; -import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.testapp.R; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static com.mapbox.mapboxsdk.testapp.activity.annotation.PolygonActivity.Config.BLUE_COLOR; -import static com.mapbox.mapboxsdk.testapp.activity.annotation.PolygonActivity.Config.BROKEN_SHAPE_POINTS; -import static com.mapbox.mapboxsdk.testapp.activity.annotation.PolygonActivity.Config.FULL_ALPHA; -import static com.mapbox.mapboxsdk.testapp.activity.annotation.PolygonActivity.Config.NO_ALPHA; -import static com.mapbox.mapboxsdk.testapp.activity.annotation.PolygonActivity.Config.PARTIAL_ALPHA; -import static com.mapbox.mapboxsdk.testapp.activity.annotation.PolygonActivity.Config.RED_COLOR; -import static com.mapbox.mapboxsdk.testapp.activity.annotation.PolygonActivity.Config.STAR_SHAPE_HOLES; -import static com.mapbox.mapboxsdk.testapp.activity.annotation.PolygonActivity.Config.STAR_SHAPE_POINTS; - -/** - * Test activity to showcase the Polygon annotation API & programmatically creating a MapView. - *

- * Shows how to change Polygon features as visibility, alpha, color and points. - *

- */ -public class PolygonActivity extends AppCompatActivity implements OnMapReadyCallback { - - private MapView mapView; - private MapboxMap mapboxMap; - - private Polygon polygon; - private boolean fullAlpha = true; - private boolean visible = true; - private boolean color = true; - private boolean allPoints = true; - private boolean holes = false; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // configure inital map state - MapboxMapOptions options = new MapboxMapOptions() - .attributionTintColor(RED_COLOR) - .compassFadesWhenFacingNorth(false) - .camera(new CameraPosition.Builder() - .target(new LatLng(45.520486, -122.673541)) - .zoom(12) - .tilt(40) - .build()); - - // create map - mapView = new MapView(this, options); - mapView.setId(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(this); - - setContentView(mapView); - } - - @Override - public void onMapReady(@NonNull MapboxMap map) { - mapboxMap = map; - map.setStyle(Style.MAPBOX_STREETS); - - map.setOnPolygonClickListener(polygon -> Toast.makeText( - PolygonActivity.this, - "You clicked on polygon with id = " + polygon.getId(), - Toast.LENGTH_SHORT - ).show()); - - polygon = mapboxMap.addPolygon(new PolygonOptions() - .addAll(STAR_SHAPE_POINTS) - .fillColor(BLUE_COLOR)); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_id_alpha: - fullAlpha = !fullAlpha; - polygon.setAlpha(fullAlpha ? FULL_ALPHA : PARTIAL_ALPHA); - return true; - case R.id.action_id_visible: - visible = !visible; - polygon.setAlpha(visible ? (fullAlpha ? FULL_ALPHA : PARTIAL_ALPHA) : NO_ALPHA); - return true; - case R.id.action_id_points: - allPoints = !allPoints; - polygon.setPoints(allPoints ? STAR_SHAPE_POINTS : BROKEN_SHAPE_POINTS); - return true; - case R.id.action_id_color: - color = !color; - polygon.setFillColor(color ? BLUE_COLOR : RED_COLOR); - return true; - case R.id.action_id_holes: - holes = !holes; - polygon.setHoles(holes ? STAR_SHAPE_HOLES : Collections.>emptyList()); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_polygon, menu); - return true; - } - - static final class Config { - static final int BLUE_COLOR = Color.parseColor("#3bb2d0"); - static final int RED_COLOR = Color.parseColor("#AF0000"); - - static final float FULL_ALPHA = 1.0f; - static final float PARTIAL_ALPHA = 0.5f; - static final float NO_ALPHA = 0.0f; - - static final List STAR_SHAPE_POINTS = new ArrayList() { - { - add(new LatLng(45.522585, -122.685699)); - add(new LatLng(45.534611, -122.708873)); - add(new LatLng(45.530883, -122.678833)); - add(new LatLng(45.547115, -122.667503)); - add(new LatLng(45.530643, -122.660121)); - add(new LatLng(45.533529, -122.636260)); - add(new LatLng(45.521743, -122.659091)); - add(new LatLng(45.510677, -122.648792)); - add(new LatLng(45.515008, -122.664070)); - add(new LatLng(45.502496, -122.669048)); - add(new LatLng(45.515369, -122.678489)); - add(new LatLng(45.506346, -122.702007)); - add(new LatLng(45.522585, -122.685699)); - } - }; - - static final List BROKEN_SHAPE_POINTS = - STAR_SHAPE_POINTS.subList(0, STAR_SHAPE_POINTS.size() - 3); - - static final List> STAR_SHAPE_HOLES = new ArrayList>() { - { - add(new ArrayList<>(new ArrayList() { - { - add(new LatLng(45.521743, -122.669091)); - add(new LatLng(45.530483, -122.676833)); - add(new LatLng(45.520483, -122.676833)); - add(new LatLng(45.521743, -122.669091)); - } - })); - add(new ArrayList<>(new ArrayList() { - { - add(new LatLng(45.529743, -122.662791)); - add(new LatLng(45.525543, -122.662791)); - add(new LatLng(45.525543, -122.660)); - add(new LatLng(45.527743, -122.660)); - add(new LatLng(45.529743, -122.662791)); - } - })); - } - }; - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java deleted file mode 100644 index 855b686691..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java +++ /dev/null @@ -1,224 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.annotation; - -import android.graphics.Color; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Toast; - -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Test activity showcasing the Polyline annotations API. - *

- * Shows how to add and remove polylines. - *

- */ -public class PolylineActivity extends AppCompatActivity { - - private static final String STATE_POLYLINE_OPTIONS = "polylineOptions"; - - private static final LatLng ANDORRA = new LatLng(42.505777, 1.52529); - private static final LatLng LUXEMBOURG = new LatLng(49.815273, 6.129583); - private static final LatLng MONACO = new LatLng(43.738418, 7.424616); - private static final LatLng VATICAN_CITY = new LatLng(41.902916, 12.453389); - private static final LatLng SAN_MARINO = new LatLng(43.942360, 12.457777); - private static final LatLng LIECHTENSTEIN = new LatLng(47.166000, 9.555373); - - private static final float FULL_ALPHA = 1.0f; - private static final float PARTIAL_ALPHA = 0.5f; - private static final float NO_ALPHA = 0.0f; - - private List polylines; - private ArrayList polylineOptions = new ArrayList<>(); - private MapView mapView; - private MapboxMap mapboxMap; - - private boolean fullAlpha = true; - private boolean visible = true; - private boolean width = true; - private boolean color = true; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_polyline); - - if (savedInstanceState != null) { - polylineOptions = savedInstanceState.getParcelableArrayList(STATE_POLYLINE_OPTIONS); - } else { - polylineOptions.addAll(getAllPolylines()); - } - - mapView = findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(mapboxMap -> { - PolylineActivity.this.mapboxMap = mapboxMap; - mapboxMap.setStyle(Style.SATELLITE_STREETS); - mapboxMap.setOnPolylineClickListener(polyline -> Toast.makeText( - PolylineActivity.this, - "You clicked on polyline with id = " + polyline.getId(), - Toast.LENGTH_SHORT - ).show()); - - polylines = mapboxMap.addPolylines(polylineOptions); - }); - - View fab = findViewById(R.id.fab); - if (fab != null) { - fab.setOnClickListener(view -> { - if (mapboxMap != null) { - if (polylines != null && polylines.size() > 0) { - if (polylines.size() == 1) { - // test for removing annotation - mapboxMap.removeAnnotation(polylines.get(0)); - } else { - // test for removing annotations - mapboxMap.removeAnnotations(polylines); - } - } - polylineOptions.clear(); - polylineOptions.addAll(getRandomLine()); - polylines = mapboxMap.addPolylines(polylineOptions); - - } - }); - } - } - - private List getAllPolylines() { - List options = new ArrayList<>(); - options.add(generatePolyline(ANDORRA, LUXEMBOURG, "#F44336")); - options.add(generatePolyline(ANDORRA, MONACO, "#FF5722")); - options.add(generatePolyline(MONACO, VATICAN_CITY, "#673AB7")); - options.add(generatePolyline(VATICAN_CITY, SAN_MARINO, "#009688")); - options.add(generatePolyline(SAN_MARINO, LIECHTENSTEIN, "#795548")); - options.add(generatePolyline(LIECHTENSTEIN, LUXEMBOURG, "#3F51B5")); - return options; - } - - private PolylineOptions generatePolyline(LatLng start, LatLng end, String color) { - PolylineOptions line = new PolylineOptions(); - line.add(start); - line.add(end); - line.color(Color.parseColor(color)); - return line; - } - - public List getRandomLine() { - final List randomLines = getAllPolylines(); - Collections.shuffle(randomLines); - return new ArrayList() { - { - add(randomLines.get(0)); - } - }; - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - outState.putParcelableArrayList(STATE_POLYLINE_OPTIONS, polylineOptions); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_polyline, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (polylines.size() <= 0) { - Toast.makeText(PolylineActivity.this, "No polylines on map", Toast.LENGTH_LONG).show(); - return super.onOptionsItemSelected(item); - } - switch (item.getItemId()) { - case R.id.action_id_remove: - // test to remove all annotations - polylineOptions.clear(); - mapboxMap.clear(); - polylines.clear(); - return true; - - case R.id.action_id_alpha: - fullAlpha = !fullAlpha; - for (Polyline p : polylines) { - p.setAlpha(fullAlpha ? FULL_ALPHA : PARTIAL_ALPHA); - } - return true; - - case R.id.action_id_color: - color = !color; - for (Polyline p : polylines) { - p.setColor(color ? Color.RED : Color.BLUE); - } - return true; - - case R.id.action_id_width: - width = !width; - for (Polyline p : polylines) { - p.setWidth(width ? 3.0f : 5.0f); - } - return true; - - case R.id.action_id_visible: - visible = !visible; - for (Polyline p : polylines) { - p.setAlpha(visible ? (fullAlpha ? FULL_ALPHA : PARTIAL_ALPHA) : NO_ALPHA); - } - return true; - default: - return super.onOptionsItemSelected(item); - } - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PressForMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PressForMarkerActivity.java deleted file mode 100644 index 5bd59507a9..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PressForMarkerActivity.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.annotation; - -import android.graphics.PointF; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.view.Menu; -import android.view.MenuItem; - -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; - -import java.text.DecimalFormat; -import java.util.ArrayList; - -/** - * Test activity showcasing to add a Marker on click. - *

- * Shows how to use a OnMapClickListener and a OnMapLongClickListener - *

- */ -public class PressForMarkerActivity extends AppCompatActivity { - - private MapView mapView; - private MapboxMap mapboxMap; - private ArrayList markerList = new ArrayList<>(); - - private static final DecimalFormat LAT_LON_FORMATTER = new DecimalFormat("#.#####"); - - private static String STATE_MARKER_LIST = "markerList"; - - @Override - protected void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_press_for_marker); - - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(map -> { - mapboxMap = map; - resetMap(); - - mapboxMap.addOnMapLongClickListener(point -> { - addMarker(point); - return false; - }); - - mapboxMap.addOnMapClickListener(point -> { - addMarker(point); - return false; - }); - - mapboxMap.setStyle(Style.MAPBOX_STREETS); - - if (savedInstanceState != null) { - markerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST); - if (markerList != null) { - mapboxMap.addMarkers(markerList); - } - } - }); - } - - private void addMarker(LatLng point) { - final PointF pixel = mapboxMap.getProjection().toScreenLocation(point); - - String title = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " - + LAT_LON_FORMATTER.format(point.getLongitude()); - String snippet = "X = " + (int) pixel.x + ", Y = " + (int) pixel.y; - - MarkerOptions marker = new MarkerOptions() - .position(point) - .title(title) - .snippet(snippet); - - markerList.add(marker); - mapboxMap.addMarker(marker); - } - - private void resetMap() { - if (mapboxMap == null) { - return; - } - mapboxMap.removeAnnotations(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_press_for_marker, menu); - return true; - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - - mapView.onSaveInstanceState(outState); - outState.putParcelableArrayList(STATE_MARKER_LIST, markerList); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menuItemReset: - resetMap(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/GestureDetectorActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/GestureDetectorActivity.java index ed5364655e..018bda2251 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/GestureDetectorActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/GestureDetectorActivity.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.camera; +import android.graphics.Bitmap; import android.graphics.Typeface; import android.os.Bundle; import android.os.Handler; @@ -8,6 +9,7 @@ import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.support.v4.content.res.ResourcesCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -18,28 +20,30 @@ import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; import android.widget.TextView; - import com.mapbox.android.gestures.AndroidGesturesManager; import com.mapbox.android.gestures.MoveGestureDetector; import com.mapbox.android.gestures.RotateGestureDetector; import com.mapbox.android.gestures.ShoveGestureDetector; import com.mapbox.android.gestures.StandardScaleGestureDetector; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Style; import com.mapbox.mapboxsdk.maps.UiSettings; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.utils.FontCache; import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils; +import com.mapbox.mapboxsdk.utils.BitmapUtils; import java.lang.annotation.Retention; import java.util.ArrayList; import java.util.List; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; import static java.lang.annotation.RetentionPolicy.SOURCE; /** @@ -48,16 +52,17 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; public class GestureDetectorActivity extends AppCompatActivity { private static final int MAX_NUMBER_OF_ALERTS = 30; + private static final String SYMBOL_LAYER_ID = "symbol-layer-id"; + private static final String SYMBOL_SOURCE_ID = "symbol-source-id"; private MapView mapView; private MapboxMap mapboxMap; private RecyclerView recyclerView; private GestureAlertsAdapter gestureAlertsAdapter; - private AndroidGesturesManager gesturesManager; + private GeoJsonSource geoJsonSource; + private SymbolLayer symbolLayer; - @Nullable - private Marker marker; @Nullable private LatLng focalPointLatLng; @@ -70,7 +75,23 @@ public class GestureDetectorActivity extends AppCompatActivity { mapView.onCreate(savedInstanceState); mapView.getMapAsync(mapboxMap -> { GestureDetectorActivity.this.mapboxMap = mapboxMap; - mapboxMap.setStyle(Style.MAPBOX_STREETS); + + geoJsonSource = new GeoJsonSource(SYMBOL_SOURCE_ID); + symbolLayer = new SymbolLayer(SYMBOL_LAYER_ID, SYMBOL_SOURCE_ID) + .withProperties( + iconImage("marker") + ); + + Bitmap marker = BitmapUtils.getBitmapFromDrawable( + ResourcesCompat.getDrawable(getResources(), R.drawable.mapbox_marker_icon, getTheme()) + ); + + mapboxMap.setStyle(new Style.Builder() + .fromUrl(Style.MAPBOX_STREETS) + .withSource(geoJsonSource) + .withLayer(symbolLayer) + .withImage("marker", marker) + ); initializeMap(); }); @@ -266,7 +287,7 @@ public class GestureDetectorActivity extends AppCompatActivity { private void fixedFocalPointEnabled(boolean enabled) { if (enabled) { focalPointLatLng = new LatLng(51.50325, -0.12968); - marker = mapboxMap.addMarker(new MarkerOptions().position(focalPointLatLng)); + geoJsonSource.setGeoJson(Point.fromLngLat(focalPointLatLng.getLongitude(), focalPointLatLng.getLatitude())); mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(focalPointLatLng, 16), new MapboxMap.CancelableCallback() { @Override @@ -280,9 +301,8 @@ public class GestureDetectorActivity extends AppCompatActivity { } }); } else { - if (marker != null) { - mapboxMap.removeMarker(marker); - marker = null; + if (focalPointLatLng != null) { + geoJsonSource.setGeoJson(""); } focalPointLatLng = null; mapboxMap.getUiSettings().setFocalPoint(null); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java index 23f887eb88..51c34a66c2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java @@ -1,24 +1,32 @@ package com.mapbox.mapboxsdk.testapp.activity.camera; +import android.graphics.Bitmap; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomSheetBehavior; +import android.support.v4.content.res.ResourcesCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; - -import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.view.LockableBottomSheetBehavior; +import com.mapbox.mapboxsdk.utils.BitmapUtils; import java.util.ArrayList; import java.util.List; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; + /** * Test activity showcasing using the LatLngBounds camera API. */ @@ -43,6 +51,9 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl private static final int ANIMATION_DURATION_SHORT = 250; private static final int BOUNDS_PADDING_DIVIDER_SMALL = 3; private static final int BOUNDS_PADDING_DIVIDER_LARGE = 9; + private static final String SYMBOL_SOURCE_ID = "source=id"; + private static final String SYMBOL_LAYER_ID = "layer=id"; + private static final String ICON_ID = "marker"; private MapView mapView; private MapboxMap mapboxMap; @@ -60,6 +71,18 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl private void initMapView(Bundle savedInstanceState) { mapView = findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); + + mapView.addOnStyleImageMissingListener(id -> { + if (mapboxMap != null && id.equals(ICON_ID)) { + mapboxMap.getStyle(style -> { + Bitmap marker = BitmapUtils.getBitmapFromDrawable( + ResourcesCompat.getDrawable(getResources(), R.drawable.mapbox_marker_icon, getTheme()) + ); + assert marker != null; + style.addImage(id, marker); + }); + } + }); mapView.getMapAsync(map -> { mapboxMap = map; disableGestures(); @@ -81,9 +104,15 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl } private void addMarkers() { + final List features = new ArrayList<>(); for (LatLng location : LOCATIONS) { - mapboxMap.addMarker(new MarkerOptions().position(location)); + features.add(Feature.fromGeometry(Point.fromLngLat(location.getLongitude(), location.getLatitude()))); } + + mapboxMap.getStyle(style -> { + style.addSource(new GeoJsonSource(SYMBOL_SOURCE_ID, FeatureCollection.fromFeatures(features))); + style.addLayer(new SymbolLayer(SYMBOL_LAYER_ID, SYMBOL_SOURCE_ID).withProperties(iconImage("marker"))); + }); } private void initFab() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.java index 22daf262d8..c2f3a76b02 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.java @@ -7,7 +7,6 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Toast; - import com.mapbox.geojson.Feature; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; @@ -17,12 +16,11 @@ import com.mapbox.mapboxsdk.style.layers.SymbolLayer; import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils; +import timber.log.Timber; import java.io.IOException; import java.util.List; -import timber.log.Timber; - import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; @@ -45,14 +43,14 @@ public class QueryRenderedFeaturesBoxSymbolCountActivity extends AppCompatActivi final View selectionBox = findViewById(R.id.selection_box); // Initialize map as normal - mapView = (MapView) findViewById(R.id.mapView); + mapView = findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); mapView.getMapAsync(mapboxMap -> { QueryRenderedFeaturesBoxSymbolCountActivity.this.mapboxMap = mapboxMap; try { String testPoints = ResourceUtils.readRawResource(mapView.getContext(), R.raw.test_points_utrecht); - Bitmap markerImage = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default); + Bitmap markerImage = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon); mapboxMap.setStyle(new Style.Builder() .withLayer( diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.java index f2f22bae9e..f31b5c8b8a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.java @@ -1,40 +1,38 @@ package com.mapbox.mapboxsdk.testapp.activity.feature; -import android.graphics.Color; import android.graphics.PointF; import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.TextView; - import com.google.gson.JsonElement; import com.mapbox.geojson.Feature; -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.testapp.R; - +import timber.log.Timber; import java.util.List; import java.util.Map; -import timber.log.Timber; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField; /** * Test activity showcasing using the query rendered features API to query feature properties on Map click. */ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity { - public MapView mapView; + private static final String SYMBOL_SOURCE_ID = "symbol-source-id"; + private static final String SYMBOL_LAYER_ID = "symbol-source-id"; + + private MapView mapView; private MapboxMap mapboxMap; - private Marker marker; + private GeoJsonSource geoJsonSource; + private SymbolLayer symbolLayer; private MapboxMap.OnMapClickListener mapClickListener = new MapboxMap.OnMapClickListener() { @Override @@ -50,14 +48,19 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity { // Debug output debugOutput(features); - // Remove any previous markers - if (marker != null) { - mapboxMap.removeMarker(marker); - } + geoJsonSource.setGeoJson(Feature.fromGeometry(Point.fromLngLat(point.getLongitude(), point.getLatitude()))); - // Add a marker on the clicked point - marker = mapboxMap.addMarker(new CustomMarkerOptions().position(point).features(features)); - mapboxMap.selectMarker(marker); + StringBuilder stringBuilder = new StringBuilder(); + if (!features.isEmpty()) { + stringBuilder.append(String.format("Found %s features\n", features.size())); + Feature feature = features.get(0); + for (Map.Entry prop : feature.properties().entrySet()) { + stringBuilder.append(String.format("%s: %s\n", prop.getKey(), prop.getValue())); + } + } else { + stringBuilder.append("No features here"); + } + symbolLayer.setProperties(textField(stringBuilder.toString())); return true; } }; @@ -68,15 +71,13 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity { setContentView(R.layout.activity_query_features_point); // Initialize map as normal - mapView = (MapView) findViewById(R.id.mapView); + mapView = findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); mapView.getMapAsync(mapboxMap -> { mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> { QueryRenderedFeaturesPropertiesActivity.this.mapboxMap = mapboxMap; - - // Add custom window adapter - addCustomInfoWindowAdapter(mapboxMap); - + style.addSource(geoJsonSource = new GeoJsonSource(SYMBOL_SOURCE_ID)); + style.addLayer(symbolLayer = new SymbolLayer(SYMBOL_LAYER_ID, SYMBOL_SOURCE_ID)); // Add a click listener mapboxMap.addOnMapClickListener(mapClickListener); }); @@ -103,41 +104,6 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity { } } - private void addCustomInfoWindowAdapter(MapboxMap mapboxMap) { - mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() { - - private TextView row(String text) { - TextView view = new TextView(QueryRenderedFeaturesPropertiesActivity.this); - view.setText(text); - return view; - } - - @Override - public View getInfoWindow(@NonNull Marker marker) { - CustomMarker customMarker = (CustomMarker) marker; - LinearLayout view = new LinearLayout(QueryRenderedFeaturesPropertiesActivity.this); - view.setOrientation(LinearLayout.VERTICAL); - view.setBackgroundColor(Color.WHITE); - - if (customMarker.features.size() > 0) { - view.addView(row(String.format("Found %s features", customMarker.features.size()))); - Feature feature = customMarker.features.get(0); - for (Map.Entry prop : feature.properties().entrySet()) { - view.addView(row(String.format("%s: %s", prop.getKey(), prop.getValue()))); - } - } else { - view.addView(row("No features here")); - } - - return view; - } - }); - } - - public MapboxMap getMapboxMap() { - return mapboxMap; - } - @Override protected void onStart() { super.onStart(); @@ -182,63 +148,4 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity { super.onLowMemory(); mapView.onLowMemory(); } - - private static class CustomMarker extends Marker { - - private final List features; - - CustomMarker(BaseMarkerOptions baseMarkerOptions, List features) { - super(baseMarkerOptions); - this.features = features; - } - } - - private static class CustomMarkerOptions extends BaseMarkerOptions { - - - private List features; - - public CustomMarkerOptions features(List features) { - this.features = features; - return this; - } - - CustomMarkerOptions() { - } - - private CustomMarkerOptions(Parcel in) { - // Should implement this - } - - @Override - public CustomMarkerOptions getThis() { - return this; - } - - @Override - public CustomMarker getMarker() { - return new CustomMarker(this, features); - } - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - public CustomMarkerOptions createFromParcel(Parcel in) { - return new CustomMarkerOptions(in); - } - - public CustomMarkerOptions[] newArray(int size) { - return new CustomMarkerOptions[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - // Should implement this - } - } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/FragmentBackStackActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/FragmentBackStackActivity.kt index febe17a701..199e0096ec 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/FragmentBackStackActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/FragmentBackStackActivity.kt @@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.testapp.activity.fragment import android.os.Bundle import android.support.v7.app.AppCompatActivity -import android.view.View import com.mapbox.mapboxsdk.maps.MapboxMap import com.mapbox.mapboxsdk.maps.Style import com.mapbox.mapboxsdk.maps.SupportMapFragment @@ -28,7 +27,7 @@ class FragmentBackStackActivity : AppCompatActivity() { add(R.id.container, mapFragment) }.commit() - button.setOnClickListener { handleClick(it) } + button.setOnClickListener { handleClick() } } private fun initMap(mapboxMap: MapboxMap) { @@ -37,7 +36,7 @@ class FragmentBackStackActivity : AppCompatActivity() { } } - private fun handleClick(button: View) { + private fun handleClick() { supportFragmentManager.beginTransaction().apply { replace(R.id.container, NestedViewPagerActivity.ItemAdapter.EmptyFragment()) addToBackStack("map_empty_fragment") diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java deleted file mode 100644 index c5743518b1..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.infowindow; - -import android.graphics.Color; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v7.app.AppCompatActivity; -import android.widget.TextView; - -import com.mapbox.mapboxsdk.annotations.InfoWindow; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.utils.IconUtils; - -import java.util.Locale; - -/** - * Test activity showcasing how to dynamically update InfoWindow when Using an MapboxMap.InfoWindowAdapter. - */ -public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implements OnMapReadyCallback { - - private static final LatLng PARIS = new LatLng(48.864716, 2.349014); - - private MapboxMap mapboxMap; - private MapView mapView; - private Marker marker; - - private MapboxMap.OnMapClickListener mapClickListener = new MapboxMap.OnMapClickListener() { - @Override - public boolean onMapClick(@NonNull LatLng point) { - if (marker == null) { - return false; - } - - // Distance from click to marker - double distanceKm = marker.getPosition().distanceTo(point) / 1000; - - // Get the info window - final InfoWindow infoWindow = marker.getInfoWindow(); - - // Get the view from the info window - if (infoWindow != null && infoWindow.getView() != null) { - // Set the new text on the text view in the info window - TextView textView = (TextView) infoWindow.getView(); - textView.setText(String.format(Locale.getDefault(), "%.2fkm", distanceKm)); - // Update the info window position (as the text length changes) - textView.post(infoWindow::update); - } - return true; - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_infowindow_adapter); - - mapView = findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(this); - } - - @Override - public void onMapReady(@NonNull MapboxMap map) { - mapboxMap = map; - - map.setStyle(Style.MAPBOX_STREETS); - - // Add info window adapter - addCustomInfoWindowAdapter(mapboxMap); - - // Keep info windows open on click - mapboxMap.getUiSettings().setDeselectMarkersOnTap(false); - - // Add a marker - marker = addMarker(mapboxMap); - mapboxMap.selectMarker(marker); - - // On map click, change the info window contents - mapboxMap.addOnMapClickListener(mapClickListener); - - // Focus on Paris - mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(PARIS)); - } - - private Marker addMarker(MapboxMap mapboxMap) { - return mapboxMap.addMarker( - new MarkerOptions() - .position(PARIS) - .icon(IconUtils.drawableToIcon(this, R.drawable.ic_location_city, - ResourcesCompat.getColor(getResources(), R.color.mapbox_blue, getTheme())) - )); - } - - private void addCustomInfoWindowAdapter(final MapboxMap mapboxMap) { - final int padding = (int) getResources().getDimension(R.dimen.attr_margin); - mapboxMap.setInfoWindowAdapter(marker -> { - TextView textView = new TextView(DynamicInfoWindowAdapterActivity.this); - textView.setText(marker.getTitle()); - textView.setBackgroundColor(Color.WHITE); - textView.setText(R.string.action_calculate_distance); - textView.setPadding(padding, padding, padding, padding); - return textView; - }); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (mapboxMap != null) { - mapboxMap.removeOnMapClickListener(mapClickListener); - } - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.java deleted file mode 100644 index 5baa214698..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.infowindow; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.Toast; - -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; - -import java.text.DecimalFormat; - -/** - * Test activity showcasing using the InfoWindow API above Washington D.C. - *

- * Allows to test mulitple concurrently open InfoWindows. - *

- */ -public class InfoWindowActivity extends AppCompatActivity - implements OnMapReadyCallback, MapboxMap.OnInfoWindowCloseListener, MapboxMap.OnInfoWindowClickListener, - MapboxMap.OnInfoWindowLongClickListener { - - private MapboxMap mapboxMap; - private MapView mapView; - private Marker customMarker; - - private MapboxMap.OnMapLongClickListener mapLongClickListener = new MapboxMap.OnMapLongClickListener() { - @Override - public boolean onMapLongClick(@NonNull LatLng point) { - if (customMarker != null) { - // Remove previous added marker - mapboxMap.removeAnnotation(customMarker); - customMarker = null; - } - - // Add marker on long click location with default marker image - customMarker = mapboxMap.addMarker(new MarkerOptions() - .title("Custom Marker") - .snippet(new DecimalFormat("#.#####").format(point.getLatitude()) + ", " - + new DecimalFormat("#.#####").format(point.getLongitude())) - .position(point)); - return true; - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_infowindow); - - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(this); - } - - @Override - public void onMapReady(@NonNull MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; - mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> { - addMarkers(); - addInfoWindowListeners(); - }); - } - - private void addMarkers() { - mapboxMap.addMarker(new MarkerOptions() - .title("Intersection") - .snippet("H St NW with 15th St NW") - .position(new LatLng(38.9002073, -77.03364419))); - - mapboxMap.addMarker(new MarkerOptions().title("Intersection") - .snippet("E St NW with 17th St NW") - .position(new LatLng(38.8954236, -77.0394623))); - - mapboxMap.addMarker(new MarkerOptions().title("The Ellipse").position(new LatLng(38.89393, -77.03654))); - - mapboxMap.addMarker(new MarkerOptions().position(new LatLng(38.89596, -77.03434))); - - mapboxMap.addMarker(new MarkerOptions().snippet("Lafayette Square").position(new LatLng(38.89949, -77.03656))); - - Marker marker = mapboxMap.addMarker(new MarkerOptions() - .title("White House") - .snippet("The official residence and principal workplace of the President of the United States, " - + "located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every" - + "U.S. president since John Adams in 1800.") - .position(new LatLng(38.897705003219784, -77.03655168667463))); - - // open InfoWindow at startup - mapboxMap.selectMarker(marker); - } - - private void addInfoWindowListeners() { - mapboxMap.setOnInfoWindowCloseListener(this); - mapboxMap.addOnMapLongClickListener(mapLongClickListener); - mapboxMap.setOnInfoWindowClickListener(this); - mapboxMap.setOnInfoWindowLongClickListener(this); - } - - private void toggleConcurrentInfoWindow(boolean allowConcurrentInfoWindow) { - mapboxMap.deselectMarkers(); - mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(allowConcurrentInfoWindow); - } - - private void toggleDeselectMarkersOnTap(boolean deselectMarkersOnTap) { - mapboxMap.getUiSettings().setDeselectMarkersOnTap(deselectMarkersOnTap); - } - - @Override - public boolean onInfoWindowClick(@NonNull Marker marker) { - Toast.makeText(getApplicationContext(), "OnClick: " + marker.getTitle(), Toast.LENGTH_LONG).show(); - // returning true will leave the info window open - return false; - } - - @Override - public void onInfoWindowClose(Marker marker) { - Toast.makeText(getApplicationContext(), "OnClose: " + marker.getTitle(), Toast.LENGTH_LONG).show(); - } - - @Override - public void onInfoWindowLongClick(Marker marker) { - Toast.makeText(getApplicationContext(), "OnLongClick: " + marker.getTitle(), Toast.LENGTH_LONG).show(); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (mapboxMap != null) { - mapboxMap.removeOnMapLongClickListener(mapLongClickListener); - } - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_infowindow, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_toggle_concurrent_infowindow: - toggleConcurrentInfoWindow(!item.isChecked()); - item.setChecked(!item.isChecked()); - return true; - case R.id.action_toggle_deselect_markers_on_tap: - toggleDeselectMarkersOnTap(!item.isChecked()); - item.setChecked(!item.isChecked()); - return true; - default: - return super.onOptionsItemSelected(item); - } - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java deleted file mode 100644 index 5140a969d2..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.infowindow; - -import android.graphics.Color; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.widget.TextView; - -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.model.annotations.CityStateMarker; -import com.mapbox.mapboxsdk.testapp.model.annotations.CityStateMarkerOptions; -import com.mapbox.mapboxsdk.testapp.utils.IconUtils; - -/** - * Test activity showcasing using an InfoWindowAdapter to provide a custom InfoWindow content. - */ -public class InfoWindowAdapterActivity extends AppCompatActivity { - - private MapView mapView; - private MapboxMap mapboxMap; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_infowindow_adapter); - - mapView = findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(map -> { - mapboxMap = map; - map.setStyle(Style.MAPBOX_STREETS, style -> { - addMarkers(); - addCustomInfoWindowAdapter(); - }); - }); - } - - private void addMarkers() { - mapboxMap.addMarker(generateCityStateMarker("Andorra", 42.505777, 1.52529, "#F44336")); - mapboxMap.addMarker(generateCityStateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5")); - mapboxMap.addMarker(generateCityStateMarker("Monaco", 43.738418, 7.424616, "#673AB7")); - mapboxMap.addMarker(generateCityStateMarker("Vatican City", 41.902916, 12.453389, "#009688")); - mapboxMap.addMarker(generateCityStateMarker("San Marino", 43.942360, 12.457777, "#795548")); - mapboxMap.addMarker(generateCityStateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722")); - } - - private CityStateMarkerOptions generateCityStateMarker(String title, double lat, double lng, String color) { - CityStateMarkerOptions marker = new CityStateMarkerOptions(); - marker.title(title); - marker.position(new LatLng(lat, lng)); - marker.infoWindowBackground(color); - - Icon icon = IconUtils.drawableToIcon(this, R.drawable.ic_location_city, Color.parseColor(color)); - marker.icon(icon); - return marker; - } - - private void addCustomInfoWindowAdapter() { - mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() { - - private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin); - - @Override - public View getInfoWindow(@NonNull Marker marker) { - TextView textView = new TextView(InfoWindowAdapterActivity.this); - textView.setText(marker.getTitle()); - textView.setTextColor(Color.WHITE); - - if (marker instanceof CityStateMarker) { - CityStateMarker cityStateMarker = (CityStateMarker) marker; - textView.setBackgroundColor(Color.parseColor(cityStateMarker.getInfoWindowBackgroundColor())); - } - - textView.setPadding(tenDp, tenDp, tenDp, tenDp); - return textView; - } - }); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java index 1a9d3d300b..7065caa298 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java @@ -9,20 +9,32 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.FrameLayout; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; +import com.mapbox.geojson.Point; +import com.mapbox.geojson.Polygon; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.style.layers.FillLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.testapp.R; +import java.util.ArrayList; +import java.util.List; + +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOpacity; + /** * Test activity showcasing restricting user gestures to a bounds around Iceland, almost worldview and IDL. */ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements OnMapReadyCallback { + private static final String FILL_SOURCE_ID = "fill_source_id"; + private static final String FILL_LAYER_ID = "fill_layer_id"; + private static final LatLngBounds ICELAND_BOUNDS = new LatLngBounds.Builder() .include(new LatLng(66.852863, -25.985652)) .include(new LatLng(62.985661, -12.626277)) @@ -40,6 +52,7 @@ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements private MapView mapView; private MapboxMap mapboxMap; + private GeoJsonSource geoJsonSource; @Override protected void onCreate(Bundle savedInstanceState) { @@ -54,7 +67,20 @@ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - mapboxMap.setStyle(Style.SATELLITE_STREETS); + + geoJsonSource = new GeoJsonSource(FILL_SOURCE_ID); + FillLayer fillLayer = new FillLayer(FILL_LAYER_ID, FILL_SOURCE_ID) + .withProperties( + fillOpacity(0.25f), + fillColor(Color.RED) + ); + + mapboxMap.setStyle(new Style.Builder() + .fromUrl(Style.SATELLITE_STREETS) + .withSource(geoJsonSource) + .withLayer(fillLayer) + ); + mapboxMap.setMinZoomPreference(2); mapboxMap.getUiSettings().setFlingVelocityAnimationEnabled(false); showCrosshair(); @@ -86,15 +112,20 @@ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements } private void showBoundsArea(LatLngBounds bounds) { - mapboxMap.clear(); - PolygonOptions boundsArea = new PolygonOptions() - .add(bounds.getNorthWest()) - .add(bounds.getNorthEast()) - .add(bounds.getSouthEast()) - .add(bounds.getSouthWest()); - boundsArea.alpha(0.25f); - boundsArea.fillColor(Color.RED); - mapboxMap.addPolygon(boundsArea); + List points = new ArrayList<>(); + points.add(convertToPoint(bounds.getNorthWest())); + points.add(convertToPoint(bounds.getNorthEast())); + points.add(convertToPoint(bounds.getSouthEast())); + points.add(convertToPoint(bounds.getSouthWest())); + points.add(convertToPoint(bounds.getNorthWest())); + + List> polygon = new ArrayList<>(); + polygon.add(points); + geoJsonSource.setGeoJson(Polygon.fromLngLats(polygon)); + } + + private Point convertToPoint(LatLng northWest) { + return Point.fromLngLat(northWest.getLongitude(), northWest.getLatitude()); } private void showCrosshair() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.java index 688ba46f94..85864a368d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.java @@ -5,7 +5,6 @@ import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; @@ -109,23 +108,17 @@ public class MapPaddingActivity extends AppCompatActivity { .build(); mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); - mapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore)); } @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - - case R.id.action_bangalore: - if (mapboxMap != null) { - moveToBangalore(); - } - return true; - - default: - return super.onOptionsItemSelected(item); + if (item.getItemId() == R.id.action_bangalore) { + if (mapboxMap != null) { + moveToBangalore(); + } + return true; } + return super.onOptionsItemSelected(item); } - } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java index d7ceda699e..d11fb84fd1 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java @@ -26,7 +26,6 @@ import timber.log.Timber; public class MapSnapshotterMarkerActivity extends AppCompatActivity implements MapSnapshotter.SnapshotReadyCallback { private MapSnapshotter mapSnapshotter; - private MapSnapshot mapSnapshot; @Override protected void onCreate(Bundle savedInstanceState) { @@ -38,7 +37,6 @@ public class MapSnapshotterMarkerActivity extends AppCompatActivity implements M .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { - //noinspection deprecation container.getViewTreeObserver().removeGlobalOnLayoutListener(this); Timber.i("Starting snapshot"); @@ -65,7 +63,7 @@ public class MapSnapshotterMarkerActivity extends AppCompatActivity implements M @Override public void onSnapshotReady(MapSnapshot snapshot) { Timber.i("Snapshot ready"); - ImageView imageView = (ImageView) findViewById(R.id.snapshot_image); + ImageView imageView = findViewById(R.id.snapshot_image); Bitmap image = addMarker(snapshot); imageView.setImageBitmap(image); imageView.setOnTouchListener((v, event) -> { @@ -80,7 +78,7 @@ public class MapSnapshotterMarkerActivity extends AppCompatActivity implements M private Bitmap addMarker(MapSnapshot snapshot) { Canvas canvas = new Canvas(snapshot.getBitmap()); - Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default, null); + Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon, null); // Dom toren PointF markerLocation = snapshot.pixelForLatLng(new LatLng(52.090649433011315, 5.121310651302338)); canvas.drawBitmap(marker, diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/AnimatedSymbolLayerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/AnimatedSymbolLayerActivity.java new file mode 100644 index 0000000000..7fbdce06b6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/AnimatedSymbolLayerActivity.java @@ -0,0 +1,443 @@ +package com.mapbox.mapboxsdk.testapp.activity.style; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.TypeEvaluator; +import android.animation.ValueAnimator; +import android.graphics.drawable.BitmapDrawable; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.LinearInterpolator; + +import com.google.gson.JsonObject; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.geojson.Point; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.turf.TurfMeasurement; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconAllowOverlap; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconIgnorePlacement; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotate; + +/** + * Test activity showcasing animating a SymbolLayer. + */ +public class AnimatedSymbolLayerActivity extends AppCompatActivity { + + private static final String PASSENGER = "passenger"; + private static final String PASSENGER_LAYER = "passenger-layer"; + private static final String PASSENGER_SOURCE = "passenger-source"; + private static final String TAXI = "taxi"; + private static final String TAXI_LAYER = "taxi-layer"; + private static final String TAXI_SOURCE = "taxi-source"; + private static final String RANDOM_CAR_LAYER = "random-car-layer"; + private static final String RANDOM_CAR_SOURCE = "random-car-source"; + private static final String RANDOM_CAR_IMAGE_ID = "random-car"; + private static final String PROPERTY_BEARING = "bearing"; + private static final String WATERWAY_LAYER_ID = "waterway-label"; + private static final int DURATION_RANDOM_MAX = 1500; + private static final int DURATION_BASE = 3000; + + private final Random random = new Random(); + + private MapView mapView; + private MapboxMap mapboxMap; + private Style style; + + private List randomCars = new ArrayList<>(); + private GeoJsonSource randomCarSource; + private Car taxi; + private GeoJsonSource taxiSource; + private LatLng passenger; + + private List animators = new ArrayList<>(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_animated_marker); + + mapView = findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(map -> { + this.mapboxMap = map; + map.setStyle(Style.MAPBOX_STREETS, style -> { + this.style = style; + setupCars(); + animateRandomRoutes(); + animateTaxi(); + }); + }); + } + + private void setupCars() { + addRandomCars(); + addPassenger(); + addMainCar(); + } + + private void animateRandomRoutes() { + final Car longestDrive = getLongestDrive(); + final Random random = new Random(); + for (final Car car : randomCars) { + final boolean isLongestDrive = longestDrive.equals(car); + ValueAnimator valueAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), car.current, car.next); + valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + + private LatLng latLng; + + @Override + public void onAnimationUpdate(ValueAnimator animation) { + latLng = (LatLng) animation.getAnimatedValue(); + car.current = latLng; + if (isLongestDrive) { + updateRandomCarSource(); + } + } + }); + + if (isLongestDrive) { + valueAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + updateRandomDestinations(); + animateRandomRoutes(); + } + }); + } + + valueAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationStart(Animator animation) { + super.onAnimationStart(animation); + car.feature.properties().addProperty("bearing", Car.getBearing(car.current, car.next)); + } + }); + + int offset = random.nextInt(2) == 0 ? 0 : random.nextInt(1000) + 250; + valueAnimator.setStartDelay(offset); + valueAnimator.setDuration(car.duration - offset); + valueAnimator.setInterpolator(new LinearInterpolator()); + valueAnimator.start(); + + animators.add(valueAnimator); + } + } + + private void animateTaxi() { + ValueAnimator valueAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), taxi.current, taxi.next); + valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + + private LatLng latLng; + + @Override + public void onAnimationUpdate(ValueAnimator animation) { + latLng = (LatLng) animation.getAnimatedValue(); + taxi.current = latLng; + updateTaxiSource(); + } + }); + + valueAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + updatePassenger(); + animateTaxi(); + } + }); + + valueAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationStart(Animator animation) { + super.onAnimationStart(animation); + taxi.feature.properties().addProperty("bearing", Car.getBearing(taxi.current, taxi.next)); + } + }); + + valueAnimator.setDuration((long) (7 * taxi.current.distanceTo(taxi.next))); + valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); + valueAnimator.start(); + + animators.add(valueAnimator); + } + + private void updatePassenger() { + passenger = getLatLngInBounds(); + updatePassengerSource(); + taxi.setNext(passenger); + } + + private void updatePassengerSource() { + GeoJsonSource source = style.getSourceAs(PASSENGER_SOURCE); + FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] { + Feature.fromGeometry( + Point.fromLngLat( + passenger.getLongitude(), + passenger.getLatitude() + ) + ) + }); + source.setGeoJson(featureCollection); + } + + private void updateTaxiSource() { + taxi.updateFeature(); + taxiSource.setGeoJson(taxi.feature); + } + + private void updateRandomDestinations() { + for (Car randomCar : randomCars) { + randomCar.setNext(getLatLngInBounds()); + } + } + + private Car getLongestDrive() { + Car longestDrive = null; + for (Car randomCar : randomCars) { + if (longestDrive == null) { + longestDrive = randomCar; + } else if (longestDrive.duration < randomCar.duration) { + longestDrive = randomCar; + } + } + return longestDrive; + } + + private void updateRandomCarSource() { + for (Car randomCarsRoute : randomCars) { + randomCarsRoute.updateFeature(); + } + randomCarSource.setGeoJson(featuresFromRoutes()); + } + + private FeatureCollection featuresFromRoutes() { + List features = new ArrayList<>(); + for (Car randomCarsRoute : randomCars) { + features.add(randomCarsRoute.feature); + } + return FeatureCollection.fromFeatures(features); + } + + private long getDuration() { + return random.nextInt(DURATION_RANDOM_MAX) + DURATION_BASE; + } + + private void addRandomCars() { + LatLng latLng; + LatLng next; + for (int i = 0; i < 10; i++) { + latLng = getLatLngInBounds(); + next = getLatLngInBounds(); + + JsonObject properties = new JsonObject(); + properties.addProperty(PROPERTY_BEARING, Car.getBearing(latLng, next)); + + Feature feature = Feature.fromGeometry( + Point.fromLngLat( + latLng.getLongitude(), + latLng.getLatitude() + ), properties); + + randomCars.add( + new Car(feature, next, getDuration()) + ); + } + + randomCarSource = new GeoJsonSource(RANDOM_CAR_SOURCE, featuresFromRoutes()); + style.addSource(randomCarSource); + style.addImage(RANDOM_CAR_IMAGE_ID, + ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_car_top)).getBitmap()); + + SymbolLayer symbolLayer = new SymbolLayer(RANDOM_CAR_LAYER, RANDOM_CAR_SOURCE); + symbolLayer.withProperties( + iconImage(RANDOM_CAR_IMAGE_ID), + iconAllowOverlap(true), + iconRotate(get(PROPERTY_BEARING)), + iconIgnorePlacement(true) + ); + + style.addLayerBelow(symbolLayer, WATERWAY_LAYER_ID); + } + + private void addPassenger() { + passenger = getLatLngInBounds(); + FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] { + Feature.fromGeometry( + Point.fromLngLat( + passenger.getLongitude(), + passenger.getLatitude() + ) + ) + }); + + style.addImage(PASSENGER, + ((BitmapDrawable) getResources().getDrawable(R.drawable.icon_burned)).getBitmap()); + + GeoJsonSource geoJsonSource = new GeoJsonSource(PASSENGER_SOURCE, featureCollection); + style.addSource(geoJsonSource); + + SymbolLayer symbolLayer = new SymbolLayer(PASSENGER_LAYER, PASSENGER_SOURCE); + symbolLayer.withProperties( + iconImage(PASSENGER), + iconIgnorePlacement(true), + iconAllowOverlap(true) + ); + style.addLayerBelow(symbolLayer, RANDOM_CAR_LAYER); + } + + private void addMainCar() { + LatLng latLng = getLatLngInBounds(); + JsonObject properties = new JsonObject(); + properties.addProperty(PROPERTY_BEARING, Car.getBearing(latLng, passenger)); + Feature feature = Feature.fromGeometry( + Point.fromLngLat( + latLng.getLongitude(), + latLng.getLatitude()), properties); + FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] {feature}); + + taxi = new Car(feature, passenger, getDuration()); + style.addImage(TAXI, + ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_taxi_top)).getBitmap()); + taxiSource = new GeoJsonSource(TAXI_SOURCE, featureCollection); + style.addSource(taxiSource); + + SymbolLayer symbolLayer = new SymbolLayer(TAXI_LAYER, TAXI_SOURCE); + symbolLayer.withProperties( + iconImage(TAXI), + iconRotate(get(PROPERTY_BEARING)), + iconAllowOverlap(true), + iconIgnorePlacement(true) + + ); + style.addLayer(symbolLayer); + } + + private LatLng getLatLngInBounds() { + LatLngBounds bounds = mapboxMap.getProjection().getVisibleRegion().latLngBounds; + Random generator = new Random(); + double randomLat = bounds.getLatSouth() + generator.nextDouble() + * (bounds.getLatNorth() - bounds.getLatSouth()); + double randomLon = bounds.getLonWest() + generator.nextDouble() + * (bounds.getLonEast() - bounds.getLonWest()); + return new LatLng(randomLat, randomLon); + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + protected void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + for (Animator animator : animators) { + if (animator != null) { + animator.removeAllListeners(); + animator.cancel(); + } + } + + mapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + /** + * Evaluator for LatLng pairs + */ + private static class LatLngEvaluator implements TypeEvaluator { + + private LatLng latLng = new LatLng(); + + @Override + public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { + latLng.setLatitude(startValue.getLatitude() + + ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); + latLng.setLongitude(startValue.getLongitude() + + ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); + return latLng; + } + } + + + private static class Car { + private Feature feature; + private LatLng next; + private LatLng current; + private long duration; + + Car(Feature feature, LatLng next, long duration) { + this.feature = feature; + Point point = ((Point) feature.geometry()); + this.current = new LatLng(point.latitude(), point.longitude()); + this.duration = duration; + this.next = next; + } + + void setNext(LatLng next) { + this.next = next; + } + + void updateFeature() { + feature = Feature.fromGeometry(Point.fromLngLat( + current.getLongitude(), + current.getLatitude()) + ); + feature.properties().addProperty("bearing", getBearing(current, next)); + } + + private static float getBearing(LatLng from, LatLng to) { + return (float) TurfMeasurement.bearing( + Point.fromLngLat(from.getLongitude(), from.getLatitude()), + Point.fromLngLat(to.getLongitude(), to.getLatitude()) + ); + } + } +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DraggableMarkerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DraggableMarkerActivity.kt index 0b784675e9..11234de30a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DraggableMarkerActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DraggableMarkerActivity.kt @@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.testapp.activity.style import android.graphics.PointF import android.os.Bundle import android.support.design.widget.Snackbar +import android.support.v4.content.res.ResourcesCompat import android.support.v7.app.AppCompatActivity import android.view.MotionEvent import android.view.View @@ -11,7 +12,6 @@ import com.mapbox.android.gestures.MoveGestureDetector import com.mapbox.geojson.Feature import com.mapbox.geojson.FeatureCollection import com.mapbox.geojson.Point -import com.mapbox.mapboxsdk.annotations.IconFactory import com.mapbox.mapboxsdk.camera.CameraUpdateFactory import com.mapbox.mapboxsdk.geometry.LatLng import com.mapbox.mapboxsdk.maps.MapView @@ -21,6 +21,7 @@ import com.mapbox.mapboxsdk.style.layers.PropertyFactory.* import com.mapbox.mapboxsdk.style.layers.SymbolLayer import com.mapbox.mapboxsdk.style.sources.GeoJsonSource import com.mapbox.mapboxsdk.testapp.R +import com.mapbox.mapboxsdk.utils.BitmapUtils import kotlinx.android.synthetic.main.activity_draggable_marker.* /** @@ -68,10 +69,13 @@ class DraggableMarkerActivity : AppCompatActivity() { mapView.getMapAsync { mapboxMap -> this.mapboxMap = mapboxMap + val markerDrawable = ResourcesCompat.getDrawable(resources, R.drawable.mapbox_marker_icon, theme) + val markerBitmap = BitmapUtils.getBitmapFromDrawable(markerDrawable) + mapboxMap.setStyle( Style.Builder() .fromUrl(Style.MAPBOX_STREETS) - .withImage(markerImageId, IconFactory.getInstance(this).defaultMarker().bitmap) + .withImage(markerImageId, markerBitmap!!) .withSource(source) .withLayer(layer) ) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CityStateMarker.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CityStateMarker.java deleted file mode 100644 index 15b2f0b127..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CityStateMarker.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.model.annotations; - -import com.mapbox.mapboxsdk.annotations.Marker; - -public class CityStateMarker extends Marker { - - private String infoWindowBackgroundColor; - - public CityStateMarker(CityStateMarkerOptions cityStateOptions, String color) { - super(cityStateOptions); - infoWindowBackgroundColor = color; - } - - public String getInfoWindowBackgroundColor() { - return infoWindowBackgroundColor; - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CityStateMarkerOptions.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CityStateMarkerOptions.java deleted file mode 100644 index 874c644af7..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CityStateMarkerOptions.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.model.annotations; - -import android.graphics.Bitmap; -import android.os.Parcel; -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.IconFactory; -import com.mapbox.mapboxsdk.geometry.LatLng; - -public class CityStateMarkerOptions extends BaseMarkerOptions { - - private String infoWindowBackgroundColor; - - public CityStateMarkerOptions infoWindowBackground(String color) { - infoWindowBackgroundColor = color; - return getThis(); - } - - public CityStateMarkerOptions() { - } - - private CityStateMarkerOptions(Parcel in) { - position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); - snippet(in.readString()); - String iconId = in.readString(); - Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); - Icon icon = IconFactory.recreate(iconId, iconBitmap); - icon(icon); - title(in.readString()); - } - - @Override - public CityStateMarkerOptions getThis() { - return this; - } - - @Override - public CityStateMarker getMarker() { - return new CityStateMarker(this, infoWindowBackgroundColor); - } - - public static final Parcelable.Creator CREATOR - = new Parcelable.Creator() { - public CityStateMarkerOptions createFromParcel(Parcel in) { - return new CityStateMarkerOptions(in); - } - - public CityStateMarkerOptions[] newArray(int size) { - return new CityStateMarkerOptions[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeParcelable(position, flags); - out.writeString(snippet); - out.writeString(icon.getId()); - out.writeParcelable(icon.getBitmap(), flags); - out.writeString(title); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarker.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarker.java deleted file mode 100644 index 6b172ef83f..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarker.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.model.annotations; - -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; - -public class CountryMarker extends Marker { - - private String abbrevName; - private int flagRes; - - public CountryMarker(BaseMarkerOptions baseMarkerOptions, String abbrevName, int iconRes) { - super(baseMarkerOptions); - this.abbrevName = abbrevName; - this.flagRes = iconRes; - } - - public String getAbbrevName() { - return abbrevName; - } - - public int getFlagRes() { - return flagRes; - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerOptions.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerOptions.java deleted file mode 100644 index 0a64359979..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerOptions.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.model.annotations; - -import android.graphics.Bitmap; -import android.os.Parcel; -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.IconFactory; -import com.mapbox.mapboxsdk.geometry.LatLng; - -public class CountryMarkerOptions extends BaseMarkerOptions { - - private String abbrevName; - private int flagRes; - - public CountryMarkerOptions abbrevName(String name) { - abbrevName = name; - return getThis(); - } - - public CountryMarkerOptions flagRes(int imageRes) { - flagRes = imageRes; - return getThis(); - } - - public CountryMarkerOptions() { - } - - private CountryMarkerOptions(Parcel in) { - position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); - snippet(in.readString()); - String iconId = in.readString(); - Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); - Icon icon = IconFactory.recreate(iconId, iconBitmap); - icon(icon); - title(in.readString()); - } - - @Override - public CountryMarkerOptions getThis() { - return this; - } - - @Override - public CountryMarker getMarker() { - return new CountryMarker(this, abbrevName, flagRes); - } - - public static final Parcelable.Creator CREATOR - = new Parcelable.Creator() { - public CountryMarkerOptions createFromParcel(Parcel in) { - return new CountryMarkerOptions(in); - } - - public CountryMarkerOptions[] newArray(int size) { - return new CountryMarkerOptions[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeParcelable(position, flags); - out.writeString(snippet); - out.writeString(icon.getId()); - out.writeParcelable(icon.getBitmap(), flags); - out.writeString(title); - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IconUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IconUtils.java deleted file mode 100644 index b6768a91a3..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IconUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.DrawableRes; -import android.support.annotation.NonNull; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v4.graphics.drawable.DrawableCompat; - -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.IconFactory; - -public class IconUtils { - - /** - * Demonstrates converting any Drawable to an Icon, for use as a marker icon. - */ - public static Icon drawableToIcon(@NonNull Context context, @DrawableRes int id, @ColorInt int colorRes) { - Drawable vectorDrawable = ResourcesCompat.getDrawable(context.getResources(), id, context.getTheme()); - Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), - vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - DrawableCompat.setTint(vectorDrawable, colorRes); - vectorDrawable.draw(canvas); - return IconFactory.getInstance(context).fromBitmap(bitmap); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-hdpi/mapbox_marker_icon.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-hdpi/mapbox_marker_icon.png new file mode 100644 index 0000000000..651482f3ee Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-hdpi/mapbox_marker_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-mdpi/mapbox_marker_icon.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-mdpi/mapbox_marker_icon.png new file mode 100644 index 0000000000..63cb7b5f4b Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-mdpi/mapbox_marker_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xhdpi/mapbox_marker_icon.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xhdpi/mapbox_marker_icon.png new file mode 100644 index 0000000000..175f88ff88 Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xhdpi/mapbox_marker_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/mapbox_marker_icon.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/mapbox_marker_icon.png new file mode 100644 index 0000000000..be782e1d4b Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/mapbox_marker_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/mapbox_marker_icon.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/mapbox_marker_icon.png new file mode 100644 index 0000000000..fe1c486518 Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/mapbox_marker_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml index 94c805f357..17f323cae0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml @@ -2,7 +2,6 @@ category _Basic - Annotation Camera Custom Layer Fragment diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml index be8dae57a0..9b36a7738e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml @@ -1,20 +1,15 @@ Overlay a custom native layer on the map - Learn how to create a custom InfoWindow CameraPosition capabilities Showcase MapFragment Showcase SupportMapFragment Showcase using a Map Fragment with a fragment backstack Activity with multiple maps on screen - Add marker to map on long press Different types of zoom methods Configure a max and min zoomlevel - Learn how to handle the InfoWindow - Add Markers In Bulk to a Map Showcase the different animation types Center the camera around a bounds - Update position and icon Map Padding example Debug Mode Offline Map example @@ -23,12 +18,9 @@ Delete region example Change resources cache path example Animate the position change of a symbol layer - Add a polyline to a map - Add a polygon to a map Scroll with pixels in x,y direction Example to make a snapshot of the map 2 maps in a view hierarchy - Learn how to create a dynamic custom InfoWindow Use SupportMapFragments in a ViewPager Adopt the map style on the fly Show a gradient line layer from a geojson source @@ -83,5 +75,5 @@ Show a GLSurfaceView MapView as a recyclerView item Show a MapView inside a viewpager inside a recyclerView Show the use PerformanceEvent for performance measurements - Use TurfTransformation#circle() to show a Cirlce expressed in physical units + Use TurfTransformation#circle() to show a Circle expressed in physical units diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml index 027198c71b..8ffa91ad30 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml @@ -4,16 +4,8 @@ Map Fragment Backstack Map Fragment Multiple Maps on Screen - Add Markers In Bulk Animated SymbolLayer - Dynamic Marker - Polyline - Polygon - Press Map For Marker Zoom function with SymbolLayer - Standard InfoWindow - Custom InfoWindow - Custom Dynamic InfoWindow Animation Types Zoom Methods LatLngBounds Method diff --git a/platform/android/core-files.json b/platform/android/core-files.json index ba56695bdd..e8bc6f2cba 100644 --- a/platform/android/core-files.json +++ b/platform/android/core-files.json @@ -4,9 +4,6 @@ "platform/android/src/main.cpp", "platform/android/src/android_renderer_backend.cpp", "platform/android/src/android_renderer_frontend.cpp", - "platform/android/src/annotation/marker.cpp", - "platform/android/src/annotation/polygon.cpp", - "platform/android/src/annotation/polyline.cpp", "platform/android/src/async_task.cpp", "platform/android/src/attach_env.cpp", "platform/android/src/bitmap.cpp", @@ -104,10 +101,6 @@ "private_headers": { "android_renderer_backend.hpp": "platform/android/src/android_renderer_backend.hpp", "android_renderer_frontend.hpp": "platform/android/src/android_renderer_frontend.hpp", - "annotation/marker.hpp": "platform/android/src/annotation/marker.hpp", - "annotation/multi_point.hpp": "platform/android/src/annotation/multi_point.hpp", - "annotation/polygon.hpp": "platform/android/src/annotation/polygon.hpp", - "annotation/polyline.hpp": "platform/android/src/annotation/polyline.hpp", "attach_env.hpp": "platform/android/src/attach_env.hpp", "bitmap.hpp": "platform/android/src/bitmap.hpp", "bitmap_factory.hpp": "platform/android/src/bitmap_factory.hpp", diff --git a/platform/android/src/annotation/marker.cpp b/platform/android/src/annotation/marker.cpp deleted file mode 100644 index 899f87a74f..0000000000 --- a/platform/android/src/annotation/marker.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "marker.hpp" - -namespace mbgl { -namespace android { - -mbgl::Point Marker::getPosition(jni::JNIEnv& env, const jni::Object& marker) { - static auto& javaClass = jni::Class::Singleton(env); - static auto positionField = javaClass.GetField>(env, "position"); - return LatLng::getGeometry(env, marker.Get(env, positionField)); -} - -std::string Marker::getIconId(jni::JNIEnv& env, const jni::Object& marker) { - static auto& javaClass = jni::Class::Singleton(env); - static auto iconIdField = javaClass.GetField(env, "iconId"); - return jni::Make(env, marker.Get(env, iconIdField)); -} - -void Marker::registerNative(jni::JNIEnv& env) { - jni::Class::Singleton(env); -} - -} // namespace android -} // namespace mbgl \ No newline at end of file diff --git a/platform/android/src/annotation/marker.hpp b/platform/android/src/annotation/marker.hpp deleted file mode 100644 index b38a25b4fb..0000000000 --- a/platform/android/src/annotation/marker.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include "../geometry/lat_lng.hpp" - -namespace mbgl { -namespace android { - -class Marker : private mbgl::util::noncopyable { -public: - - static constexpr auto Name() { return "com/mapbox/mapboxsdk/annotations/Marker"; }; - - static mbgl::Point getPosition(jni::JNIEnv&, const jni::Object&); - - static std::string getIconId(jni::JNIEnv&, const jni::Object&); - - static void registerNative(jni::JNIEnv&); - -}; - - -} // namespace android -} // namespace mbgl \ No newline at end of file diff --git a/platform/android/src/annotation/multi_point.hpp b/platform/android/src/annotation/multi_point.hpp deleted file mode 100644 index 20f1b3eaf2..0000000000 --- a/platform/android/src/annotation/multi_point.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#include "../geometry/lat_lng.hpp" -#include "../java/util.hpp" - -namespace mbgl { -namespace android { - -class MultiPoint : protected mbgl::util::noncopyable { - -protected: - - template - static Geometry toGeometry(JNIEnv& env, const jni::Object& pointsList) { - auto jarray = java::util::List::toArray(env, pointsList); - - std::size_t size = jarray.Length(env); - - Geometry geometry; - geometry.reserve(size); - - for (std::size_t i = 0; i < size; i++) { - geometry.push_back(LatLng::getGeometry(env, jarray.Get(env, i))); - } - - return geometry; - } -}; - -} // namespace android -} // namespace mbgl \ No newline at end of file diff --git a/platform/android/src/annotation/polygon.cpp b/platform/android/src/annotation/polygon.cpp deleted file mode 100644 index f22cffb100..0000000000 --- a/platform/android/src/annotation/polygon.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "polygon.hpp" - -#include "../conversion/color.hpp" - -namespace mbgl { -namespace android { - -mbgl::FillAnnotation Polygon::toAnnotation(jni::JNIEnv& env, const jni::Object& polygon) { - static auto& javaClass = jni::Class::Singleton(env); - static auto points = javaClass.GetField>(env, "points"); - static auto holes = javaClass.GetField>(env, "holes"); - static auto alpha = javaClass.GetField(env, "alpha"); - static auto fillColor = javaClass.GetField(env, "fillColor"); - static auto strokeColor = javaClass.GetField(env, "strokeColor"); - - mbgl::Polygon geometry { - MultiPoint::toGeometry>(env, polygon.Get(env, points)) - }; - - auto jHoleListsArray = java::util::List::toArray(env, polygon.Get(env, holes)); - - std::size_t jHoleListsSize = jHoleListsArray.Length(env); - for (std::size_t i = 0; i < jHoleListsSize; i++) { - geometry.push_back(MultiPoint::toGeometry>(env, jHoleListsArray.Get(env, i))); - } - - mbgl::FillAnnotation annotation { geometry }; - annotation.opacity = polygon.Get(env, alpha); - annotation.color = *conversion::convert(env, polygon.Get(env, fillColor)); - annotation.outlineColor = *conversion::convert(env, polygon.Get(env, strokeColor)); - - return annotation; -} - -void Polygon::registerNative(jni::JNIEnv& env) { - jni::Class::Singleton(env); -} - -} // namespace android -} // namespace mbgl \ No newline at end of file diff --git a/platform/android/src/annotation/polygon.hpp b/platform/android/src/annotation/polygon.hpp deleted file mode 100644 index bc21878ef3..0000000000 --- a/platform/android/src/annotation/polygon.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -#include "multi_point.hpp" - -namespace mbgl { -namespace android { - -class Polygon : private MultiPoint { -public: - static constexpr auto Name() { return "com/mapbox/mapboxsdk/annotations/Polygon"; }; - - static mbgl::FillAnnotation toAnnotation(jni::JNIEnv&, const jni::Object&); - - static void registerNative(jni::JNIEnv&); -}; - - -} // namespace android -} // namespace mbgl \ No newline at end of file diff --git a/platform/android/src/annotation/polyline.cpp b/platform/android/src/annotation/polyline.cpp deleted file mode 100644 index d6161e856e..0000000000 --- a/platform/android/src/annotation/polyline.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "polyline.hpp" - -#include "../conversion/color.hpp" - -namespace mbgl { -namespace android { - -mbgl::LineAnnotation Polyline::toAnnotation(jni::JNIEnv& env, const jni::Object& polyline) { - static auto& javaClass = jni::Class::Singleton(env); - static auto points = javaClass.GetField>(env, "points"); - static auto alpha = javaClass.GetField(env, "alpha"); - static auto color = javaClass.GetField(env, "color"); - static auto width = javaClass.GetField(env, "width"); - - mbgl::LineAnnotation annotation { - MultiPoint::toGeometry>(env, polyline.Get(env, points)) - }; - - annotation.opacity = polyline.Get(env, alpha); - annotation.color = *conversion::convert(env, polyline.Get(env, color)); - annotation.width = polyline.Get(env, width); - - return annotation; -} - -void Polyline::registerNative(jni::JNIEnv& env) { - jni::Class::Singleton(env); -} - -} // namespace android -} // namespace mbgl \ No newline at end of file diff --git a/platform/android/src/annotation/polyline.hpp b/platform/android/src/annotation/polyline.hpp deleted file mode 100644 index 6178e98cfc..0000000000 --- a/platform/android/src/annotation/polyline.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -#include "multi_point.hpp" - -namespace mbgl { -namespace android { - -class Polyline : private MultiPoint { -public: - static constexpr auto Name() { return "com/mapbox/mapboxsdk/annotations/Polyline"; }; - - static mbgl::LineAnnotation toAnnotation(jni::JNIEnv&, const jni::Object&); - - static void registerNative(jni::JNIEnv&); -}; - - -} // namespace android -} // namespace mbgl \ No newline at end of file diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 410c962384..f8404b6880 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -2,9 +2,6 @@ #include -#include "annotation/marker.hpp" -#include "annotation/polygon.hpp" -#include "annotation/polyline.hpp" #include "bitmap.hpp" #include "bitmap_factory.hpp" #include "connectivity_listener.hpp" @@ -145,11 +142,6 @@ void registerNatives(JavaVM *vm) { gson::JsonObject::registerNative(env); gson::JsonPrimitive::registerNative(env); - //Annotation - Marker::registerNative(env); - Polygon::registerNative(env); - Polyline::registerNative(env); - // Map MapRenderer::registerNative(env); MapRendererRunnable::registerNative(env); diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index ae53bcc802..43993f7add 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -535,37 +535,6 @@ jni::Local> NativeMapView::getCameraPosition(jni::JN return CameraPosition::New(env, map->getCameraOptions(insets)); } -void NativeMapView::updateMarker(jni::JNIEnv& env, jni::jlong markerId, jni::jdouble lat, jni::jdouble lon, const jni::String& jid) { - if (markerId == -1) { - return; - } - - std::string iconId = jni::Make(env, jid); - // Because Java only has int, not unsigned int, we need to bump the annotation id up to a long. - map->updateAnnotation(markerId, mbgl::SymbolAnnotation { mbgl::Point(lon, lat), iconId }); -} - -jni::Local> NativeMapView::addMarkers(jni::JNIEnv& env, const jni::Array>& jmarkers) { - jni::NullCheck(env, &jmarkers); - std::size_t len = jmarkers.Length(env); - - std::vector ids; - ids.reserve(len); - - for (std::size_t i = 0; i < len; i++) { - auto marker = jmarkers.Get(env, i); - ids.push_back(map->addAnnotation(mbgl::SymbolAnnotation { - Marker::getPosition(env, marker), - Marker::getIconId(env, marker) - })); - } - - auto result = jni::Array::New(env, len); - result.SetRegion>(env, 0, ids); - - return result; -} - void NativeMapView::onLowMemory(JNIEnv&) { rendererFrontend->reduceMemoryUse(); } @@ -612,92 +581,6 @@ jni::Local> NativeMapView::latLngForPixel(JNIEnv& env, jfloa return LatLng::New(env, map->latLngForPixel(mbgl::ScreenCoordinate(x, y))); } -jni::Local> NativeMapView::addPolylines(JNIEnv& env, const jni::Array>& polylines) { - NullCheck(env, &polylines); - std::size_t len = polylines.Length(env); - - std::vector ids; - ids.reserve(len); - - for (std::size_t i = 0; i < len; i++) { - mbgl::LineAnnotation annotation = Polyline::toAnnotation(env, polylines.Get(env, i)); - ids.push_back(map->addAnnotation(annotation)); - } - - auto result = jni::Array::New(env, len); - result.SetRegion>(env, 0, ids); - - return result; -} - - -jni::Local> NativeMapView::addPolygons(JNIEnv& env, const jni::Array>& polygons) { - NullCheck(env, &polygons); - std::size_t len = polygons.Length(env); - - std::vector ids; - ids.reserve(len); - - for (std::size_t i = 0; i < len; i++) { - mbgl::FillAnnotation annotation = Polygon::toAnnotation(env, polygons.Get(env, i)); - ids.push_back(map->addAnnotation(annotation)); - } - - auto result = jni::Array::New(env, len); - result.SetRegion>(env, 0, ids); - - return result; -} - -void NativeMapView::updatePolyline(JNIEnv& env, jlong polylineId, const jni::Object& polyline) { - mbgl::LineAnnotation annotation = Polyline::toAnnotation(env, polyline); - map->updateAnnotation(polylineId, annotation); -} - -void NativeMapView::updatePolygon(JNIEnv& env, jlong polygonId, const jni::Object& polygon) { - mbgl::FillAnnotation annotation = Polygon::toAnnotation(env, polygon); - map->updateAnnotation(polygonId, annotation); -} - -void NativeMapView::removeAnnotations(JNIEnv& env, const jni::Array& ids) { - NullCheck(env, &ids); - std::size_t len = ids.Length(env); - auto elements = jni::GetArrayElements(env, *ids); - jlong* jids = std::get<0>(elements).get(); - - for (std::size_t i = 0; i < len; i++) { - if(jids[i] == -1L) { - continue; - } - map->removeAnnotation(jids[i]); - } -} - -void NativeMapView::addAnnotationIcon(JNIEnv& env, const jni::String& symbol, jint w, jint h, jfloat scale, const jni::Array& jpixels) { - const std::string symbolName = jni::Make(env, symbol); - - NullCheck(env, &jpixels); - std::size_t size = jpixels.Length(env); - - mbgl::PremultipliedImage premultipliedImage({ static_cast(w), static_cast(h) }); - if (premultipliedImage.bytes() != uint32_t(size)) { - throw mbgl::util::SpriteImageException("Sprite image pixel count mismatch"); - } - - jni::GetArrayRegion(env, *jpixels, 0, size, reinterpret_cast(premultipliedImage.data.get())); - map->addAnnotationImage(std::make_unique( - symbolName, std::move(premultipliedImage), float(scale))); -} - -void NativeMapView::removeAnnotationIcon(JNIEnv& env, const jni::String& symbol) { - const std::string symbolName = jni::Make(env, symbol); - map->removeAnnotationImage(symbolName); -} - -jdouble NativeMapView::getTopOffsetPixelsForAnnotationSymbol(JNIEnv& env, const jni::String& symbolName) { - return map->getTopOffsetPixelsForAnnotationImage(jni::Make(env, symbolName)); -} - jni::Local> NativeMapView::getTransitionOptions(JNIEnv& env) { const auto transitionOptions = map->getStyle().getTransitionOptions(); const auto duration = std::chrono::duration_cast(transitionOptions.duration.value_or(mbgl::Duration::zero())).count(); @@ -715,47 +598,6 @@ void NativeMapView::setTransitionOptions(JNIEnv& env, const jni::ObjectgetStyle().setTransitionOptions(transitionOptions); } -jni::Local> NativeMapView::queryPointAnnotations(JNIEnv& env, const jni::Object& rect) { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - // Convert input - mbgl::ScreenBox box = { - { RectF::getLeft(env, rect), RectF::getTop(env, rect) }, - { RectF::getRight(env, rect), RectF::getBottom(env, rect) }, - }; - - // Assume only points for now - mbgl::AnnotationIDs ids = rendererFrontend->queryPointAnnotations(box); - - // Convert result - std::vector longIds(ids.begin(), ids.end()); - auto result = jni::Array::New(env, ids.size()); - result.SetRegion>(env, 0, longIds); - - return result; -} - -jni::Local> NativeMapView::queryShapeAnnotations(JNIEnv& env, const jni::Object& rect) { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - // Convert input - mbgl::ScreenBox box = { - {RectF::getLeft(env, rect), RectF::getTop(env, rect)}, - {RectF::getRight(env, rect), RectF::getBottom(env, rect)}, - }; - - mbgl::AnnotationIDs ids = rendererFrontend->queryShapeAnnotations(box); - - // Convert result - std::vector longIds(ids.begin(), ids.end()); - auto result = jni::Array::New(env, ids.size()); - result.SetRegion>(env, 0, longIds); - - return result; -} - jni::Local>> NativeMapView::queryRenderedFeaturesForPoint(JNIEnv& env, jni::jfloat x, jni::jfloat y, const jni::Array& layerIds, const jni::Array>& jfilter) { @@ -1086,8 +928,6 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::getContentPadding, "nativeGetContentPadding"), METHOD(&NativeMapView::scheduleSnapshot, "nativeTakeSnapshot"), METHOD(&NativeMapView::getCameraPosition, "nativeGetCameraPosition"), - METHOD(&NativeMapView::updateMarker, "nativeUpdateMarker"), - METHOD(&NativeMapView::addMarkers, "nativeAddMarkers"), METHOD(&NativeMapView::setDebug, "nativeSetDebug"), METHOD(&NativeMapView::cycleDebugOptions, "nativeCycleDebugOptions"), METHOD(&NativeMapView::getDebug, "nativeGetDebug"), @@ -1098,18 +938,8 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::pixelForLatLng, "nativePixelForLatLng"), METHOD(&NativeMapView::latLngForProjectedMeters, "nativeLatLngForProjectedMeters"), METHOD(&NativeMapView::latLngForPixel, "nativeLatLngForPixel"), - METHOD(&NativeMapView::addPolylines, "nativeAddPolylines"), - METHOD(&NativeMapView::addPolygons, "nativeAddPolygons"), - METHOD(&NativeMapView::updatePolyline, "nativeUpdatePolyline"), - METHOD(&NativeMapView::updatePolygon, "nativeUpdatePolygon"), - METHOD(&NativeMapView::removeAnnotations, "nativeRemoveAnnotations"), - METHOD(&NativeMapView::addAnnotationIcon, "nativeAddAnnotationIcon"), - METHOD(&NativeMapView::removeAnnotationIcon, "nativeRemoveAnnotationIcon"), - METHOD(&NativeMapView::getTopOffsetPixelsForAnnotationSymbol, "nativeGetTopOffsetPixelsForAnnotationSymbol"), METHOD(&NativeMapView::getTransitionOptions, "nativeGetTransitionOptions"), METHOD(&NativeMapView::setTransitionOptions, "nativeSetTransitionOptions"), - METHOD(&NativeMapView::queryPointAnnotations, "nativeQueryPointAnnotations"), - METHOD(&NativeMapView::queryShapeAnnotations, "nativeQueryShapeAnnotations"), METHOD(&NativeMapView::queryRenderedFeaturesForPoint, "nativeQueryRenderedFeaturesForPoint"), METHOD(&NativeMapView::queryRenderedFeaturesForBox, "nativeQueryRenderedFeaturesForBox"), METHOD(&NativeMapView::getLight, "nativeGetLight"), diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index 9e6ad73dd7..99635e6edf 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -7,9 +7,6 @@ #include #include -#include "annotation/marker.hpp" -#include "annotation/polygon.hpp" -#include "annotation/polyline.hpp" #include "graphics/pointf.hpp" #include "graphics/rectf.hpp" #include "geojson/feature.hpp" @@ -146,10 +143,6 @@ public: jni::Local> getCameraPosition(jni::JNIEnv&); - void updateMarker(jni::JNIEnv&, jni::jlong, jni::jdouble, jni::jdouble, const jni::String&); - - jni::Local> addMarkers(jni::JNIEnv&, const jni::Array>&); - void onLowMemory(JNIEnv& env); void setDebug(JNIEnv&, jni::jboolean); @@ -170,30 +163,10 @@ public: jni::Local> latLngForPixel(JNIEnv&, jfloat, jfloat); - jni::Local> addPolylines(JNIEnv&, const jni::Array>&); - - jni::Local> addPolygons(JNIEnv&, const jni::Array>&); - - void updatePolyline(JNIEnv&, jlong, const jni::Object&); - - void updatePolygon(JNIEnv&, jlong, const jni::Object&); - - void removeAnnotations(JNIEnv&, const jni::Array&); - - void addAnnotationIcon(JNIEnv&, const jni::String&, jint, jint, jfloat, const jni::Array&); - - void removeAnnotationIcon(JNIEnv&, const jni::String&); - - jni::jdouble getTopOffsetPixelsForAnnotationSymbol(JNIEnv&, const jni::String&); - jni::Local> getTransitionOptions(JNIEnv&); void setTransitionOptions(JNIEnv&, const jni::Object&); - jni::Local> queryPointAnnotations(JNIEnv&, const jni::Object&); - - jni::Local> queryShapeAnnotations(JNIEnv&, const jni::Object&); - jni::Local>> queryRenderedFeaturesForPoint(JNIEnv&, jni::jfloat, jni::jfloat, const jni::Array&, const jni::Array>& jfilter); -- cgit v1.2.1