std::array<mbgl::LatLng, 4> LatLngQuad::getLatLngArray(jni::JNIEnv& env, jni::Object<LatLngQuad> quad) {
    static auto topLeftField = LatLngQuad::javaClass.GetField <jni::Object<LatLng>>(env, "topLeft");
    static auto topRightField = LatLngQuad::javaClass.GetField <jni::Object<LatLng>>(env, "topRight");
    static auto bottomRightField = LatLngQuad::javaClass.GetField <jni::Object<LatLng>>(env, "bottomRight");
    static auto bottomLeftField = LatLngQuad::javaClass.GetField <jni::Object<LatLng>>(env, "bottomLeft");

    return std::array < mbgl::LatLng, 4 > {{
        LatLng::getLatLng(env, quad.Get(env, topLeftField)),
        LatLng::getLatLng(env, quad.Get(env, topRightField)),
        LatLng::getLatLng(env, quad.Get(env, bottomRightField)),
        LatLng::getLatLng(env, quad.Get(env, bottomLeftField))
    }};
}
Example #2
0
mbgl::Point<double> Point::convert(jni::JNIEnv &env, const jni::Object<Point>& jPoint) {
    static auto& javaClass = jni::Class<Point>::Singleton(env);
    static auto longitude = javaClass.GetMethod<jni::jdouble ()>(env, "longitude");
    static auto latitude = javaClass.GetMethod<jni::jdouble ()>(env, "latitude");

    if (!jPoint) {
        return {};
    }

    return {
        jPoint.Call(env, longitude),
        jPoint.Call(env, latitude)
    };
}
Example #3
0
mbgl::Feature Feature::convert(jni::JNIEnv& env, const jni::Object<Feature>& jFeature) {
    static auto& javaClass = jni::Class<Feature>::Singleton(env);
    static auto id = javaClass.GetMethod<jni::String ()>(env, "id");
    static auto geometry = javaClass.GetMethod<jni::Object<Geometry> ()>(env, "geometry");
    static auto properties = javaClass.GetMethod<jni::Object<gson::JsonObject> ()>(env, "properties");

    auto jId = jFeature.Call(env, id);

    return mbgl::Feature {
        Geometry::convert(env, jFeature.Call(env, geometry)),
        JsonObject::convert(env, jFeature.Call(env, properties)),
        jId ? std::experimental::optional<mapbox::geometry::identifier>(jni::Make<std::string>(env, jId))
            : std::experimental::nullopt
    };
}
Example #4
0
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;
}
Example #5
0
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;
}
Example #6
0
void FileSource::setResourceTransform(jni::JNIEnv& env, jni::Object<FileSource::ResourceTransformCallback> transformCallback) {
    if (transformCallback) {
        resourceTransform = std::make_unique<Actor<ResourceTransform>>(*util::RunLoop::Get(),
            // Capture the ResourceTransformCallback object as a managed global into
            // the lambda. It is released automatically when we're setting a new ResourceTransform in
            // a subsequent call.
            // Note: we're converting it to shared_ptr because this lambda is converted to a std::function,
            // which requires copyability of its captured variables.
            [callback = std::shared_ptr<jni::jobject>(transformCallback.NewGlobalRef(env).release()->Get(), GenericGlobalRefDeleter())]
            (mbgl::Resource::Kind kind, const std::string&& url_) {
                android::UniqueEnv _env = android::AttachEnv();
                return FileSource::ResourceTransformCallback::onURL(*_env, jni::Object<FileSource::ResourceTransformCallback>(*callback), int(kind), url_);
            });
        fileSource->setResourceTransform(resourceTransform->self());
    } else {
        // Reset the callback
        resourceTransform.reset();
        fileSource->setResourceTransform({});
    }
}
Example #7
0
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);
}
Example #8
0
std::string Geometry::getType(jni::JNIEnv &env, const jni::Object<Geometry>& jGeometry) {
    static auto& javaClass = jni::Class<Geometry>::Singleton(env);
    static auto method = javaClass.GetMethod<jni::String ()>(env, "type");
    return jni::Make<std::string>(env, jGeometry.Call(env, method));
}
mbgl::Color Polygon::getOutlineColor(jni::JNIEnv& env, jni::Object<Polygon> polygon) {
    static auto field = Polygon::javaClass.GetField<int>(env, "strokeColor");
    return *conversion::convert<mbgl::Color, int>(env, polygon.Get(env, field));
}
float Polygon::getOpacity(jni::JNIEnv& env, jni::Object<Polygon> polygon) {
    static auto field = Polygon::javaClass.GetField<float>(env, "alpha");
    return polygon.Get(env, field);
}
jni::Object<java::util::List> Polygon::getHoles(jni::JNIEnv& env, jni::Object<Polygon> polygon) {
    static auto field = Polygon::javaClass.GetField<jni::Object<java::util::List>>(env, "holes");
    return polygon.Get(env, field);
}
Example #12
0
float RectF::getLeft(jni::JNIEnv& env, const jni::Object<RectF>& rectf) {
    static auto& javaClass = jni::Class<RectF>::Singleton(env);
    static auto field = javaClass.GetField<float>(env, "left");
    return rectf.Get(env, field);
}
jni::Object<java::util::List> Point::coordinates(jni::JNIEnv &env, jni::Object<Point> jPoint) {
     static auto method = Point::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "coordinates");
     return jPoint.Call(env, method);
}
Example #14
0
std::string FileSource::ResourceTransformCallback::onURL(jni::JNIEnv& env, jni::Object<FileSource::ResourceTransformCallback> callback, int kind, std::string url_) {
    static auto method = FileSource::ResourceTransformCallback::javaClass.GetMethod<jni::String (jni::jint, jni::String)>(env, "onURL");
    auto url = jni::Make<jni::String>(env, url_);
    url = callback.Call(env, method, kind, url);
    return jni::Make<std::string>(env, url);
}
MapRenderer::MapRenderer(jni::JNIEnv& _env, jni::Object<MapRenderer> obj,
                         jni::Object<FileSource> _fileSource, jni::jfloat pixelRatio_,
                         jni::String programCacheDir_,
                         jni::String localIdeographFontFamily_)
        : javaPeer(SeizeGenericWeakRef(_env, jni::Object<MapRenderer>(jni::NewWeakGlobalRef(_env, obj.Get()).release()))), pixelRatio(pixelRatio_)
        , fileSource(FileSource::getDefaultFileSource(_env, _fileSource))
        , programCacheDir(jni::Make<std::string>(_env, programCacheDir_))
        , localIdeographFontFamily(localIdeographFontFamily_ == nullptr ? optional<std::string>{} : jni::Make<std::string>(_env, localIdeographFontFamily_ ))
        , threadPool(sharedThreadPool())
        , mailbox(std::make_shared<Mailbox>(*this)) {
}