Replacing hardcoded configuration with configurable API and removing Mapbox assets (#90)

* Refactoring online file source so that tile server configuration is not hardcoded - part 1

* Added default templates

* Update from master

* Renaming MGLAccountManager to MGLSettings. Passing ResourceOptions and TileServerOptions to relevant classes and method in order to remove mapbox hardocded configuration

* Fixing build

* Addedm missing theme

* Unit tests fixes

* Fixing unit tests, adding factory methods for creating predefined configuration.

* Fixing mapbox unit tests

* Additional unit test fixes

* Making MapboxConfiguration default

* Making get/set resource options available in all classes that inherits from FileSource

* Making get/set resource options available in all classes that inherits from FileSource - part 2

* Fixes for Android

* Disable test coverage reports

* Disable test coverage reports

* Disable test coverage reports

* Disable test coverage reports

* Removing hardcoded configuration in iOS project - part 1

* Fixing wrong file extension, making use of tile server options.

* Use apiKey and MGL_API_KEY everywhere

* Just a rename

* Re-enabling tests and improving MGLSettings init

* Removing mapbox hardcoded configuration, using api key everywhere, implementing JNI conversion for TileServerOptions

* Lint issues.

* Integrating configurable tile server properties into Android SDK - part 2

* Removing mabox accounts

* Exposing multiple configurations to Android SDK - bug fixes

* Removing TileServerOptions from public interface - native methods dont work before mapbox-gl library is loaded

* Adding support for configurable predefined styles

* Migrating predefined styles in test app + cleanup

* Parameter fix

* Bug fixes

* Fixing render test build

* Fixing offline tester

* Fixing benchmark tool

* Fix: typo in method name

* Adding code for public access to TileServerOptions

* Bug fixes and debug code removal

* Fixes for macOS, adding unit tests from MapLibre, removing redundant members from OnlineFileSource

* Unit test fixes

* MacOS test app - migrating to configurable tile server options, part 1

* Fixing offline maps

* Migrating macOS test app to MapTiler

* Minor improvements

* Putting back apiKey test

* Added unit tests for MapTiler configuration

* Migrating test resources to MapTiler

* minor fix

* A few fixes

* Fixing macOS tests, removing feedback functionality

* Migrating ios test app to MapTiler

* Migrating ui tests

* UI tests fix

* Benchmarking app fix

* Cleanup and strings updates

* Migrating benchmark app to maptiler

* API key injection in benchmark app

* Putting back release configuration

* Additional tests and fixing issues identified by thread sanitizer.

* Removing test filters

* Fixes and addressing lint issues

* More Maptiler tests + minro fix

* Android instrumentation test migration to MapTiler. Exposing missing TileServerOptions in Android SDK. Minor fixes.

* No requirements on API key format.

* Fixing offline cache test tool

* Adding configurable domain name for sources, adding source domain int MapTiler configuration, cleanup

* Migrating tests to MapTiler, adding code for canonicalizing URLs, removing mapbox stuff from comments, cleanup

* More tests

* Updated database size

* Lint issues

* Fixed test

* Updating developer config API key

* Fixes for Android, propagaing updated tileServerOptions to native file sources, more tests

* Just a few more fixes

* Propagating updated settings to file sources + additional unit test

* Lint issues

* Removing test filter and fixing incorrect uri

* Release preparation

* macos release notes
This commit is contained in:
Petr Pokorny
2021-06-29 12:44:51 +02:00
committed by GitHub
parent 9a49fa16c9
commit d62ff400c6
398 changed files with 107907 additions and 184517 deletions

View File

@@ -183,7 +183,11 @@ add_library(mapbox-gl SHARED
${PROJECT_SOURCE_DIR}/style/transition_options.cpp
${PROJECT_SOURCE_DIR}/style/transition_options.hpp
${PROJECT_SOURCE_DIR}/style/value.cpp
${PROJECT_SOURCE_DIR}/style/value.hpp)
${PROJECT_SOURCE_DIR}/style/value.hpp
${PROJECT_SOURCE_DIR}/util/default_style.cpp
${PROJECT_SOURCE_DIR}/util/tile_server_options.cpp
${PROJECT_SOURCE_DIR}/util/default_style.hpp
${PROJECT_SOURCE_DIR}/util/tile_server_options.hpp)
target_include_directories(
mapbox-gl

View File

@@ -3,6 +3,7 @@
#include <mbgl/platform/settings.hpp>
#include <mbgl/storage/file_source_request.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/thread.hpp>
#include <mbgl/util/url.hpp>
@@ -15,8 +16,9 @@ namespace mbgl {
class AssetManagerFileSource::Impl {
public:
Impl(ActorRef<Impl>, AAssetManager* assetManager_) : assetManager(assetManager_) {
}
Impl(ActorRef<Impl>, AAssetManager* assetManager_, const ResourceOptions options) :
resourceOptions(options.clone()),
assetManager(assetManager_) {}
void request(const std::string& url, ActorRef<FileSourceRequest> req) {
// Note: AssetManager already prepends "assets" to the filename.
@@ -36,17 +38,28 @@ public:
req.invoke(&FileSourceRequest::setResponse, response);
}
void setResourceOptions(ResourceOptions options) {
resourceOptions = options;
}
ResourceOptions getResourceOptions() {
return resourceOptions.clone();
}
private:
AAssetManager* assetManager;
ResourceOptions resourceOptions;
};
AssetManagerFileSource::AssetManagerFileSource(jni::JNIEnv& env,
const jni::Object<android::AssetManager>& assetManager_)
const jni::Object<android::AssetManager>& assetManager_,
const ResourceOptions options)
: assetManager(jni::NewGlobal(env, assetManager_)),
impl(std::make_unique<util::Thread<Impl>>(
util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_FILE),
"AssetManagerFileSource",
AAssetManager_fromJava(&env, jni::Unwrap(assetManager.get())))) {}
AAssetManager_fromJava(&env, jni::Unwrap(assetManager.get())),
options.clone())) {}
AssetManagerFileSource::~AssetManagerFileSource() = default;
@@ -62,4 +75,11 @@ bool AssetManagerFileSource::canRequest(const Resource& resource) const {
return 0 == resource.url.rfind(mbgl::util::ASSET_PROTOCOL, 0);
}
void AssetManagerFileSource::setResourceOptions(ResourceOptions options) {
impl->actor().invoke(&Impl::setResourceOptions, options.clone());
}
ResourceOptions AssetManagerFileSource::getResourceOptions() {
return impl->actor().ask(&Impl::getResourceOptions).get();
}
} // namespace mbgl

View File

@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/storage/file_source.hpp>
#include <mbgl/storage/resource_options.hpp>
#include "asset_manager.hpp"
@@ -14,12 +15,15 @@ template <typename T> class Thread;
class AssetManagerFileSource : public FileSource {
public:
AssetManagerFileSource(jni::JNIEnv&, const jni::Object<android::AssetManager>&);
AssetManagerFileSource(jni::JNIEnv&, const jni::Object<android::AssetManager>&, const ResourceOptions);
~AssetManagerFileSource() override;
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
bool canRequest(const Resource&) const override;
void setResourceOptions(ResourceOptions options) override;
ResourceOptions getResourceOptions() override;
private:
class Impl;

View File

@@ -19,24 +19,27 @@ namespace android {
// FileSource //
FileSource::FileSource(jni::JNIEnv& _env, const jni::String& accessToken, const jni::String& _cachePath)
FileSource::FileSource(jni::JNIEnv& _env, const jni::String& apiKey, const jni::String& _cachePath, const jni::Object<TileServerOptions>& _options)
:activationCounter( optional<int>(1)) {
std::string path = jni::Make<std::string>(_env, _cachePath);
mapbox::sqlite::setTempPath(path);
mbgl::FileSourceManager::get()->registerFileSourceFactory(
mbgl::FileSourceType::Asset, [](const mbgl::ResourceOptions&) {
mbgl::FileSourceType::Asset, [](const mbgl::ResourceOptions& opts) {
auto env{android::AttachEnv()};
std::unique_ptr<mbgl::FileSource> assetFileSource;
if (android::Mapbox::hasInstance(*env)) {
auto assetManager = android::Mapbox::getAssetManager(*env);
assetFileSource = std::make_unique<AssetManagerFileSource>(*env, assetManager);
assetFileSource = std::make_unique<AssetManagerFileSource>(*env, assetManager, opts.clone());
}
return assetFileSource;
});
resourceOptions.withAccessToken(accessToken ? jni::Make<std::string>(_env, accessToken) : "")
.withCachePath(path + DATABASE_FILE);
auto tileServerOptions = TileServerOptions::getTileServerOptions(_env, _options);
resourceOptions
.withTileServerOptions(tileServerOptions)
.withApiKey(apiKey ? jni::Make<std::string>(_env, apiKey) : "")
.withCachePath(path + DATABASE_FILE);
// Create a core file sources
// TODO: Split Android FileSource API to smaller interfaces
@@ -50,8 +53,16 @@ FileSource::FileSource(jni::JNIEnv& _env, const jni::String& accessToken, const
FileSource::~FileSource() {
}
jni::Local<jni::String> FileSource::getAccessToken(jni::JNIEnv& env) {
if (auto* token = onlineSource->getProperty(mbgl::ACCESS_TOKEN_KEY).getString()) {
void FileSource::setTileServerOptions(jni::JNIEnv& _env, const jni::Object<TileServerOptions>& _options) {
auto tileServerOptions = TileServerOptions::getTileServerOptions(_env, _options);
resourceOptions.withTileServerOptions(tileServerOptions);
resourceLoader->setResourceOptions(resourceOptions.clone());
databaseSource->setResourceOptions(resourceOptions.clone());
onlineSource->setResourceOptions(resourceOptions.clone());
}
jni::Local<jni::String> FileSource::getApiKey(jni::JNIEnv& env) {
if (auto* token = onlineSource->getProperty(mbgl::API_KEY_KEY).getString()) {
return jni::Make<jni::String>(env, *token);
}
@@ -59,9 +70,9 @@ jni::Local<jni::String> FileSource::getAccessToken(jni::JNIEnv& env) {
return jni::Make<jni::String>(env, "");
}
void FileSource::setAccessToken(jni::JNIEnv& env, const jni::String& token) {
void FileSource::setApiKey(jni::JNIEnv& env, const jni::String& token) {
if (onlineSource) {
onlineSource->setProperty(mbgl::ACCESS_TOKEN_KEY, token ? jni::Make<std::string>(env, token) : "");
onlineSource->setProperty(mbgl::API_KEY_KEY, token ? jni::Make<std::string>(env, token) : "");
} else {
ThrowNew(env, jni::FindClass(env, "java/lang/IllegalStateException"), "Online functionality is disabled.");
}
@@ -75,6 +86,15 @@ void FileSource::setAPIBaseUrl(jni::JNIEnv& env, const jni::String& url) {
}
}
jni::Local<jni::String> FileSource::getAPIBaseUrl(jni::JNIEnv& env) {
if (auto* url = onlineSource->getProperty(mbgl::API_BASE_URL_KEY).getString()) {
return jni::Make<jni::String>(env, *url);
}
ThrowNew(env, jni::FindClass(env, "java/lang/IllegalStateException"), "Online functionality is disabled.");
return jni::Make<jni::String>(env, "");
}
void FileSource::setResourceTransform(jni::JNIEnv& env, const jni::Object<FileSource::ResourceTransformCallback>& transformCallback) {
// Core could be built without support for network resource provider.
if (!onlineSource) {
@@ -214,12 +234,14 @@ void FileSource::registerNative(jni::JNIEnv& env) {
jni::RegisterNativePeer<FileSource>(env,
javaClass,
"nativePtr",
jni::MakePeer<FileSource, const jni::String&, const jni::String&>,
jni::MakePeer<FileSource, const jni::String&, const jni::String&, const jni::Object<TileServerOptions>&>,
"initialize",
"finalize",
METHOD(&FileSource::getAccessToken, "getAccessToken"),
METHOD(&FileSource::setAccessToken, "setAccessToken"),
METHOD(&FileSource::setTileServerOptions, "setTileServerOptions"),
METHOD(&FileSource::getApiKey, "getApiKey"),
METHOD(&FileSource::setApiKey, "setApiKey"),
METHOD(&FileSource::setAPIBaseUrl, "setApiBaseUrl"),
METHOD(&FileSource::getAPIBaseUrl, "getApiBaseUrl"),
METHOD(&FileSource::setResourceTransform, "setResourceTransform"),
METHOD(&FileSource::setResourceCachePath, "setResourceCachePath"),
METHOD(&FileSource::resume, "activate"),

View File

@@ -9,6 +9,8 @@
#include <jni/jni.hpp>
#include "util/tile_server_options.hpp"
namespace mbgl {
template <typename T> class Actor;
@@ -42,13 +44,17 @@ public:
const jni::String&);
};
FileSource(jni::JNIEnv&, const jni::String&, const jni::String&);
FileSource(jni::JNIEnv&, const jni::String&, const jni::String&, const jni::Object<TileServerOptions>&);
~FileSource();
jni::Local<jni::String> getAccessToken(jni::JNIEnv&);
void setTileServerOptions(jni::JNIEnv& _env, const jni::Object<TileServerOptions>& _options);
void setAccessToken(jni::JNIEnv&, const jni::String&);
jni::Local<jni::String> getApiKey(jni::JNIEnv&);
void setApiKey(jni::JNIEnv&, const jni::String&);
jni::Local<jni::String> getAPIBaseUrl(jni::JNIEnv&);
void setAPIBaseUrl(jni::JNIEnv&, const jni::String&);

View File

@@ -1,5 +1,6 @@
#include <mbgl/storage/http_file_source.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/logging.hpp>
@@ -16,7 +17,15 @@ namespace mbgl {
class HTTPFileSource::Impl {
public:
Impl(const ResourceOptions options): resourceOptions(options.clone()){};
android::UniqueEnv env { android::AttachEnv() };
void setResourceOptions(ResourceOptions options) {resourceOptions = options;};
ResourceOptions getResourceOptions() {return resourceOptions.clone(); };
private:
ResourceOptions resourceOptions;
};
class HTTPRequest : public AsyncRequest {
@@ -182,8 +191,8 @@ void HTTPRequest::onFailure(jni::JNIEnv& env, int type, const jni::String& messa
async.send();
}
HTTPFileSource::HTTPFileSource()
: impl(std::make_unique<Impl>()) {
HTTPFileSource::HTTPFileSource(const ResourceOptions& options)
: impl(std::make_unique<Impl>(options.clone())) {
}
HTTPFileSource::~HTTPFileSource() = default;
@@ -192,4 +201,12 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
return std::make_unique<HTTPRequest>(*impl->env, resource, callback);
}
void HTTPFileSource::setResourceOptions(ResourceOptions options) {
impl->setResourceOptions(options.clone());
}
ResourceOptions HTTPFileSource::getResourceOptions() {
return impl->getResourceOptions();
}
} // namespace mbgl

View File

@@ -34,6 +34,7 @@
#include "map_renderer_runnable.hpp"
#include "mapbox.hpp"
#include "native_map_view.hpp"
#include "util/tile_server_options.hpp"
#ifndef MBGL_MODULE_OFFLINE_DISABLE
#include "offline/offline_manager.hpp"
#include "offline/offline_region.hpp"
@@ -162,6 +163,10 @@ void registerNatives(JavaVM *vm) {
// AssetManager
Mapbox::registerNative(env);
// Util
DefaultStyle::registerNative(env);
TileServerOptions::registerNative(env);
}
} // namespace android

View File

@@ -0,0 +1,31 @@
#include "default_style.hpp"
namespace mbgl {
namespace android {
jni::Local<jni::Object<DefaultStyle>> DefaultStyle::New(jni::JNIEnv& env, const mbgl::util::DefaultStyle& jDefaultStyle) {
static auto& javaClass = jni::Class<DefaultStyle>::Singleton(env);
static auto constructor = javaClass.GetConstructor<jni::String, jni::String, int>(env);
return javaClass.New(
env,
constructor,
jni::Make<jni::String>(env, jDefaultStyle.getUrl()),
jni::Make<jni::String>(env, jDefaultStyle.getName()),
jDefaultStyle.getCurrentVersion());
}
mbgl::util::DefaultStyle DefaultStyle::getDefaultStyle(jni::JNIEnv& env, const jni::Object<DefaultStyle>& options) {
static auto& javaClass = jni::Class<DefaultStyle>::Singleton(env);
return mbgl::util::DefaultStyle (
jni::Make<std::string>(env, options.Get(env, javaClass.GetField<jni::String>(env, "url"))),
jni::Make<std::string>(env, options.Get(env, javaClass.GetField<jni::String>(env, "name"))),
options.Get(env, javaClass.GetField<int>(env, "version"))
);
}
void DefaultStyle::registerNative(jni::JNIEnv& env) {
jni::Class<DefaultStyle>::Singleton(env);
}
} // namespace android
} // namespace mbgl

View File

@@ -0,0 +1,25 @@
#pragma once
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/default_style.hpp>
#include <jni/jni.hpp>
namespace mbgl {
namespace android {
class DefaultStyle : private mbgl::util::noncopyable {
public:
static constexpr auto Name() { return "com/mapbox/mapboxsdk/util/DefaultStyle"; };
static jni::Local<jni::Object<DefaultStyle>> New(jni::JNIEnv&, const mbgl::util::DefaultStyle&);
static mbgl::util::DefaultStyle getDefaultStyle(jni::JNIEnv&, const jni::Object<DefaultStyle>&);
static void registerNative(jni::JNIEnv&);
};
} // namespace android
} // namespace mbgl

View File

@@ -0,0 +1,178 @@
#include "tile_server_options.hpp"
namespace mbgl {
namespace android {
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::New(jni::JNIEnv& env, const mbgl::TileServerOptions& tileServerOptions) {
static auto& javaClass = jni::Class<TileServerOptions>::Singleton(env);
static auto constructor = javaClass.GetConstructor<
jni::String, jni::String, jni::String, jni::String, jni::String, jni::String,
jni::String, jni::String, jni::String, jni::String, jni::String,
jni::String, jni::String, jni::String, jni::String, jni::String,
jni::String, jni::String, jni::jboolean, jni::String, jni::Array<jni::Object<DefaultStyle>>>(env);
optional<std::string> sourceVersionPrefixValue = tileServerOptions.sourceVersionPrefix();
optional<std::string> styleVersionPrefixValue = tileServerOptions.styleVersionPrefix();
optional<std::string> spritesVersionPrefixValue = tileServerOptions.spritesVersionPrefix();
optional<std::string> glyphsVersionPrefixValue = tileServerOptions.glyphsVersionPrefix();
optional<std::string> tileVersionPrefixValue = tileServerOptions.tileVersionPrefix();
return javaClass.New(env, constructor,
jni::Make<jni::String>(env, tileServerOptions.baseURL()),
jni::Make<jni::String>(env, tileServerOptions.uriSchemeAlias()),
jni::Make<jni::String>(env, tileServerOptions.sourceTemplate()),
jni::Make<jni::String>(env, tileServerOptions.sourceDomainName()),
sourceVersionPrefixValue ? jni::Make<jni::String>(env, *sourceVersionPrefixValue) : jni::Local<jni::String>(),
jni::Make<jni::String>(env, tileServerOptions.styleTemplate()),
jni::Make<jni::String>(env, tileServerOptions.styleDomainName()),
styleVersionPrefixValue ? jni::Make<jni::String>(env, *styleVersionPrefixValue) : jni::Local<jni::String>(),
jni::Make<jni::String>(env, tileServerOptions.spritesTemplate()),
jni::Make<jni::String>(env, tileServerOptions.spritesDomainName()),
spritesVersionPrefixValue ? jni::Make<jni::String>(env, *spritesVersionPrefixValue) : jni::Local<jni::String>(),
jni::Make<jni::String>(env, tileServerOptions.glyphsTemplate()),
jni::Make<jni::String>(env, tileServerOptions.glyphsDomainName()),
glyphsVersionPrefixValue ? jni::Make<jni::String>(env, *glyphsVersionPrefixValue) : jni::Local<jni::String>(),
jni::Make<jni::String>(env, tileServerOptions.tileTemplate()),
jni::Make<jni::String>(env, tileServerOptions.tileDomainName()),
tileVersionPrefixValue ? jni::Make<jni::String>(env, *tileVersionPrefixValue) : jni::Local<jni::String>(),
jni::Make<jni::String>(env, tileServerOptions.apiKeyParameterName()),
jni::jboolean(tileServerOptions.requiresApiKey()),
jni::Make<jni::String>(env, tileServerOptions.defaultStyle()),
TileServerOptions::NewStyles(env, tileServerOptions.defaultStyles())
);
}
jni::Local<jni::Array<jni::Object<DefaultStyle>>> TileServerOptions::NewStyles(jni::JNIEnv& env, const std::vector<const mbgl::util::DefaultStyle> nativeStyles) {
auto retVal = jni::Array<jni::Object<DefaultStyle>>::New(env, nativeStyles.size());
for (auto it = begin(nativeStyles); it != end(nativeStyles); ++it) {
auto converted = DefaultStyle::New(env, *it);
retVal.Set(env, it - nativeStyles.begin(), converted);
}
return retVal;
}
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::DefaultConfiguration(jni::JNIEnv& env, const jni::Class<TileServerOptions>& jOptions) {
auto options = mbgl::TileServerOptions::DefaultConfiguration();
return TileServerOptions::New(env, options);
}
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::MapboxConfiguration(jni::JNIEnv& env, const jni::Class<TileServerOptions>& jOptions) {
auto options = mbgl::TileServerOptions::MapboxConfiguration();
return TileServerOptions::New(env, options);
}
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::MapTilerConfiguration(jni::JNIEnv& env, const jni::Class<TileServerOptions>& jOptions) {
auto options = mbgl::TileServerOptions::MapTilerConfiguration();
return TileServerOptions::New(env, options);
}
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::MapLibreConfiguration(jni::JNIEnv& env, const jni::Class<TileServerOptions>& jOptions) {
auto options = mbgl::TileServerOptions::MapLibreConfiguration();
return TileServerOptions::New(env, options);
}
mbgl::TileServerOptions TileServerOptions::getTileServerOptions(jni::JNIEnv& env, const jni::Object<TileServerOptions>& options) {
auto opts = mbgl::TileServerOptions();
static auto& javaClass = jni::Class<TileServerOptions>::Singleton(env);
static auto baseURLField = javaClass.GetField<jni::String>(env, "baseURL");
static auto uriSchemeAliasField = javaClass.GetField<jni::String>(env, "uriSchemeAlias");
static auto sourceTemplateField = javaClass.GetField<jni::String>(env, "sourceTemplate");
static auto sourceDomainNameField = javaClass.GetField<jni::String>(env, "sourceDomainName");
static auto sourceVersionPrefixField = javaClass.GetField<jni::String>(env, "sourceVersionPrefix");
static auto styleTemplateField = javaClass.GetField<jni::String>(env, "styleTemplate");
static auto styleDomainNameField = javaClass.GetField<jni::String>(env, "styleDomainName");
static auto styleVersionPrefixField = javaClass.GetField<jni::String>(env, "styleVersionPrefix");
static auto spritesTemplateField = javaClass.GetField<jni::String>(env, "spritesTemplate");
static auto spritesDomainNameField = javaClass.GetField<jni::String>(env, "spritesDomainName");
static auto spritesVersionPrefixField = javaClass.GetField<jni::String>(env, "spritesVersionPrefix");
static auto glyphsTemplateField = javaClass.GetField<jni::String>(env, "glyphsTemplate");
static auto glyphsDomainNameField = javaClass.GetField<jni::String>(env, "glyphsDomainName");
static auto glyphsVersionPrefixField = javaClass.GetField<jni::String>(env, "glyphsVersionPrefix");
static auto tileTemplateField = javaClass.GetField<jni::String>(env, "tileTemplate");
static auto tileDomainNameField = javaClass.GetField<jni::String>(env, "tileDomainName");
static auto tileVersionPrefixField = javaClass.GetField<jni::String>(env, "tileVersionPrefix");
static auto apiKeyParameterNameField = javaClass.GetField<jni::String>(env, "apiKeyParameterName");
static auto apiKeyRequiredField = javaClass.GetField<jni::jboolean>(env, "apiKeyRequired");
static auto defaultStyleField = javaClass.GetField<jni::String>(env, "defaultStyle");
static auto defaultStylesField = javaClass.GetField<jni::Array<jni::Object<DefaultStyle>>>(env, "defaultStyles");
std::vector<const mbgl::util::DefaultStyle> defaultStyles = TileServerOptions::getDefaultStyles(env, options.Get(env, defaultStylesField));
auto retVal = mbgl::TileServerOptions()
.withBaseURL(jni::Make<std::string>(env, options.Get(env, baseURLField)))
.withUriSchemeAlias(jni::Make<std::string>(env, options.Get(env, uriSchemeAliasField)))
.withApiKeyParameterName(jni::Make<std::string>(env, options.Get(env, apiKeyParameterNameField)))
.setRequiresApiKey(options.Get(env, apiKeyRequiredField));
auto sourcePrefixValue = options.Get(env, sourceVersionPrefixField);
retVal.withSourceTemplate(
jni::Make<std::string>(env, options.Get(env, sourceTemplateField)),
jni::Make<std::string>(env, options.Get(env, sourceDomainNameField)),
sourcePrefixValue ? jni::Make<std::string>(env, sourcePrefixValue): optional<std::string>{});
auto styleVersionPrefixValue = options.Get(env, styleVersionPrefixField);
retVal.withStyleTemplate(
jni::Make<std::string>(env, options.Get(env, styleTemplateField)),
jni::Make<std::string>(env, options.Get(env, styleDomainNameField)),
styleVersionPrefixValue ? jni::Make<std::string>(env, styleVersionPrefixValue): optional<std::string>{});
auto spritesVersionPrefixValue = options.Get(env, spritesVersionPrefixField);
retVal.withSpritesTemplate(
jni::Make<std::string>(env, options.Get(env, spritesTemplateField)),
jni::Make<std::string>(env, options.Get(env, spritesDomainNameField)),
spritesVersionPrefixValue ? jni::Make<std::string>(env, spritesVersionPrefixValue): optional<std::string>{});
auto glyphsVersionPrefixValue = options.Get(env, glyphsVersionPrefixField);
retVal.withGlyphsTemplate(
jni::Make<std::string>(env, options.Get(env, glyphsTemplateField)),
jni::Make<std::string>(env, options.Get(env, glyphsDomainNameField)),
glyphsVersionPrefixValue ? jni::Make<std::string>(env, glyphsVersionPrefixValue) : optional<std::string>{});
auto tileVersionPrefixValue = options.Get(env, tileVersionPrefixField);
retVal.withTileTemplate(
jni::Make<std::string>(env, options.Get(env, tileTemplateField)),
jni::Make<std::string>(env, options.Get(env, tileDomainNameField)),
tileVersionPrefixValue ? jni::Make<std::string>(env, tileVersionPrefixValue): optional<std::string>{});
retVal.withDefaultStyle(jni::Make<std::string>(env, options.Get(env, defaultStyleField)));
retVal.withDefaultStyles(defaultStyles);
return retVal;
}
std::vector<const mbgl::util::DefaultStyle> TileServerOptions::getDefaultStyles(jni::JNIEnv& env, const jni::Array<jni::Object<DefaultStyle>>& styles_) {
std::size_t length = styles_.Length(env);
std::vector<const mbgl::util::DefaultStyle> convertedStyles;
//convertedStyles.reserve(length);
for (std::size_t i = 0; i < length; i++) {
const mbgl::util::DefaultStyle converted = DefaultStyle::getDefaultStyle(env, styles_.Get(env, i));
convertedStyles.push_back(converted);
}
return convertedStyles;
}
void TileServerOptions::registerNative(jni::JNIEnv& env) {
static auto& javaClass = jni::Class<TileServerOptions>::Singleton(env);
jni::RegisterNatives(env,
*javaClass,
jni::MakeNativeMethod<decltype(&TileServerOptions::DefaultConfiguration), &TileServerOptions::DefaultConfiguration>("defaultConfiguration"),
jni::MakeNativeMethod<decltype(&TileServerOptions::MapboxConfiguration), &TileServerOptions::MapboxConfiguration>("mapboxConfiguration"),
jni::MakeNativeMethod<decltype(&TileServerOptions::MapTilerConfiguration), &TileServerOptions::MapTilerConfiguration>("mapTilerConfiguration"),
jni::MakeNativeMethod<decltype(&TileServerOptions::MapLibreConfiguration), &TileServerOptions::MapLibreConfiguration>("mapLibreConfiguration"));
}
} // namespace android
} // namespace mbgl

View File

@@ -0,0 +1,38 @@
#pragma once
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/tile_server_options.hpp>
#include <mbgl/util/default_style.hpp>
#include <jni/jni.hpp>
#include "default_style.hpp"
namespace mbgl {
namespace android {
class TileServerOptions : private mbgl::util::noncopyable {
public:
static constexpr auto Name() { return "com/mapbox/mapboxsdk/util/TileServerOptions"; };
static jni::Local<jni::Object<TileServerOptions>> New(jni::JNIEnv&, const mbgl::TileServerOptions&);
static jni::Local<jni::Object<TileServerOptions>> DefaultConfiguration(jni::JNIEnv&, const jni::Class<TileServerOptions>&);
static jni::Local<jni::Object<TileServerOptions>> MapboxConfiguration(jni::JNIEnv&, const jni::Class<TileServerOptions>&);
static jni::Local<jni::Object<TileServerOptions>> MapTilerConfiguration(jni::JNIEnv&, const jni::Class<TileServerOptions>&);
static jni::Local<jni::Object<TileServerOptions>> MapLibreConfiguration(jni::JNIEnv&, const jni::Class<TileServerOptions>&);
static mbgl::TileServerOptions getTileServerOptions(jni::JNIEnv&, const jni::Object<TileServerOptions>&);
static void registerNative(jni::JNIEnv&);
static jni::Local<jni::Array<jni::Object<DefaultStyle>>> NewStyles(jni::JNIEnv& env, const std::vector<const mbgl::util::DefaultStyle>);
static std::vector<const mbgl::util::DefaultStyle> getDefaultStyles(jni::JNIEnv& env, const jni::Array<jni::Object<DefaultStyle>>& styles_);
};
} // namespace android
} // namespace mbgl