[android] geojson conversion optimisation
This commit is contained in:
committed by
Ivo van Dongen
parent
f70f604e5b
commit
fa7489fb7e
@@ -11,7 +11,6 @@ import com.mapbox.services.commons.geojson.FeatureCollection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -133,8 +132,7 @@ public class GeoJsonSource extends Source {
|
||||
* @param features the GeoJSON {@link FeatureCollection}
|
||||
*/
|
||||
public void setGeoJson(FeatureCollection features) {
|
||||
checkValidity();
|
||||
setGeoJson(features.toJson());
|
||||
nativeSetFeatureCollection(features);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,8 +141,7 @@ public class GeoJsonSource extends Source {
|
||||
* @param json the raw GeoJson FeatureCollection string
|
||||
*/
|
||||
public void setGeoJson(String json) {
|
||||
checkValidity();
|
||||
setRawJson(json);
|
||||
nativeSetGeoJsonString(json);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +150,6 @@ public class GeoJsonSource extends Source {
|
||||
* @param url the GeoJSON FeatureCollection url
|
||||
*/
|
||||
public void setUrl(URL url) {
|
||||
checkValidity();
|
||||
setUrl(url.toExternalForm());
|
||||
}
|
||||
|
||||
@@ -163,7 +159,6 @@ public class GeoJsonSource extends Source {
|
||||
* @param url the GeoJSON FeatureCollection url
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
checkValidity();
|
||||
nativeSetUrl(url);
|
||||
}
|
||||
|
||||
@@ -179,19 +174,13 @@ public class GeoJsonSource extends Source {
|
||||
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
|
||||
}
|
||||
|
||||
protected void setRawJson(String geoJson) {
|
||||
// Wrap the String in a map as an Object is expected by the
|
||||
// style conversion template
|
||||
HashMap<String, String> wrapper = new HashMap<>();
|
||||
wrapper.put("data", geoJson);
|
||||
nativeSetGeoJson(wrapper);
|
||||
}
|
||||
|
||||
protected native void initialize(String layerId, Object options);
|
||||
|
||||
protected native void nativeSetUrl(String url);
|
||||
|
||||
private native void nativeSetGeoJson(Object geoJson);
|
||||
private native void nativeSetGeoJsonString(String geoJson);
|
||||
|
||||
private native void nativeSetFeatureCollection(FeatureCollection geoJson);
|
||||
|
||||
private native Feature[] querySourceFeatures(Object[] filter);
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ package com.mapbox.mapboxsdk.style.sources;
|
||||
*/
|
||||
public abstract class Source {
|
||||
private long nativePtr;
|
||||
private boolean invalidated;
|
||||
|
||||
/**
|
||||
* Internal use
|
||||
@@ -25,7 +24,6 @@ public abstract class Source {
|
||||
* @return the source id
|
||||
*/
|
||||
public String getId() {
|
||||
checkValidity();
|
||||
return nativeGetId();
|
||||
}
|
||||
|
||||
@@ -40,16 +38,4 @@ public abstract class Source {
|
||||
|
||||
protected native String nativeGetId();
|
||||
|
||||
protected void checkValidity() {
|
||||
if (invalidated) {
|
||||
throw new RuntimeException("Layer has been invalidated. Request a new reference after adding");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use - invalidates the source for further use (after adding it to the map)
|
||||
*/
|
||||
public final void invalidate() {
|
||||
this.invalidated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,9 +184,29 @@ add_library(mbgl-android STATIC
|
||||
platform/android/src/graphics/rectf.cpp
|
||||
platform/android/src/graphics/rectf.hpp
|
||||
|
||||
# GeoJSON
|
||||
platform/android/src/geojson/feature.cpp
|
||||
platform/android/src/geojson/feature.hpp
|
||||
platform/android/src/geojson/feature_collection.cpp
|
||||
platform/android/src/geojson/feature_collection.hpp
|
||||
platform/android/src/geojson/geometry.cpp
|
||||
platform/android/src/geojson/geometry.hpp
|
||||
platform/android/src/geojson/line_string.cpp
|
||||
platform/android/src/geojson/line_string.hpp
|
||||
platform/android/src/geojson/multi_line_string.cpp
|
||||
platform/android/src/geojson/multi_line_string.hpp
|
||||
platform/android/src/geojson/multi_point.cpp
|
||||
platform/android/src/geojson/multi_point.hpp
|
||||
platform/android/src/geojson/multi_polygon.cpp
|
||||
platform/android/src/geojson/multi_polygon.hpp
|
||||
platform/android/src/geojson/point.cpp
|
||||
platform/android/src/geojson/point.hpp
|
||||
platform/android/src/geojson/polygon.cpp
|
||||
platform/android/src/geojson/polygon.hpp
|
||||
platform/android/src/geojson/position.cpp
|
||||
platform/android/src/geojson/position.hpp
|
||||
|
||||
# Geometry
|
||||
platform/android/src/geometry/feature.cpp
|
||||
platform/android/src/geometry/feature.hpp
|
||||
platform/android/src/geometry/lat_lng.cpp
|
||||
platform/android/src/geometry/lat_lng.hpp
|
||||
platform/android/src/geometry/lat_lng_bounds.cpp
|
||||
@@ -194,6 +214,16 @@ add_library(mbgl-android STATIC
|
||||
platform/android/src/geometry/projected_meters.cpp
|
||||
platform/android/src/geometry/projected_meters.hpp
|
||||
|
||||
# GSon
|
||||
platform/android/src/gson/json_array.cpp
|
||||
platform/android/src/gson/json_array.hpp
|
||||
platform/android/src/gson/json_element.cpp
|
||||
platform/android/src/gson/json_element.hpp
|
||||
platform/android/src/gson/json_object.cpp
|
||||
platform/android/src/gson/json_object.hpp
|
||||
platform/android/src/gson/json_primitive.cpp
|
||||
platform/android/src/gson/json_primitive.hpp
|
||||
|
||||
# Annotation
|
||||
platform/android/src/annotation/marker.cpp
|
||||
platform/android/src/annotation/marker.hpp
|
||||
|
||||
@@ -170,8 +170,8 @@ struct Converter<jni::jobject*, std::unordered_map<std::string, mbgl::Value>> {
|
||||
|
||||
|
||||
template <>
|
||||
struct Converter<jni::Object<Feature>, mbgl::Feature> {
|
||||
Result<jni::Object<Feature>> operator()(jni::JNIEnv& env, const mbgl::Feature& value) const {
|
||||
struct Converter<jni::Object<android::geojson::Feature>, mbgl::Feature> {
|
||||
Result<jni::Object<android::geojson::Feature>> operator()(jni::JNIEnv& env, const mbgl::Feature& value) const {
|
||||
|
||||
// Convert Id
|
||||
FeatureIdVisitor idEvaluator;
|
||||
@@ -179,13 +179,13 @@ struct Converter<jni::Object<Feature>, mbgl::Feature> {
|
||||
auto jid = jni::Make<jni::String>(env, id);
|
||||
|
||||
// Convert properties
|
||||
auto properties = jni::Object<JsonObject>(*convert<jni::jobject*>(env, value.properties));
|
||||
auto properties = jni::Object<gson::JsonObject>(*convert<jni::jobject*>(env, value.properties));
|
||||
|
||||
// Convert geometry
|
||||
auto geometry = jni::Object<Geometry>(*convert<jni::jobject*>(env, value.geometry));
|
||||
auto geometry = jni::Object<android::geojson::Geometry>(*convert<jni::jobject*>(env, value.geometry));
|
||||
|
||||
// Create feature
|
||||
auto feature = Feature::fromGeometry(env, geometry, properties, jid);
|
||||
auto feature = android::geojson::Feature::fromGeometry(env, geometry, properties, jid);
|
||||
|
||||
//Cleanup
|
||||
jni::DeleteLocalRef(env, jid);
|
||||
@@ -197,13 +197,13 @@ struct Converter<jni::Object<Feature>, mbgl::Feature> {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>> {
|
||||
Result<jni::Array<jni::Object<Feature>>> operator()(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) const {
|
||||
|
||||
struct Converter<jni::Array<jni::Object<android::geojson::Feature>>, std::vector<mbgl::Feature>> {
|
||||
Result<jni::Array<jni::Object<android::geojson::Feature>>> operator()(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) const {
|
||||
using namespace mbgl::android::geojson;
|
||||
auto features = jni::Array<jni::Object<Feature>>::New(env, value.size(), Feature::javaClass);
|
||||
|
||||
for(size_t i = 0; i < value.size(); i = i + 1) {
|
||||
auto converted = *convert<jni::Object<Feature>, mbgl::Feature>(env, value.at(i));
|
||||
auto converted = *convert<jni::Object<android::geojson::Feature>, mbgl::Feature>(env, value.at(i));
|
||||
features.Set(env, i, converted);
|
||||
jni::DeleteLocalRef(env, converted);
|
||||
}
|
||||
63
platform/android/src/geojson/feature.cpp
Normal file
63
platform/android/src/geojson/feature.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "feature.hpp"
|
||||
|
||||
#include "geometry.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mbgl::Feature Feature::convert(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
|
||||
// Convert
|
||||
auto jGeometry = getGeometry(env, jFeature);
|
||||
auto jProperties = Feature::getProperties(env, jFeature);
|
||||
|
||||
std::experimental::optional<mapbox::geometry::identifier> id;
|
||||
auto jId = Feature::getId(env, jFeature);
|
||||
if (jId) {
|
||||
id = { jni::Make<std::string>(env, jId) };
|
||||
}
|
||||
|
||||
auto feature = mbgl::Feature {
|
||||
Geometry::convert(env, jGeometry),
|
||||
gson::JsonObject::convert(env, jProperties),
|
||||
id
|
||||
};
|
||||
|
||||
// Cleanup
|
||||
jni::DeleteLocalRef(env, jGeometry);
|
||||
jni::DeleteLocalRef(env, jProperties);
|
||||
jni::DeleteLocalRef(env, jId);
|
||||
|
||||
return feature;
|
||||
}
|
||||
|
||||
jni::Object<Geometry> Feature::getGeometry(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
|
||||
static auto method = Feature::javaClass.GetMethod<jni::Object<Geometry> ()>(env, "getGeometry");
|
||||
return jFeature.Call(env, method);
|
||||
}
|
||||
|
||||
jni::Object<gson::JsonObject> Feature::getProperties(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
|
||||
static auto method = Feature::javaClass.GetMethod<jni::Object<gson::JsonObject> ()>(env, "getProperties");
|
||||
return jFeature.Call(env, method);
|
||||
}
|
||||
|
||||
jni::String Feature::getId(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
|
||||
static auto method = Feature::javaClass.GetMethod<jni::String ()>(env, "getId");
|
||||
return jFeature.Call(env, method);
|
||||
}
|
||||
|
||||
jni::Object<Feature> Feature::fromGeometry(jni::JNIEnv& env, jni::Object<Geometry> geometry, jni::Object<gson::JsonObject> properties, jni::String id) {
|
||||
static auto method = Feature::javaClass.GetStaticMethod<jni::Object<Feature> (jni::Object<Geometry>, jni::Object<gson::JsonObject>, jni::String)>(env, "fromGeometry");
|
||||
return Feature::javaClass.Call(env, method, geometry, properties, id);
|
||||
}
|
||||
|
||||
void Feature::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
Feature::javaClass = *jni::Class<Feature>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<Feature> Feature::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/feature.hpp>
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
@@ -10,13 +11,22 @@
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Feature : private mbgl::util::noncopyable {
|
||||
public:
|
||||
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/Feature"; };
|
||||
|
||||
static jni::Object<Feature> fromGeometry(jni::JNIEnv&, jni::Object<Geometry>, jni::Object<JsonObject>, jni::String);
|
||||
static jni::Object<Feature> fromGeometry(jni::JNIEnv&, jni::Object<Geometry>, jni::Object<gson::JsonObject>, jni::String);
|
||||
|
||||
static mbgl::Feature convert(jni::JNIEnv&, jni::Object<Feature>);
|
||||
|
||||
static jni::Object<Geometry> getGeometry(jni::JNIEnv&, jni::Object<Feature>);
|
||||
|
||||
static jni::String getId(jni::JNIEnv&, jni::Object<Feature>);
|
||||
|
||||
static jni::Object<gson::JsonObject> getProperties(jni::JNIEnv&, jni::Object<Feature>);
|
||||
|
||||
static jni::Class<Feature> javaClass;
|
||||
|
||||
@@ -24,6 +34,6 @@ public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
40
platform/android/src/geojson/feature_collection.cpp
Normal file
40
platform/android/src/geojson/feature_collection.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "feature_collection.hpp"
|
||||
|
||||
#include "feature.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mbgl::FeatureCollection FeatureCollection::convert(jni::JNIEnv& env, jni::Object<FeatureCollection> jCollection) {
|
||||
auto jFeatureList = FeatureCollection::getFeatures(env, jCollection);
|
||||
auto jFeatures = java::util::List::toArray<Feature>(env, jFeatureList);
|
||||
auto size = size_t(jFeatures.Length(env));
|
||||
|
||||
auto collection = mbgl::FeatureCollection();
|
||||
collection.reserve(size);
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
auto jFeature = jFeatures.Get(env, i);
|
||||
collection.push_back(Feature::convert(env, jFeature));
|
||||
jni::DeleteLocalRef(env, jFeature);
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
jni::Object<java::util::List> FeatureCollection::getFeatures(jni::JNIEnv& env, jni::Object<FeatureCollection> jCollection) {
|
||||
static auto method = FeatureCollection::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "getFeatures");
|
||||
return jCollection.Call(env, method);
|
||||
}
|
||||
|
||||
void FeatureCollection::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<FeatureCollection>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<FeatureCollection> FeatureCollection::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
29
platform/android/src/geojson/feature_collection.hpp
Normal file
29
platform/android/src/geojson/feature_collection.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class FeatureCollection : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/FeatureCollection"; };
|
||||
|
||||
static mbgl::FeatureCollection convert(jni::JNIEnv&, jni::Object<FeatureCollection>);
|
||||
|
||||
static jni::Object<java::util::List> getFeatures(jni::JNIEnv&, jni::Object<FeatureCollection>);
|
||||
|
||||
static jni::Class<FeatureCollection> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
52
platform/android/src/geojson/geometry.cpp
Normal file
52
platform/android/src/geojson/geometry.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "geometry.hpp"
|
||||
|
||||
#include "point.hpp"
|
||||
#include "multi_point.hpp"
|
||||
#include "line_string.hpp"
|
||||
#include "multi_line_string.hpp"
|
||||
#include "polygon.hpp"
|
||||
#include "multi_polygon.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mapbox::geojson::geometry Geometry::convert(jni::JNIEnv &env, jni::Object<Geometry> jGeometry) {
|
||||
auto type = Geometry::getType(env, jGeometry);
|
||||
if (type == Point::Type()) {
|
||||
return { Point::convert(env, jni::Object<Point>(jGeometry.Get())) };
|
||||
} else if (type == MultiPoint::Type()) {
|
||||
return { MultiPoint::convert(env, jni::Object<MultiPoint>(jGeometry.Get())) };
|
||||
} else if (type == LineString::Type()) {
|
||||
return { LineString::convert(env, jni::Object<LineString>(jGeometry.Get())) };
|
||||
} else if (type == MultiLineString::Type()) {
|
||||
return { MultiLineString::convert(env, jni::Object<MultiLineString>(jGeometry.Get())) };
|
||||
} else if (type == Polygon::Type()) {
|
||||
return { Polygon::convert(env, jni::Object<Polygon>(jGeometry.Get())) };
|
||||
} else if (type == MultiPolygon::Type()) {
|
||||
return { MultiPolygon::convert(env, jni::Object<MultiPolygon>(jGeometry.Get())) };
|
||||
}
|
||||
|
||||
throw std::runtime_error(std::string {"Unsupported GeoJSON type: " } + type);
|
||||
}
|
||||
|
||||
std::string Geometry::getType(jni::JNIEnv &env, jni::Object<Geometry> jGeometry) {
|
||||
static auto method = Geometry::javaClass.GetMethod<jni::String ()>(env, "getType");
|
||||
auto jType = jGeometry.Call(env, method);
|
||||
auto type = jni::Make<std::string>(env, jType);
|
||||
jni::DeleteLocalRef(env, jType);
|
||||
return type;
|
||||
}
|
||||
|
||||
void Geometry::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<Geometry>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<Geometry> Geometry::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
27
platform/android/src/geojson/geometry.hpp
Normal file
27
platform/android/src/geojson/geometry.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Geometry : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/Geometry"; };
|
||||
|
||||
static mapbox::geojson::geometry convert(jni::JNIEnv&, jni::Object<Geometry>);
|
||||
|
||||
static std::string getType(jni::JNIEnv&, jni::Object<Geometry>);
|
||||
|
||||
static jni::Class<Geometry> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
54
platform/android/src/geojson/line_string.cpp
Normal file
54
platform/android/src/geojson/line_string.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "line_string.hpp"
|
||||
|
||||
#include "position.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mapbox::geojson::line_string LineString::convert(jni::JNIEnv &env, jni::Object<LineString> jLineString) {
|
||||
mapbox::geojson::line_string lineString;
|
||||
|
||||
if (jLineString) {
|
||||
auto jPositionList = LineString::getCoordinates(env, jLineString);
|
||||
lineString = LineString::convert(env, jPositionList);
|
||||
jni::DeleteLocalRef(env, jPositionList);
|
||||
}
|
||||
|
||||
return lineString;
|
||||
}
|
||||
|
||||
mapbox::geojson::line_string LineString::convert(jni::JNIEnv &env, jni::Object<java::util::List/*<Position>*/> jPositionList) {
|
||||
mapbox::geojson::line_string lineString;
|
||||
|
||||
if (jPositionList) {
|
||||
auto jPositionArray = java::util::List::toArray<Position>(env, jPositionList);
|
||||
|
||||
auto size = jPositionArray.Length(env);
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
auto jPosition = jPositionArray.Get(env, i);
|
||||
lineString.push_back(Position::convert(env, jPosition));
|
||||
jni::DeleteLocalRef(env, jPosition);
|
||||
}
|
||||
|
||||
jni::DeleteLocalRef(env, jPositionArray);
|
||||
}
|
||||
|
||||
return lineString;
|
||||
}
|
||||
|
||||
jni::Object<java::util::List> LineString::getCoordinates(jni::JNIEnv &env, jni::Object<LineString> jLineString) {
|
||||
static auto method = LineString::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "getCoordinates");
|
||||
return jLineString.Call(env, method);
|
||||
}
|
||||
|
||||
void LineString::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<LineString>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<LineString> LineString::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
34
platform/android/src/geojson/line_string.hpp
Normal file
34
platform/android/src/geojson/line_string.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
|
||||
class LineString : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/LineString"; };
|
||||
|
||||
static constexpr auto Type() { return "LineString"; };
|
||||
|
||||
static mapbox::geojson::line_string convert(jni::JNIEnv&, jni::Object<LineString>);
|
||||
|
||||
static mapbox::geojson::line_string convert(jni::JNIEnv&, jni::Object<java::util::List/*<Position>*/>);
|
||||
|
||||
static jni::Object<java::util::List> getCoordinates(jni::JNIEnv&, jni::Object<LineString>);
|
||||
|
||||
static jni::Class<LineString> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
56
platform/android/src/geojson/multi_line_string.cpp
Normal file
56
platform/android/src/geojson/multi_line_string.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "multi_line_string.hpp"
|
||||
|
||||
#include "line_string.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mapbox::geojson::multi_line_string MultiLineString::convert(jni::JNIEnv &env, jni::Object<MultiLineString> jMultiLineString) {
|
||||
mapbox::geojson::multi_line_string multiLineString;
|
||||
|
||||
if (jMultiLineString) {
|
||||
auto jPositionListsList = MultiLineString::getCoordinates(env, jMultiLineString);
|
||||
multiLineString = MultiLineString::convert(env, jPositionListsList);
|
||||
jni::DeleteLocalRef(env, jPositionListsList);
|
||||
}
|
||||
|
||||
return multiLineString;
|
||||
}
|
||||
|
||||
mapbox::geojson::multi_line_string MultiLineString::convert(jni::JNIEnv &env, jni::Object<java::util::List/*<java::util::List<Position>>*/> jPositionListsList) {
|
||||
mapbox::geojson::multi_line_string multiLineString;
|
||||
|
||||
if (jPositionListsList) {
|
||||
auto jPositionListsArray = java::util::List::toArray<java::util::List>(env, jPositionListsList);
|
||||
|
||||
auto size = jPositionListsArray.Length(env);
|
||||
multiLineString.reserve(size);
|
||||
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
auto jPositionList = jPositionListsArray.Get(env, i);
|
||||
multiLineString.push_back(LineString::convert(env, jPositionList));
|
||||
jni::DeleteLocalRef(env, jPositionList);
|
||||
}
|
||||
|
||||
jni::DeleteLocalRef(env, jPositionListsArray);
|
||||
}
|
||||
|
||||
return multiLineString;
|
||||
}
|
||||
|
||||
jni::Object<java::util::List> MultiLineString::getCoordinates(jni::JNIEnv &env, jni::Object<MultiLineString> jLineString) {
|
||||
static auto method = MultiLineString::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "getCoordinates");
|
||||
return jLineString.Call(env, method);
|
||||
}
|
||||
|
||||
void MultiLineString::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<MultiLineString>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<MultiLineString> MultiLineString::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
33
platform/android/src/geojson/multi_line_string.hpp
Normal file
33
platform/android/src/geojson/multi_line_string.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class MultiLineString : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/MultiLineString"; };
|
||||
|
||||
static constexpr auto Type() { return "MultiLineString"; };
|
||||
|
||||
static mapbox::geojson::multi_line_string convert(jni::JNIEnv&, jni::Object<MultiLineString>);
|
||||
|
||||
static mapbox::geojson::multi_line_string convert(jni::JNIEnv&, jni::Object<java::util::List/*<java::util::List<Position>>*/>);
|
||||
|
||||
static jni::Object<java::util::List> getCoordinates(jni::JNIEnv&, jni::Object<MultiLineString>);
|
||||
|
||||
static jni::Class<MultiLineString> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
35
platform/android/src/geojson/multi_point.cpp
Normal file
35
platform/android/src/geojson/multi_point.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "multi_point.hpp"
|
||||
|
||||
#include "line_string.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mapbox::geojson::multi_point MultiPoint::convert(jni::JNIEnv &env, jni::Object<MultiPoint> jMultiPoint) {
|
||||
mapbox::geojson::multi_point multiPoint;
|
||||
|
||||
if (jMultiPoint) {
|
||||
auto jPositionListsList = MultiPoint::getCoordinates(env, jMultiPoint);
|
||||
multiPoint = LineString::convert(env, jPositionListsList);
|
||||
jni::DeleteLocalRef(env, jPositionListsList);
|
||||
}
|
||||
|
||||
return multiPoint;
|
||||
}
|
||||
|
||||
jni::Object<java::util::List> MultiPoint::getCoordinates(jni::JNIEnv &env, jni::Object<MultiPoint> jMultiPoint) {
|
||||
static auto method = MultiPoint::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "getCoordinates");
|
||||
return jMultiPoint.Call(env, method);
|
||||
}
|
||||
|
||||
void MultiPoint::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<MultiPoint>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<MultiPoint> MultiPoint::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
31
platform/android/src/geojson/multi_point.hpp
Normal file
31
platform/android/src/geojson/multi_point.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class MultiPoint : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/MultiPoint"; };
|
||||
|
||||
static constexpr auto Type() { return "MultiPoint"; };
|
||||
|
||||
static mapbox::geojson::multi_point convert(jni::JNIEnv&, jni::Object<MultiPoint>);
|
||||
|
||||
static jni::Object<java::util::List> getCoordinates(jni::JNIEnv&, jni::Object<MultiPoint>);
|
||||
|
||||
static jni::Class<MultiPoint> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
46
platform/android/src/geojson/multi_polygon.cpp
Normal file
46
platform/android/src/geojson/multi_polygon.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "multi_polygon.hpp"
|
||||
|
||||
#include "polygon.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mapbox::geojson::multi_polygon MultiPolygon::convert(jni::JNIEnv &env, jni::Object<MultiPolygon> jMultiPolygon) {
|
||||
mapbox::geojson::multi_polygon multiPolygon;
|
||||
|
||||
if (jMultiPolygon) {
|
||||
auto jPositionListsListList = MultiPolygon::getCoordinates(env, jMultiPolygon);
|
||||
auto jPositionListsListArray = java::util::List::toArray<java::util::List>(env, jPositionListsListList);
|
||||
|
||||
auto size = jPositionListsListArray.Length(env);
|
||||
multiPolygon.reserve(size);
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
auto jPositionListsList = jPositionListsListArray.Get(env, i);
|
||||
multiPolygon.push_back(Polygon::convert(env, jPositionListsList));
|
||||
jni::DeleteLocalRef(env, jPositionListsList);
|
||||
}
|
||||
|
||||
jni::DeleteLocalRef(env, jPositionListsListList);
|
||||
jni::DeleteLocalRef(env, jPositionListsListArray);
|
||||
}
|
||||
|
||||
return multiPolygon;
|
||||
}
|
||||
|
||||
jni::Object<java::util::List> MultiPolygon::getCoordinates(jni::JNIEnv &env, jni::Object<MultiPolygon> jPolygon) {
|
||||
static auto method = MultiPolygon::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "getCoordinates");
|
||||
return jPolygon.Call(env, method);
|
||||
}
|
||||
|
||||
void MultiPolygon::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<MultiPolygon>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<MultiPolygon> MultiPolygon::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
31
platform/android/src/geojson/multi_polygon.hpp
Normal file
31
platform/android/src/geojson/multi_polygon.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class MultiPolygon : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/MultiPolygon"; };
|
||||
|
||||
static constexpr auto Type() { return "MultiPolygon"; };
|
||||
|
||||
static mapbox::geojson::multi_polygon convert(jni::JNIEnv&, jni::Object<MultiPolygon>);
|
||||
|
||||
static jni::Object<java::util::List> getCoordinates(jni::JNIEnv&, jni::Object<MultiPolygon>);
|
||||
|
||||
static jni::Class<MultiPolygon> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
28
platform/android/src/geojson/point.cpp
Normal file
28
platform/android/src/geojson/point.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "point.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mapbox::geojson::point Point::convert(jni::JNIEnv &env, jni::Object<Point> jPoint) {
|
||||
auto jPosition = Point::getPosition(env, jPoint);
|
||||
auto point = Position::convert(env, jPosition);
|
||||
jni::DeleteLocalRef(env, jPosition);
|
||||
return point;
|
||||
}
|
||||
|
||||
jni::Object<Position> Point::getPosition(JNIEnv& env, jni::Object<Point> jPoint) {
|
||||
static auto method = Point::javaClass.GetMethod<jni::Object<Position> ()>(env, "getCoordinates");
|
||||
return jPoint.Call(env, method);
|
||||
}
|
||||
|
||||
void Point::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<Point>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<Point> Point::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
31
platform/android/src/geojson/point.hpp
Normal file
31
platform/android/src/geojson/point.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include "position.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Point : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/Point"; };
|
||||
|
||||
static constexpr auto Type() { return "Point"; };
|
||||
|
||||
static mapbox::geojson::point convert(jni::JNIEnv&, jni::Object<Point>);
|
||||
|
||||
static jni::Object<Position> getPosition(JNIEnv&, jni::Object<Point>);
|
||||
|
||||
static jni::Class<Point> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
48
platform/android/src/geojson/polygon.cpp
Normal file
48
platform/android/src/geojson/polygon.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "polygon.hpp"
|
||||
|
||||
#include "multi_line_string.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mapbox::geojson::polygon Polygon::convert(jni::JNIEnv &env, jni::Object<Polygon> jPolygon) {
|
||||
mapbox::geojson::polygon polygon;
|
||||
|
||||
if (jPolygon) {
|
||||
auto jPositionListsList = Polygon::getCoordinates(env, jPolygon);
|
||||
polygon = Polygon::convert(env, jPositionListsList);
|
||||
jni::DeleteLocalRef(env, jPositionListsList);
|
||||
}
|
||||
|
||||
return polygon;
|
||||
}
|
||||
|
||||
mapbox::geojson::polygon Polygon::convert(jni::JNIEnv &env, jni::Object<java::util::List/*<java::util::List<Position>>*/> jPositionListsList) {
|
||||
mapbox::geojson::polygon polygon;
|
||||
|
||||
if (jPositionListsList) {
|
||||
auto multiLine = MultiLineString::convert(env, jPositionListsList);
|
||||
polygon.reserve(multiLine.size());
|
||||
polygon.insert(std::end(polygon), std::begin(multiLine), std::end(multiLine));
|
||||
}
|
||||
|
||||
return polygon;
|
||||
}
|
||||
|
||||
|
||||
jni::Object<java::util::List> Polygon::getCoordinates(jni::JNIEnv &env, jni::Object<Polygon> jPolygon) {
|
||||
static auto method = Polygon::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "getCoordinates");
|
||||
return jPolygon.Call(env, method);
|
||||
}
|
||||
|
||||
void Polygon::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<Polygon>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<Polygon> Polygon::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
33
platform/android/src/geojson/polygon.hpp
Normal file
33
platform/android/src/geojson/polygon.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Polygon : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/Polygon"; };
|
||||
|
||||
static constexpr auto Type() { return "Polygon"; };
|
||||
|
||||
static mapbox::geojson::polygon convert(jni::JNIEnv &, jni::Object<Polygon>);
|
||||
|
||||
static mapbox::geojson::polygon convert(jni::JNIEnv&, jni::Object<java::util::List/*<java::util::List<Position>>*/>);
|
||||
|
||||
static jni::Object<java::util::List> getCoordinates(jni::JNIEnv&, jni::Object<Polygon>);
|
||||
|
||||
static jni::Class<Polygon> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv &);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
27
platform/android/src/geojson/position.cpp
Normal file
27
platform/android/src/geojson/position.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "position.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mapbox::geojson::point Position::convert(jni::JNIEnv &env, jni::Object<Position> jPosition) {
|
||||
static auto method = Position::javaClass.GetMethod<jni::Array<jdouble> ()>(env, "getCoordinates");
|
||||
// Array with 0: longitude, 1: latitude (and optionally 2: altitude)
|
||||
auto coordinates = jPosition.Call(env, method);
|
||||
jdouble lngLat[2];
|
||||
coordinates.GetRegion(env, 0, lngLat);
|
||||
mapbox::geojson::point point(lngLat[0], lngLat[1]);
|
||||
jni::DeleteLocalRef(env, coordinates);
|
||||
return point;
|
||||
}
|
||||
|
||||
void Position::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<Position>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<Position> Position::javaClass;
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
27
platform/android/src/geojson/position.hpp
Normal file
27
platform/android/src/geojson/position.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Position : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/models/Position"; };
|
||||
|
||||
static constexpr auto Type() { return "Position"; };
|
||||
|
||||
static mapbox::geojson::point convert(jni::JNIEnv&, jni::Object<Position>);
|
||||
|
||||
static jni::Class<Position> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "feature.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
jni::Object<Feature> Feature::fromGeometry(jni::JNIEnv& env, jni::Object<Geometry> geometry, jni::Object<JsonObject> properties, jni::String id) {
|
||||
static auto method = Feature::javaClass.GetStaticMethod<jni::Object<Feature> (jni::Object<Geometry>, jni::Object<JsonObject>, jni::String)>(env, "fromGeometry");
|
||||
return Feature::javaClass.Call(env, method, geometry, properties, id);
|
||||
}
|
||||
|
||||
void Feature::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
Feature::javaClass = *jni::Class<Feature>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<Feature> Feature::javaClass;
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class Geometry : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/services/commons/geojson/Geometry"; };
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
40
platform/android/src/gson/json_array.cpp
Normal file
40
platform/android/src/gson/json_array.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "json_array.hpp"
|
||||
|
||||
#include "json_element.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace gson {
|
||||
|
||||
std::vector<mapbox::geometry::value> JsonArray::convert(jni::JNIEnv &env, jni::Object<JsonArray> jsonArray) {
|
||||
std::vector<mapbox::geometry::value> values;
|
||||
|
||||
if (jsonArray) {
|
||||
static auto getMethod = JsonArray::javaClass.GetMethod<jni::Object<JsonElement> (jni::jint)>(env, "get");
|
||||
static auto sizeMethod = JsonArray::javaClass.GetMethod<jni::jint ()>(env, "size");
|
||||
|
||||
int size = jsonArray.Call(env, sizeMethod);
|
||||
values.reserve(uint(size));
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
auto entry = jsonArray.Call(env, getMethod, i);
|
||||
if (entry) {
|
||||
values.push_back(JsonElement::convert(env, entry));
|
||||
}
|
||||
jni::DeleteLocalRef(env, entry);
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
void JsonArray::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<JsonArray>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<JsonArray> JsonArray::javaClass;
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
25
platform/android/src/gson/json_array.hpp
Normal file
25
platform/android/src/gson/json_array.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace gson {
|
||||
|
||||
class JsonArray : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/google/gson/JsonArray"; };
|
||||
|
||||
static std::vector<mapbox::geometry::value> convert(JNIEnv&, jni::Object<JsonArray>);
|
||||
|
||||
static jni::Class<JsonArray> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
62
platform/android/src/gson/json_element.cpp
Normal file
62
platform/android/src/gson/json_element.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "json_element.hpp"
|
||||
|
||||
#include "json_array.hpp"
|
||||
#include "json_object.hpp"
|
||||
#include "json_primitive.hpp"
|
||||
|
||||
#include <mapbox/geometry/feature.hpp>
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace gson {
|
||||
|
||||
mapbox::geometry::value JsonElement::convert(jni::JNIEnv &env, jni::Object<JsonElement> jsonElement) {
|
||||
mapbox::geometry::value value;
|
||||
|
||||
if (jsonElement) {
|
||||
if (isJsonPrimitive(env, jsonElement)) {
|
||||
auto primitive = JsonPrimitive::convert(env, jni::Cast(env, jsonElement, JsonPrimitive::javaClass));
|
||||
value = mapbox::util::apply_visitor([](auto t) { return mapbox::geometry::value { t }; }, primitive);
|
||||
} else if (isJsonObject(env, jsonElement)) {
|
||||
mapbox::geometry::property_map map = JsonObject::convert(env, jni::Cast(env, jsonElement, JsonObject::javaClass));
|
||||
value = mapbox::util::recursive_wrapper<std::unordered_map<std::string, mapbox::geometry::value>> { map } ;
|
||||
} else if (isJsonArray(env, jsonElement)) {
|
||||
value = JsonArray::convert(env, jni::Cast(env, jsonElement, JsonArray::javaClass));
|
||||
} else {
|
||||
value = mapbox::geometry::null_value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
bool JsonElement::isJsonObject(JNIEnv& env, jni::Object<JsonElement> jsonElement) {
|
||||
static auto method = JsonElement::javaClass.GetMethod<jni::jboolean ()>(env, "isJsonObject");
|
||||
return jsonElement.Call(env, method);
|
||||
}
|
||||
|
||||
bool JsonElement::isJsonArray(JNIEnv& env, jni::Object<JsonElement> jsonElement) {
|
||||
static auto method = JsonElement::javaClass.GetMethod<jni::jboolean ()>(env, "isJsonArray");
|
||||
return jsonElement.Call(env, method);
|
||||
}
|
||||
|
||||
bool JsonElement::isJsonPrimitive(JNIEnv& env, jni::Object<JsonElement> jsonElement) {
|
||||
static auto method = JsonElement::javaClass.GetMethod<jni::jboolean ()>(env, "isJsonPrimitive");
|
||||
return jsonElement.Call(env, method);
|
||||
}
|
||||
|
||||
bool JsonElement::isJsonNull(JNIEnv& env, jni::Object<JsonElement> jsonElement) {
|
||||
static auto method = JsonElement::javaClass.GetMethod<jni::jboolean ()>(env, "isJsonNull");
|
||||
return jsonElement.Call(env, method);
|
||||
}
|
||||
|
||||
void JsonElement::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<JsonElement>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<JsonElement> JsonElement::javaClass;
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
33
platform/android/src/gson/json_element.hpp
Normal file
33
platform/android/src/gson/json_element.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace gson {
|
||||
|
||||
class JsonElement : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/google/gson/JsonElement"; };
|
||||
|
||||
static mapbox::geometry::value convert(JNIEnv&, jni::Object<JsonElement>);
|
||||
|
||||
static bool isJsonObject(JNIEnv&, jni::Object<JsonElement>);
|
||||
|
||||
static bool isJsonArray(JNIEnv&, jni::Object<JsonElement>);
|
||||
|
||||
static bool isJsonPrimitive(JNIEnv&, jni::Object<JsonElement>);
|
||||
|
||||
static bool isJsonNull(JNIEnv&, jni::Object<JsonElement>);
|
||||
|
||||
static jni::Class<JsonElement> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
64
platform/android/src/gson/json_object.cpp
Normal file
64
platform/android/src/gson/json_object.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "json_object.hpp"
|
||||
|
||||
#include "json_element.hpp"
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace gson {
|
||||
|
||||
|
||||
template <typename F> // void (jni::String, jni::Object<gson::JsonElement>)
|
||||
static void iterateEntrySet(jni::JNIEnv& env, jni::Object<JsonObject> jsonObject, F callback) {
|
||||
// Get Set<Map.Entry<String, JsonElement>>
|
||||
static auto method = JsonObject::javaClass.GetMethod<jni::Object<java::util::Set> ()>(env, "entrySet");
|
||||
auto entrySet = jsonObject.Call(env, method);
|
||||
jni::Array<jni::Object<java::util::Map::Entry>> entryArray = java::util::Set::toArray<java::util::Map::Entry>(env, entrySet);
|
||||
|
||||
size_t size = entryArray.Length(env);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
auto entry = entryArray.Get(env, i);
|
||||
if (entry) {
|
||||
// Convert
|
||||
auto jKey = java::util::Map::Entry::getKey<jni::ObjectTag>(env, entry);
|
||||
auto jKeyString = jni::String(reinterpret_cast<jni::jstring*>(jKey.Get()));
|
||||
auto jValue = java::util::Map::Entry::getValue<gson::JsonElement>(env, entry);
|
||||
|
||||
// Callback
|
||||
callback(jKeyString, jValue);
|
||||
|
||||
// Cleanup
|
||||
// Skip jKey as it points to the same as jKeyString
|
||||
jni::DeleteLocalRef(env, jKeyString);
|
||||
jni::DeleteLocalRef(env, jValue);
|
||||
}
|
||||
jni::DeleteLocalRef(env, entry);
|
||||
}
|
||||
|
||||
jni::DeleteLocalRef(env, entrySet);
|
||||
jni::DeleteLocalRef(env, entryArray);
|
||||
}
|
||||
|
||||
mapbox::geometry::property_map JsonObject::convert(jni::JNIEnv &env, jni::Object<JsonObject> jsonObject) {
|
||||
mapbox::geometry::property_map map;
|
||||
|
||||
if (jsonObject) {
|
||||
iterateEntrySet(env, jsonObject, [&map, &env](jni::String jId, jni::Object<gson::JsonElement> jsonElement) {
|
||||
map[jni::Make<std::string>(env, jId)] = JsonElement::convert(env, jsonElement);
|
||||
});
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void JsonObject::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<JsonObject>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<JsonObject> JsonObject::javaClass;
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,16 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace gson {
|
||||
|
||||
class JsonObject : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/google/gson/JsonObject"; };
|
||||
|
||||
static mapbox::geometry::property_map convert(JNIEnv&, jni::Object<JsonObject>);
|
||||
|
||||
static jni::Class<JsonObject> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
66
platform/android/src/gson/json_primitive.cpp
Normal file
66
platform/android/src/gson/json_primitive.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "json_primitive.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace gson {
|
||||
|
||||
JsonPrimitive::value JsonPrimitive::convert(jni::JNIEnv &env, jni::Object<JsonPrimitive> jsonPrimitive) {
|
||||
value value;
|
||||
if (jsonPrimitive) {
|
||||
if (isBoolean(env, jsonPrimitive)) {
|
||||
value = getAsBoolean(env, jsonPrimitive);
|
||||
} else if (isNumber(env, jsonPrimitive)) {
|
||||
//TODO: how to differentiate types here?
|
||||
value = getAsDouble(env, jsonPrimitive);
|
||||
} else if (isString(env, jsonPrimitive)) {
|
||||
value = getAsString(env, jsonPrimitive);
|
||||
} else {
|
||||
value = mapbox::geometry::null_value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
bool JsonPrimitive::isBoolean(JNIEnv& env, jni::Object<JsonPrimitive> jsonPrimitive) {
|
||||
static auto method = JsonPrimitive::javaClass.GetMethod<jni::jboolean ()>(env, "isBoolean");
|
||||
return jsonPrimitive.Call(env, method);
|
||||
}
|
||||
|
||||
bool JsonPrimitive::isString(JNIEnv& env, jni::Object<JsonPrimitive> jsonPrimitive) {
|
||||
static auto method = JsonPrimitive::javaClass.GetMethod<jni::jboolean ()>(env, "isString");
|
||||
return jsonPrimitive.Call(env, method);
|
||||
}
|
||||
|
||||
bool JsonPrimitive::isNumber(JNIEnv& env, jni::Object<JsonPrimitive> jsonPrimitive) {
|
||||
static auto method = JsonPrimitive::javaClass.GetMethod<jni::jboolean ()>(env, "isNumber");
|
||||
return jsonPrimitive.Call(env, method);
|
||||
}
|
||||
|
||||
bool JsonPrimitive::getAsBoolean(JNIEnv& env, jni::Object<JsonPrimitive> jsonPrimitive) {
|
||||
static auto method = JsonPrimitive::javaClass.GetMethod<jni::jboolean ()>(env, "getAsBoolean");
|
||||
return jsonPrimitive.Call(env, method);
|
||||
}
|
||||
|
||||
std::string JsonPrimitive::getAsString(JNIEnv& env, jni::Object<JsonPrimitive> jsonPrimitive) {
|
||||
static auto method = JsonPrimitive::javaClass.GetMethod<jni::String ()>(env, "getAsString");
|
||||
auto jString = jsonPrimitive.Call(env, method);
|
||||
auto string = jni::Make<std::string>(env, jString);
|
||||
jni::DeleteLocalRef(env, jString);
|
||||
return string;
|
||||
}
|
||||
|
||||
double JsonPrimitive::getAsDouble(JNIEnv& env, jni::Object<JsonPrimitive> jsonPrimitive) {
|
||||
static auto method = JsonPrimitive::javaClass.GetMethod<jni::jdouble ()>(env, "getAsDouble");
|
||||
return jsonPrimitive.Call(env, method);
|
||||
}
|
||||
|
||||
void JsonPrimitive::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<JsonPrimitive>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<JsonPrimitive> JsonPrimitive::javaClass;
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
39
platform/android/src/gson/json_primitive.hpp
Normal file
39
platform/android/src/gson/json_primitive.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace gson {
|
||||
|
||||
class JsonPrimitive : private mbgl::util::noncopyable {
|
||||
public:
|
||||
using value = mapbox::util::variant<mapbox::geometry::null_value_t, bool, uint64_t, int64_t, double, std::string>;
|
||||
|
||||
static constexpr auto Name() { return "com/google/gson/JsonPrimitive"; };
|
||||
|
||||
static value convert(JNIEnv&, jni::Object<JsonPrimitive>);
|
||||
|
||||
static bool isBoolean(JNIEnv&, jni::Object<JsonPrimitive>);
|
||||
|
||||
static bool isString(JNIEnv&, jni::Object<JsonPrimitive>);
|
||||
|
||||
static bool isNumber(JNIEnv&, jni::Object<JsonPrimitive>);
|
||||
|
||||
static bool getAsBoolean(JNIEnv&, jni::Object<JsonPrimitive>);
|
||||
|
||||
static std::string getAsString(JNIEnv&, jni::Object<JsonPrimitive>);
|
||||
|
||||
static double getAsDouble(JNIEnv&, jni::Object<JsonPrimitive>);
|
||||
|
||||
static jni::Class<JsonPrimitive> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -6,9 +6,15 @@ namespace java {
|
||||
namespace util {
|
||||
|
||||
jni::Class<List> List::javaClass;
|
||||
jni::Class<Set> Set::javaClass;
|
||||
jni::Class<Map> Map::javaClass;
|
||||
jni::Class<Map::Entry> Map::Entry::javaClass;
|
||||
|
||||
void registerNative(jni::JNIEnv& env) {
|
||||
List::javaClass = *jni::Class<List>::Find(env).NewGlobalRef(env).release();
|
||||
Set::javaClass = *jni::Class<Set>::Find(env).NewGlobalRef(env).release();
|
||||
Map::javaClass = *jni::Class<Map>::Find(env).NewGlobalRef(env).release();
|
||||
Map::Entry::javaClass = *jni::Class<Map::Entry>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,48 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class Set : private mbgl::util::noncopyable {
|
||||
public:
|
||||
|
||||
static constexpr auto Name() { return "java/util/Set"; };
|
||||
|
||||
template<class T>
|
||||
static jni::Array<jni::Object<T>> toArray(jni::JNIEnv& env, jni::Object<Set> list) {
|
||||
static auto toArray = Set::javaClass.GetMethod<jni::Array<jni::Object<>> ()>(env, "toArray");
|
||||
return (jni::Array<jni::Object<T>>) list.Call(env, toArray);
|
||||
};
|
||||
|
||||
static jni::Class<Set> javaClass;
|
||||
|
||||
};
|
||||
|
||||
class Map : private mbgl::util::noncopyable {
|
||||
public:
|
||||
|
||||
class Entry : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "java/util/Map$Entry"; };
|
||||
|
||||
template <class T>
|
||||
static jni::Object<T> getKey(jni::JNIEnv& env, jni::Object<Entry> entry) {
|
||||
static auto method = Entry::javaClass.GetMethod<jni::Object<> ()>(env, "getKey");
|
||||
return (jni::Object<T>) entry.Call(env, method);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static jni::Object<T> getValue(jni::JNIEnv& env, jni::Object<Entry> entry) {
|
||||
static auto method = Entry::javaClass.GetMethod<jni::Object<> ()>(env, "getValue");
|
||||
return (jni::Object<T>) entry.Call(env, method).Get();
|
||||
}
|
||||
|
||||
static jni::Class<Entry> javaClass;
|
||||
};
|
||||
|
||||
static constexpr auto Name() { return "java/util/Map"; };
|
||||
|
||||
static jni::Class<Map> javaClass;
|
||||
};
|
||||
|
||||
void registerNative(jni::JNIEnv&);
|
||||
|
||||
|
||||
|
||||
@@ -11,12 +11,25 @@
|
||||
#include "conversion/conversion.hpp"
|
||||
#include "conversion/collection.hpp"
|
||||
#include "file_source.hpp"
|
||||
#include "geometry/feature.hpp"
|
||||
#include "geojson/feature.hpp"
|
||||
#include "geojson/feature_collection.hpp"
|
||||
#include "geojson/geometry.hpp"
|
||||
#include "geojson/line_string.hpp"
|
||||
#include "geojson/multi_line_string.hpp"
|
||||
#include "geojson/multi_point.hpp"
|
||||
#include "geojson/multi_polygon.hpp"
|
||||
#include "geojson/point.hpp"
|
||||
#include "geojson/polygon.hpp"
|
||||
#include "geojson/position.hpp"
|
||||
#include "geometry/lat_lng.hpp"
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
#include "geometry/projected_meters.hpp"
|
||||
#include "graphics/pointf.hpp"
|
||||
#include "graphics/rectf.hpp"
|
||||
#include "gson/json_array.hpp"
|
||||
#include "gson/json_element.hpp"
|
||||
#include "gson/json_object.hpp"
|
||||
#include "gson/json_primitive.hpp"
|
||||
#include "java_types.hpp"
|
||||
#include "native_map_view.hpp"
|
||||
#include "offline/offline_manager.hpp"
|
||||
@@ -97,12 +110,29 @@ void registerNatives(JavaVM *vm) {
|
||||
PointF::registerNative(env);
|
||||
RectF::registerNative(env);
|
||||
|
||||
// GeoJSON
|
||||
geojson::Feature::registerNative(env);
|
||||
geojson::FeatureCollection::registerNative(env);
|
||||
geojson::Geometry::registerNative(env);
|
||||
geojson::LineString::registerNative(env);
|
||||
geojson::MultiLineString::registerNative(env);
|
||||
geojson::MultiPoint::registerNative(env);
|
||||
geojson::MultiPolygon::registerNative(env);
|
||||
geojson::Point::registerNative(env);
|
||||
geojson::Polygon::registerNative(env);
|
||||
geojson::Position::registerNative(env);
|
||||
|
||||
// Geometry
|
||||
Feature::registerNative(env);
|
||||
LatLng::registerNative(env);
|
||||
LatLngBounds::registerNative(env);
|
||||
ProjectedMeters::registerNative(env);
|
||||
|
||||
// GSon
|
||||
gson::JsonArray::registerNative(env);
|
||||
gson::JsonElement::registerNative(env);
|
||||
gson::JsonObject::registerNative(env);
|
||||
gson::JsonPrimitive::registerNative(env);
|
||||
|
||||
//Annotation
|
||||
Marker::registerNative(env);
|
||||
Polygon::registerNative(env);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "conversion/conversion.hpp"
|
||||
#include "conversion/collection.hpp"
|
||||
#include "style/conversion/filter.hpp"
|
||||
#include "geometry/conversion/feature.hpp"
|
||||
#include "geojson/conversion/feature.hpp"
|
||||
|
||||
#include "jni.hpp"
|
||||
#include "attach_env.hpp"
|
||||
@@ -793,32 +793,35 @@ jni::Array<jlong> NativeMapView::queryPointAnnotations(JNIEnv& env, jni::Object<
|
||||
return result;
|
||||
}
|
||||
|
||||
jni::Array<jni::Object<Feature>> NativeMapView::queryRenderedFeaturesForPoint(JNIEnv& env, jni::jfloat x, jni::jfloat y,
|
||||
jni::Array<jni::Object<geojson::Feature>> NativeMapView::queryRenderedFeaturesForPoint(JNIEnv& env, jni::jfloat x, jni::jfloat y,
|
||||
jni::Array<jni::String> layerIds,
|
||||
jni::Array<jni::Object<>> jfilter) {
|
||||
using namespace mbgl::android::conversion;
|
||||
using namespace mapbox::geometry;
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
mbgl::optional<std::vector<std::string>> layers;
|
||||
if (layerIds != nullptr && layerIds.Length(env) > 0) {
|
||||
layers = android::conversion::toVector(env, layerIds);
|
||||
}
|
||||
point<double> point = {x, y};
|
||||
mapbox::geometry::point<double> point = {x, y};
|
||||
|
||||
return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, map->queryRenderedFeatures(point, { layers, toFilter(env, jfilter) }));
|
||||
}
|
||||
|
||||
jni::Array<jni::Object<Feature>> NativeMapView::queryRenderedFeaturesForBox(JNIEnv& env, jni::jfloat left, jni::jfloat top,
|
||||
jni::Array<jni::Object<geojson::Feature>> NativeMapView::queryRenderedFeaturesForBox(JNIEnv& env, jni::jfloat left, jni::jfloat top,
|
||||
jni::jfloat right, jni::jfloat bottom, jni::Array<jni::String> layerIds,
|
||||
jni::Array<jni::Object<>> jfilter) {
|
||||
using namespace mbgl::android::conversion;
|
||||
using namespace mapbox::geometry;
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
mbgl::optional<std::vector<std::string>> layers;
|
||||
if (layerIds != nullptr && layerIds.Length(env) > 0) {
|
||||
layers = toVector(env, layerIds);
|
||||
}
|
||||
box<double> box = { point<double>{ left, top}, point<double>{ right, bottom } };
|
||||
mapbox::geometry::box<double> box = {
|
||||
mapbox::geometry::point<double>{ left, top},
|
||||
mapbox::geometry::point<double>{ right, bottom }
|
||||
};
|
||||
|
||||
return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, map->queryRenderedFeatures(box, { layers, toFilter(env, jfilter) }));
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "annotation/polyline.hpp"
|
||||
#include "graphics/pointf.hpp"
|
||||
#include "graphics/rectf.hpp"
|
||||
#include "geometry/feature.hpp"
|
||||
#include "geojson/feature.hpp"
|
||||
#include "geometry/lat_lng.hpp"
|
||||
#include "geometry/projected_meters.hpp"
|
||||
#include "style/layers/layers.hpp"
|
||||
@@ -222,11 +222,11 @@ public:
|
||||
|
||||
jni::Array<jlong> queryPointAnnotations(JNIEnv&, jni::Object<RectF>);
|
||||
|
||||
jni::Array<jni::Object<Feature>> queryRenderedFeaturesForPoint(JNIEnv&, jni::jfloat, jni::jfloat,
|
||||
jni::Array<jni::Object<geojson::Feature>> queryRenderedFeaturesForPoint(JNIEnv&, jni::jfloat, jni::jfloat,
|
||||
jni::Array<jni::String>,
|
||||
jni::Array<jni::Object<>> jfilter);
|
||||
|
||||
jni::Array<jni::Object<Feature>> queryRenderedFeaturesForBox(JNIEnv&, jni::jfloat, jni::jfloat, jni::jfloat,
|
||||
jni::Array<jni::Object<geojson::Feature>> queryRenderedFeaturesForBox(JNIEnv&, jni::jfloat, jni::jfloat, jni::jfloat,
|
||||
jni::jfloat, jni::Array<jni::String>,
|
||||
jni::Array<jni::Object<>> jfilter);
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../value.hpp"
|
||||
|
||||
#include <mapbox/geojson.hpp>
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
#include <mbgl/style/conversion/geojson.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -14,14 +11,13 @@ namespace conversion {
|
||||
|
||||
template <>
|
||||
optional<GeoJSON> convertGeoJSON(const mbgl::android::Value& value, Error& error) {
|
||||
// Value should be a string wrapped in an object
|
||||
mbgl::android::Value jsonValue = value.get("data");
|
||||
if(value.isNull()) {
|
||||
|
||||
if(value.isNull() || !value.isString()) {
|
||||
error = { "no json data found" };
|
||||
return {};
|
||||
}
|
||||
|
||||
return convertGeoJSON(value.get("data").toString(), error);
|
||||
return convertGeoJSON(value.toString(), error);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
// C++ -> Java conversion
|
||||
#include "../../conversion/conversion.hpp"
|
||||
#include "../../conversion/collection.hpp"
|
||||
#include "../../geometry/conversion/feature.hpp"
|
||||
|
||||
#include "../../geojson/conversion/feature.hpp"
|
||||
#include "../conversion/url_or_tileset.hpp"
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
#include <mbgl/style/conversion/geojson_options.hpp>
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace android {
|
||||
|
||||
GeoJSONSource::~GeoJSONSource() = default;
|
||||
|
||||
void GeoJSONSource::setGeoJSON(jni::JNIEnv& env, jni::Object<> json) {
|
||||
void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, jni::String json) {
|
||||
using namespace mbgl::style::conversion;
|
||||
|
||||
// Convert the jni object
|
||||
@@ -62,15 +62,25 @@ namespace android {
|
||||
source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setGeoJSON(*converted);
|
||||
}
|
||||
|
||||
void GeoJSONSource::setFeatureCollection(jni::JNIEnv& env, jni::Object<geojson::FeatureCollection> jFeatures) {
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
// Convert the jni object
|
||||
auto features = FeatureCollection::convert(env, jFeatures);
|
||||
|
||||
// Update the core source
|
||||
source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setGeoJSON(GeoJSON(features));
|
||||
}
|
||||
|
||||
void GeoJSONSource::setURL(jni::JNIEnv& env, jni::String url) {
|
||||
// Update the core source
|
||||
source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setURL(jni::Make<std::string>(env, url));
|
||||
}
|
||||
|
||||
jni::Array<jni::Object<Feature>> GeoJSONSource::querySourceFeatures(jni::JNIEnv& env,
|
||||
jni::Array<jni::Object<geojson::Feature>> GeoJSONSource::querySourceFeatures(jni::JNIEnv& env,
|
||||
jni::Array<jni::Object<>> jfilter) {
|
||||
using namespace mbgl::android::conversion;
|
||||
using namespace mapbox::geometry;
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
auto filter = toFilter(env, jfilter);
|
||||
auto features = source.querySourceFeatures({ {}, filter });
|
||||
@@ -96,7 +106,8 @@ namespace android {
|
||||
std::make_unique<GeoJSONSource, JNIEnv&, jni::String, jni::Object<>>,
|
||||
"initialize",
|
||||
"finalize",
|
||||
METHOD(&GeoJSONSource::setGeoJSON, "nativeSetGeoJson"),
|
||||
METHOD(&GeoJSONSource::setGeoJSONString, "nativeSetGeoJsonString"),
|
||||
METHOD(&GeoJSONSource::setFeatureCollection, "nativeSetFeatureCollection"),
|
||||
METHOD(&GeoJSONSource::setURL, "nativeSetUrl"),
|
||||
METHOD(&GeoJSONSource::querySourceFeatures, "querySourceFeatures")
|
||||
);
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
#include "source.hpp"
|
||||
#include <mbgl/style/sources/geojson_source.hpp>
|
||||
#include "../../geometry/feature.hpp"
|
||||
#include "../../geojson/feature.hpp"
|
||||
#include "../../geojson/feature_collection.hpp"
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -23,11 +24,14 @@ public:
|
||||
|
||||
~GeoJSONSource();
|
||||
|
||||
void setGeoJSON(jni::JNIEnv&, jni::Object<>);
|
||||
void setGeoJSONString(jni::JNIEnv&, jni::String);
|
||||
|
||||
void setFeatureCollection(jni::JNIEnv&, jni::Object<geojson::FeatureCollection>);
|
||||
|
||||
void setURL(jni::JNIEnv&, jni::String);
|
||||
|
||||
jni::Array<jni::Object<Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::Object<>> jfilter);
|
||||
jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&,
|
||||
jni::Array<jni::Object<>> jfilter);
|
||||
|
||||
jni::jobject* createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// C++ -> Java conversion
|
||||
#include "../../conversion/conversion.hpp"
|
||||
#include "../../conversion/collection.hpp"
|
||||
#include "../../geometry/conversion/feature.hpp"
|
||||
#include "../../geojson/conversion/feature.hpp"
|
||||
#include "../conversion/url_or_tileset.hpp"
|
||||
|
||||
#include <mbgl/util/variant.hpp>
|
||||
@@ -34,11 +34,11 @@ namespace android {
|
||||
|
||||
VectorSource::~VectorSource() = default;
|
||||
|
||||
jni::Array<jni::Object<Feature>> VectorSource::querySourceFeatures(jni::JNIEnv& env,
|
||||
jni::Array<jni::Object<geojson::Feature>> VectorSource::querySourceFeatures(jni::JNIEnv& env,
|
||||
jni::Array<jni::String> jSourceLayerIds,
|
||||
jni::Array<jni::Object<>> jfilter) {
|
||||
using namespace mbgl::android::conversion;
|
||||
using namespace mapbox::geometry;
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
mbgl::optional<std::vector<std::string>> sourceLayerIds = { toVector(env, jSourceLayerIds) };
|
||||
auto filter = toFilter(env, jfilter);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "source.hpp"
|
||||
#include <mbgl/style/sources/vector_source.hpp>
|
||||
#include "../../geometry/feature.hpp"
|
||||
#include "../../geojson/feature.hpp"
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -23,8 +23,8 @@ public:
|
||||
|
||||
~VectorSource();
|
||||
|
||||
jni::Array<jni::Object<Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::String>,
|
||||
jni::Array<jni::Object<>> jfilter);
|
||||
jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::String>,
|
||||
jni::Array<jni::Object<>> jfilter);
|
||||
|
||||
jni::jobject* createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace android {
|
||||
|
||||
// Instance
|
||||
|
||||
Value::Value(jni::JNIEnv& env, jni::jobject* _value) : jenv(env), value(_value, ObjectDeleter(env)) {}
|
||||
Value::Value(jni::JNIEnv& _env, jni::jobject* _value) : env(_env), value(_value, ObjectDeleter(env)) {}
|
||||
|
||||
Value::~Value() = default;
|
||||
|
||||
@@ -31,59 +31,59 @@ namespace android {
|
||||
}
|
||||
|
||||
bool Value::isArray() const {
|
||||
return jni::IsInstanceOf(jenv, value.get(), *java::ObjectArray::jclass);
|
||||
return jni::IsInstanceOf(env, value.get(), *java::ObjectArray::jclass);
|
||||
}
|
||||
|
||||
bool Value::isObject() const {
|
||||
return jni::IsInstanceOf(jenv, value.get(), *java::Map::jclass);;
|
||||
return jni::IsInstanceOf(env, value.get(), *java::Map::jclass);;
|
||||
}
|
||||
|
||||
bool Value::isString() const {
|
||||
return jni::IsInstanceOf(jenv, value.get(), *java::String::jclass);
|
||||
return jni::IsInstanceOf(env, value.get(), *java::String::jclass);
|
||||
}
|
||||
|
||||
bool Value::isBool() const {
|
||||
return jni::IsInstanceOf(jenv, value.get(), *java::Boolean::jclass);
|
||||
return jni::IsInstanceOf(env, value.get(), *java::Boolean::jclass);
|
||||
}
|
||||
|
||||
bool Value::isNumber() const {
|
||||
return jni::IsInstanceOf(jenv, value.get(), *java::Number::jclass);
|
||||
return jni::IsInstanceOf(env, value.get(), *java::Number::jclass);
|
||||
}
|
||||
|
||||
std::string Value::toString() const {
|
||||
jni::jstring* string = reinterpret_cast<jni::jstring*>(value.get());
|
||||
return jni::Make<std::string>(jenv, jni::String(string));
|
||||
return jni::Make<std::string>(env, jni::String(string));
|
||||
}
|
||||
|
||||
float Value::toFloat() const {
|
||||
return jni::CallMethod<jni::jfloat>(jenv, value.get(), *java::Number::floatValueMethodId);
|
||||
return jni::CallMethod<jni::jfloat>(env, value.get(), *java::Number::floatValueMethodId);
|
||||
}
|
||||
|
||||
double Value::toDouble() const {
|
||||
return jni::CallMethod<jni::jdouble>(jenv, value.get(), *java::Number::doubleValueMethodId);
|
||||
return jni::CallMethod<jni::jdouble>(env, value.get(), *java::Number::doubleValueMethodId);
|
||||
}
|
||||
|
||||
long Value::toLong() const {
|
||||
return jni::CallMethod<jni::jlong>(jenv, value.get(), *java::Number::longValueMethodId);
|
||||
return jni::CallMethod<jni::jlong>(env, value.get(), *java::Number::longValueMethodId);
|
||||
}
|
||||
|
||||
bool Value::toBool() const {
|
||||
return jni::CallMethod<jni::jboolean>(jenv, value.get(), *java::Boolean::booleanValueMethodId);
|
||||
return jni::CallMethod<jni::jboolean>(env, value.get(), *java::Boolean::booleanValueMethodId);
|
||||
}
|
||||
|
||||
Value Value::get(const char* key) const {
|
||||
jni::jobject* member = jni::CallMethod<jni::jobject*>(jenv, value.get(), *java::Map::getMethodId, jni::Make<jni::String>(jenv, std::string(key)).Get());
|
||||
return Value(jenv, member);
|
||||
jni::jobject* member = jni::CallMethod<jni::jobject*>(env, value.get(), *java::Map::getMethodId, jni::Make<jni::String>(env, std::string(key)).Get());
|
||||
return Value(env, member);
|
||||
}
|
||||
|
||||
int Value::getLength() const {
|
||||
auto array = (jni::jarray<jni::jobject>*) value.get();
|
||||
return jni::GetArrayLength(jenv, *array);
|
||||
return jni::GetArrayLength(env, *array);
|
||||
}
|
||||
|
||||
Value Value::get(const int index ) const {
|
||||
Value Value::get(const int index) const {
|
||||
auto array = (jni::jarray<jni::jobject>*) value.get();
|
||||
return Value(jenv, jni::GetObjectArrayElement(jenv, *array, index));
|
||||
return Value(env, jni::GetObjectArrayElement(env, *array, index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,7 @@ public:
|
||||
int getLength() const;
|
||||
Value get(const int index ) const;
|
||||
|
||||
private:
|
||||
|
||||
jni::JNIEnv& jenv;
|
||||
jni::JNIEnv& env;
|
||||
std::shared_ptr<jni::jobject> value;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user