summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorOsana Babayan <32496536+osana@users.noreply.github.com>2018-03-06 09:43:01 -0500
committerGitHub <noreply@github.com>2018-03-06 09:43:01 -0500
commit19d08db2e45d14dc02be59b2343c56cb9dd0cc3c (patch)
treefe40ae0ddb58db0e702dc0be1059271394b2bd6a /platform
parent38fd733c9cbd06edd03efc36eb50d3679a47a1dd (diff)
downloadqtlocation-mapboxgl-19d08db2e45d14dc02be59b2343c56cb9dd0cc3c.tar.gz
[android] take advantage of MAS 3.0-beta.3 changes
fromLngLats() take double arrays are called from Java (not the List<Point> ones)
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.java39
-rw-r--r--platform/android/gradle/dependencies.gradle2
-rw-r--r--platform/android/src/geojson/conversion/geometry.hpp112
3 files changed, 73 insertions, 80 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.java
index 15d7024abf..b7f6b10b0d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.java
@@ -4,6 +4,7 @@ import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
+import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -14,6 +15,9 @@ import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.geojson.Polygon;
+import java.util.Arrays;
+import java.util.List;
+
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionHeight;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionOpacity;
@@ -35,30 +39,17 @@ public class FillExtrusionActivity extends AppCompatActivity {
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(map -> {
mapboxMap = map;
- Polygon domTower = Polygon.fromLngLats(new double[][][] {
- new double[][] {
- new double[] {
- 5.12112557888031,
- 52.09071040847704
- },
- new double[] {
- 5.121227502822875,
- 52.09053901776669
- },
- new double[] {
- 5.121484994888306,
- 52.090601641371805
- },
- new double[] {
- 5.1213884353637695,
- 52.090766439912635
- },
- new double[] {
- 5.12112557888031,
- 52.09071040847704
- }
- }
- });
+ List<List<Point>> lngLats = Arrays.asList(
+ Arrays.asList(
+ Point.fromLngLat(5.12112557888031, 52.09071040847704),
+ Point.fromLngLat(5.121227502822875, 52.09053901776669),
+ Point.fromLngLat(5.121484994888306, 52.090601641371805),
+ Point.fromLngLat(5.1213884353637695, 52.090766439912635),
+ Point.fromLngLat(5.12112557888031, 52.09071040847704)
+ )
+ );
+
+ Polygon domTower = Polygon.fromLngLats(lngLats);
GeoJsonSource source = new GeoJsonSource("extrusion-source", domTower);
map.addSource(source);
diff --git a/platform/android/gradle/dependencies.gradle b/platform/android/gradle/dependencies.gradle
index e696bc3ee3..90688f0058 100644
--- a/platform/android/gradle/dependencies.gradle
+++ b/platform/android/gradle/dependencies.gradle
@@ -8,7 +8,7 @@ ext {
]
versions = [
- mapboxServices : '3.0.0-beta.2',
+ mapboxServices : '3.0.0-beta.3',
mapboxTelemetry: '3.0.0-beta.1',
mapboxGestures : '0.1.0-20180228.152340-13',
supportLib : '25.4.0',
diff --git a/platform/android/src/geojson/conversion/geometry.hpp b/platform/android/src/geojson/conversion/geometry.hpp
index 5d2aab4c2d..48b9089692 100644
--- a/platform/android/src/geojson/conversion/geometry.hpp
+++ b/platform/android/src/geojson/conversion/geometry.hpp
@@ -31,74 +31,76 @@ public:
}
/**
- * static LineString fromLngLats(List<Point> points)
+ * static LineString fromLngLats(double [][])
*/
jni::jobject* operator()(const mapbox::geometry::line_string<T> &geometry) const {
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/geojson/LineString")).release();
- static jni::jmethodID* fromLngLats = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "(Ljava/util/List;)Lcom/mapbox/geojson/LineString;");
+ static jni::jmethodID* fromLngLats = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "([[D)Lcom/mapbox/geojson/LineString;");
// Create
- jni::LocalObject<jni::jobject> listOfPoints = jni::NewLocalObject(env, toGeoJsonListOfPoints(env, geometry));
- return reinterpret_cast<jni::jobject*>(jni::CallStaticMethod<jni::jobject*>(env, *javaClass, *fromLngLats, listOfPoints.get()));
+ jni::LocalObject<jni::jarray<jni::jobject>> lngLatsArray =
+ jni::NewLocalObject(env, toLngLatArray(env, geometry));
+ return reinterpret_cast<jni::jobject*>(jni::CallStaticMethod<jni::jobject*>(env, *javaClass, *fromLngLats, lngLatsArray.get()));
}
/**
- * static MultiPoint fromLngLats(List<Point> points)
+ * static MultiPoint fromLngLats(double [][])
*/
jni::jobject* operator()(const mapbox::geometry::multi_point<T> &geometry) const {
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/geojson/MultiPoint")).release();
- static jni::jmethodID* fromLngLats = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "(Ljava/util/List;)Lcom/mapbox/geojson/MultiPoint;");
+ static jni::jmethodID* fromLngLats = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "([[D)Lcom/mapbox/geojson/MultiPoint;");
// Create
- jni::LocalObject<jni::jobject> coordinates = jni::NewLocalObject(env, toGeoJsonListOfPoints(env, geometry));
- return reinterpret_cast<jni::jobject*>(jni::CallStaticMethod<jni::jobject*>(env, *javaClass, *fromLngLats, coordinates.get()));
+ jni::LocalObject<jni::jarray<jni::jobject>> lngLatsArray =
+ jni::NewLocalObject(env, toLngLatArray(env, geometry));
+ return reinterpret_cast<jni::jobject*>(jni::CallStaticMethod<jni::jobject*>(env, *javaClass, *fromLngLats, lngLatsArray.get()));
}
/**
- * static Polygon fromLngLats(List<List<Point>> coordinates)
+ * static Polygon fromLngLats(double [][][])
*/
jni::jobject* operator()(const mapbox::geometry::polygon<T> &geometry) const {
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/geojson/Polygon")).release();
- static jni::jmethodID* fromLngLats = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "(Ljava/util/List;)Lcom/mapbox/geojson/Polygon;");
+ static jni::jmethodID* fromLngLats = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "([[[D)Lcom/mapbox/geojson/Polygon;");
// Create
- jni::LocalObject<jni::jobject> shape = jni::NewLocalObject(env, toShape<>(env, geometry));
+ jni::LocalObject<jni::jarray<jni::jobject>> shape =
+ jni::NewLocalObject(env, shapeToLngLatArray<>(env, geometry));
return reinterpret_cast<jni::jobject*>(jni::CallStaticMethod<jni::jobject*>(env, *javaClass, *fromLngLats, shape.get()));
}
/**
- * static MultiLineString fromLngLats(List<List<Point>> points)
+ * static MultiLineString fromLngLats(double [][][])
*/
jni::jobject* operator()(const mapbox::geometry::multi_line_string<T> &geometry) const {
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/geojson/MultiLineString")).release();
- static jni::jmethodID* fromLngLats = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "(Ljava/util/List;)Lcom/mapbox/geojson/MultiLineString;");
+ static jni::jmethodID* fromLngLats = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "([[[D)Lcom/mapbox/geojson/MultiLineString;");
// Create
- jni::LocalObject<jni::jobject> shape = jni::NewLocalObject(env, toShape<>(env, geometry));
+ jni::LocalObject<jni::jarray<jni::jobject>> shape =
+ jni::NewLocalObject(env,shapeToLngLatArray<>(env, geometry));
return reinterpret_cast<jni::jobject*>(jni::CallStaticMethod<jni::jobject*>(env, *javaClass, *fromLngLats, shape.get()));
}
/**
* MultiPolygon (double[][][][]) -> [[[D + Object array == [[[[D
- *
- * static MultiPolygon fromLngLats(List<List<List<Point>>> points)
*/
jni::jobject* operator()(const mapbox::geometry::multi_polygon<T> &geometry) const {
- // ArrayList
- static jni::jclass* arrayListClass = jni::NewGlobalRef(env, &jni::FindClass(env, "java/util/ArrayList")).release();
- static jni::jmethodID* constructor = &jni::GetMethodID(env, *arrayListClass, "<init>", "(I)V");
- static jni::jmethodID* add = &jni::GetMethodID(env, *arrayListClass, "add", "(ILjava/lang/Object;)V");
- jni::jobject* arrayList = &jni::NewObject(env, *arrayListClass, *constructor, geometry.size());
+
+ static jni::jclass* arrayClass = jni::NewGlobalRef(env, &jni::FindClass(env, "[[[D")).release();
+ jni::LocalObject<jni::jarray<jni::jobject>> jarray =
+ jni::NewLocalObject(env, &jni::NewObjectArray(env, geometry.size(), *arrayClass));
for(size_t i = 0; i < geometry.size(); i = i + 1) {
- jni::LocalObject<jni::jobject> shape = jni::NewLocalObject(env, toShape<>(env, geometry.at(i)));
- jni::CallMethod<void>(env, arrayList, *add, i, shape.get());
+ jni::LocalObject<jni::jarray<jni::jobject>> shape =
+ jni::NewLocalObject(env, shapeToLngLatArray<>(env, geometry.at(i)));
+ jni::SetObjectArrayElement(env, *jarray, i, shape.get());
}
// Create the MultiPolygon
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/geojson/MultiPolygon")).release();
- static jni::jmethodID* fromGeometries = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "(Ljava/util/List;)Lcom/mapbox/geojson/MultiPolygon;");
- return reinterpret_cast<jni::jobject*>(jni::CallStaticMethod<jni::jobject*>(env, *javaClass, *fromGeometries, arrayList));
+ static jni::jmethodID* fromGeometries = &jni::GetStaticMethodID(env, *javaClass, "fromLngLats", "([[[[D)Lcom/mapbox/geojson/MultiPolygon;");
+ return reinterpret_cast<jni::jobject*>(jni::CallStaticMethod<jni::jobject*>(env, *javaClass, *fromGeometries, jarray.get()));
}
/**
@@ -125,50 +127,50 @@ public:
private:
/**
- * vector<point<T>> -> List<Point>
- */
- static jni::jobject* toGeoJsonListOfPoints(JNIEnv& env, std::vector<mapbox::geometry::point<T>> points) {
-
- // ArrayList
- static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "java/util/ArrayList")).release();
- static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "(I)V");
- static jni::jmethodID* add = &jni::GetMethodID(env, *javaClass, "add", "(ILjava/lang/Object;)V");
- jni::jobject* arrayList = &jni::NewObject(env, *javaClass, *constructor, points.size());
+ * x, y -> jarray<jdouble> ([x,y])
+ *
+ */
+ static jni::jarray<jni::jdouble> *toLngLatArray(JNIEnv &env, double x, double y) {
+ jni::jarray<jni::jdouble> &jarray = jni::NewArray<jni::jdouble>(env, 2);
+ jni::jdouble array[] = {x, y};
+ jni::SetArrayRegion(env, jarray, 0, 2, array);
+ return &jarray;
+ }
+ /**
+ * vector<point<T>> -> jarray<jobject> -> [D + Object array == [[D (double[][])
+ */
+ static jni::jarray<jni::jobject>* toLngLatArray(JNIEnv &env,
+ std::vector<mapbox::geometry::point<T>> points) {
- // Point
- static jni::jclass* pointJavaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/geojson/Point")).release();
- static jni::jmethodID* fromLngLat = &jni::GetStaticMethodID(env, *pointJavaClass, "fromLngLat", "(DD)Lcom/mapbox/geojson/Point;");
+ static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "[D")).release();
+ jni::jarray<jni::jobject >& jarray = jni::NewObjectArray(env, points.size(), *javaClass);
for(size_t i = 0; i < points.size(); i = i + 1) {
mapbox::geometry::point<T> point = points.at(i);
- jni::LocalObject<jni::jobject> pointObject =
- jni::NewLocalObject(env, jni::CallStaticMethod<jni::jobject*>(env, *pointJavaClass, *fromLngLat, point.x, point.y));
- jni::CallMethod<void>(env, arrayList, *add, i, pointObject.get());
+ jni::jarray<jni::jdouble> *lngLatArray = toLngLatArray(env, point.x, point.y);
+ jni::SetObjectArrayElement(env, jarray, i, lngLatArray);
}
- return arrayList;
+ return &jarray;
}
/**
- * geometry -> List<List<Point>>
+ * polygon<T>
+ * multi_line_string<T> -> jarray<jobject> -> [[D + Object array == [[[D (double[][][])
*/
template <class SHAPE>
- static jni::jobject* toShape(JNIEnv& env, SHAPE value) {
-
- // ArrayList
- static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "java/util/ArrayList")).release();
- static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "(I)V");
- static jni::jmethodID* add = &jni::GetMethodID(env, *javaClass, "add", "(ILjava/lang/Object;)V");
- jni::jobject* arrayList = &jni::NewObject(env, *javaClass, *constructor, value.size());
-
-
- for(size_t i = 0; i < value.size(); i = i + 1) {
- jni::LocalObject<jni::jobject> listOfPoints = jni::NewLocalObject(env, toGeoJsonListOfPoints(env, value.at(i)));
- jni::CallMethod<void>(env, arrayList, *add, i, listOfPoints.get());
+ static jni::jarray<jni::jobject>* shapeToLngLatArray(JNIEnv &env, SHAPE value) {
+ static jni::jclass *javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "[[D")).release();
+ jni::jarray<jni::jobject> &jarray = jni::NewObjectArray(env, value.size(), *javaClass);
+
+ for (size_t i = 0; i < value.size(); i = i + 1) {
+ jni::LocalObject<jni::jarray<jni::jobject>> lngLatsArray =
+ jni::NewLocalObject(env, toLngLatArray(env, value.at(i)));
+ jni::SetObjectArrayElement(env, jarray, i, lngLatsArray.get());
}
- return arrayList;
+ return &jarray;
}
};