summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukasz.paczos@mapbox.com>2019-05-29 19:46:15 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-06-04 17:49:08 +0200
commit7b5d6c15ac235d3c7bdefdc35415ab7496bc7196 (patch)
tree5ff7223886c646200e2835d5795a95322d7ce2b8
parentfd33e066a4440b74328ff4b7139c297ae302c66b (diff)
downloadqtlocation-mapboxgl-7b5d6c15ac235d3c7bdefdc35415ab7496bc7196.tar.gz
[android] copy features array before passing them to core
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java19
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/GeoJsonSourceTests.java18
2 files changed, 31 insertions, 6 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
index f2de07bdd0..407ec4aa36 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
@@ -285,14 +285,21 @@ public class GeoJsonSource extends Source {
* Updates the GeoJson. The update is performed asynchronously,
* so the data won't be immediately visible or available to query when this method returns.
*
- * @param features the GeoJSON FeatureCollection
+ * @param featureCollection the GeoJSON FeatureCollection
*/
- public void setGeoJson(FeatureCollection features) {
+ public void setGeoJson(FeatureCollection featureCollection) {
if (detached) {
return;
}
checkThread();
- nativeSetFeatureCollection(features);
+
+ List<Feature> features = featureCollection.features();
+ if (features != null) {
+ List<Feature> featuresCopy = new ArrayList<>(features);
+ nativeSetFeatureCollection(FeatureCollection.fromFeatures(featuresCopy));
+ } else {
+ nativeSetFeatureCollection(featureCollection);
+ }
}
/**
@@ -445,7 +452,7 @@ public class GeoJsonSource extends Source {
* </p>
*
* @param cluster cluster from which to retrieve leaves from
- * @param limit limit is the number of points to return
+ * @param limit limit is the number of points to return
* @param offset offset is the amount of points to skip (for pagination)
* @return a list of features for the underlying leaves
*/
@@ -497,10 +504,10 @@ public class GeoJsonSource extends Source {
private native Feature[] querySourceFeatures(Object[] filter);
@Keep
- private native Feature[] nativeGetClusterChildren(Feature feature);
+ private native Feature[] nativeGetClusterChildren(Feature feature);
@Keep
- private native Feature[] nativeGetClusterLeaves(Feature feature, long limit, long offset);
+ private native Feature[] nativeGetClusterLeaves(Feature feature, long limit, long offset);
@Keep
private native int nativeGetClusterExpansionZoom(Feature feature);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/GeoJsonSourceTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/GeoJsonSourceTests.java
index 99e0ae4016..61086e1344 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/GeoJsonSourceTests.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/GeoJsonSourceTests.java
@@ -23,6 +23,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import timber.log.Timber;
@@ -102,6 +104,22 @@ public class GeoJsonSourceTests extends EspressoTest {
}
@Test
+ public void testClearCollectionDuringConversion() {
+ // https://github.com/mapbox/mapbox-gl-native/issues/14565
+ validateTestSetup();
+ MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
+ for (int j = 0; j < 1000; j++) {
+ List<Feature> features = new ArrayList<>();
+ for (int i = 0; i < 100; i++) {
+ features.add(Feature.fromGeometry(Point.fromLngLat(0, 0)));
+ }
+ mapboxMap.getStyle().addSource(new GeoJsonSource("source" + j, FeatureCollection.fromFeatures(features)));
+ features.clear();
+ }
+ });
+ }
+
+ @Test
public void testPointFeature() {
testFeatureFromResource(R.raw.test_point_feature);
}