Add action journal (#3409)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
@@ -110,6 +110,8 @@ add_library(maplibre SHARED
|
||||
${PROJECT_SOURCE_DIR}/map_renderer_runnable.hpp
|
||||
${PROJECT_SOURCE_DIR}/native_map_view.cpp
|
||||
${PROJECT_SOURCE_DIR}/native_map_view.hpp
|
||||
${PROJECT_SOURCE_DIR}/native_map_options.cpp
|
||||
${PROJECT_SOURCE_DIR}/native_map_options.hpp
|
||||
${PROJECT_SOURCE_DIR}/offline/offline_manager.cpp
|
||||
${PROJECT_SOURCE_DIR}/offline/offline_manager.hpp
|
||||
${PROJECT_SOURCE_DIR}/offline/offline_region.cpp
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "map_renderer_runnable.hpp"
|
||||
#include "maplibre.hpp"
|
||||
#include "native_map_view.hpp"
|
||||
#include "native_map_options.hpp"
|
||||
#include "util/tile_server_options.hpp"
|
||||
#ifndef MBGL_MODULE_OFFLINE_DISABLE
|
||||
#include "offline/offline_manager.hpp"
|
||||
@@ -109,6 +110,7 @@ void registerNatives(JavaVM* vm) {
|
||||
MapRenderer::registerNative(env);
|
||||
MapRendererRunnable::registerNative(env);
|
||||
NativeMapView::registerNative(env);
|
||||
NativeMapOptions::registerNative(env);
|
||||
|
||||
// Http
|
||||
RegisterNativeHTTPRequest(env);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "native_map_options.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
void NativeMapOptions::registerNative(jni::JNIEnv &env) {
|
||||
jni::Class<NativeMapOptions>::Singleton(env);
|
||||
}
|
||||
|
||||
NativeMapOptions::NativeMapOptions(jni::JNIEnv &_env, const jni::Object<NativeMapOptions> &_obj) {}
|
||||
|
||||
NativeMapOptions::~NativeMapOptions() {}
|
||||
|
||||
util::ActionJournalOptions NativeMapOptions::getActionJournalOptions(jni::JNIEnv &env,
|
||||
const jni::Object<NativeMapOptions> &obj) {
|
||||
auto &javaClass = jni::Class<NativeMapOptions>::Singleton(env);
|
||||
|
||||
auto enabledField = javaClass.GetField<jni::jboolean>(env, "actionJournalEnabled");
|
||||
auto pathField = javaClass.GetField<jni::String>(env, "actionJournalPath");
|
||||
auto logFileSizeField = javaClass.GetField<jni::jlong>(env, "actionJournalLogFileSize");
|
||||
auto logFileCountField = javaClass.GetField<jni::jlong>(env, "actionJournalLogFileCount");
|
||||
|
||||
return util::ActionJournalOptions()
|
||||
.enable(obj.Get(env, enabledField))
|
||||
.withPath(jni::Make<std::string>(env, obj.Get(env, pathField)))
|
||||
.withLogFileSize(obj.Get(env, logFileSizeField))
|
||||
.withLogFileCount(obj.Get(env, logFileCountField));
|
||||
}
|
||||
|
||||
float NativeMapOptions::pixelRatio(jni::JNIEnv &env, const jni::Object<NativeMapOptions> &obj) {
|
||||
auto &javaClass = jni::Class<NativeMapOptions>::Singleton(env);
|
||||
auto pixelRatioField = javaClass.GetField<float>(env, "pixelRatio");
|
||||
return obj.Get(env, pixelRatioField);
|
||||
}
|
||||
|
||||
bool NativeMapOptions::crossSourceCollisions(jni::JNIEnv &env, const jni::Object<NativeMapOptions> &obj) {
|
||||
auto &javaClass = jni::Class<NativeMapOptions>::Singleton(env);
|
||||
auto crossSourceCollisionsField = javaClass.GetField<jni::jboolean>(env, "crossSourceCollisions");
|
||||
return obj.Get(env, crossSourceCollisionsField);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <jni/jni.hpp>
|
||||
#include <mbgl/util/action_journal_options.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class NativeMapOptions {
|
||||
public:
|
||||
static constexpr auto Name() { return "org/maplibre/android/maps/NativeMapOptions"; };
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
NativeMapOptions(jni::JNIEnv&, const jni::Object<NativeMapOptions>&);
|
||||
virtual ~NativeMapOptions();
|
||||
|
||||
static util::ActionJournalOptions getActionJournalOptions(jni::JNIEnv&, const jni::Object<NativeMapOptions>&);
|
||||
static float pixelRatio(jni::JNIEnv&, const jni::Object<NativeMapOptions>&);
|
||||
static bool crossSourceCollisions(jni::JNIEnv&, const jni::Object<NativeMapOptions>&);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/map_options.hpp>
|
||||
#include <mbgl/math/minmax.hpp>
|
||||
#include <mbgl/util/action_journal.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/event.hpp>
|
||||
#include <mbgl/util/exception.hpp>
|
||||
@@ -62,11 +63,10 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
|
||||
const jni::Object<NativeMapView>& _obj,
|
||||
const jni::Object<FileSource>& jFileSource,
|
||||
const jni::Object<MapRenderer>& jMapRenderer,
|
||||
jni::jfloat pixelRatio_,
|
||||
jni::jboolean crossSourceCollisions_)
|
||||
const jni::Object<NativeMapOptions>& jNativeMapOptions)
|
||||
: javaPeer(_env, _obj),
|
||||
mapRenderer(MapRenderer::getNativePeer(_env, jMapRenderer)),
|
||||
pixelRatio(pixelRatio_) {
|
||||
pixelRatio(NativeMapOptions::pixelRatio(_env, jNativeMapOptions)) {
|
||||
// Get a reference to the JavaVM for callbacks
|
||||
if (_env.GetJavaVM(&vm) < 0) {
|
||||
_env.ExceptionDescribe();
|
||||
@@ -83,14 +83,16 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
|
||||
.withPixelRatio(pixelRatio)
|
||||
.withConstrainMode(ConstrainMode::HeightOnly)
|
||||
.withViewportMode(ViewportMode::Default)
|
||||
.withCrossSourceCollisions(crossSourceCollisions_);
|
||||
.withCrossSourceCollisions(NativeMapOptions::crossSourceCollisions(_env, jNativeMapOptions));
|
||||
|
||||
// Create the core map
|
||||
map = std::make_unique<mbgl::Map>(*rendererFrontend,
|
||||
*this,
|
||||
options,
|
||||
mbgl::android::FileSource::getSharedResourceOptions(_env, jFileSource),
|
||||
mbgl::android::FileSource::getSharedClientOptions(_env, jFileSource));
|
||||
map = std::make_unique<mbgl::Map>(
|
||||
*rendererFrontend,
|
||||
*this,
|
||||
options,
|
||||
mbgl::android::FileSource::getSharedResourceOptions(_env, jFileSource),
|
||||
mbgl::android::FileSource::getSharedClientOptions(_env, jFileSource),
|
||||
mbgl::android::NativeMapOptions::getActionJournalOptions(_env, jNativeMapOptions));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -693,6 +695,47 @@ jni::jboolean NativeMapView::getDebug(JNIEnv&) {
|
||||
return map->getDebug() != DebugOptions::NoDebug;
|
||||
}
|
||||
|
||||
jni::Local<jni::Array<jni::String>> NativeMapView::getActionJournalLogFiles(JNIEnv& env) {
|
||||
const auto& actionJournal = map->getActionJournal();
|
||||
if (!actionJournal) {
|
||||
return jni::Local<jni::Array<jni::String>>();
|
||||
}
|
||||
|
||||
const auto& files = actionJournal->getLogFiles();
|
||||
auto jFiles = jni::Array<jni::String>::New(env, files.size());
|
||||
|
||||
uint32_t index = 0;
|
||||
for (const auto& file : files) {
|
||||
jFiles.Set(env, index++, jni::Make<jni::String>(env, file));
|
||||
}
|
||||
|
||||
return jFiles;
|
||||
}
|
||||
|
||||
jni::Local<jni::Array<jni::String>> NativeMapView::getActionJournalLog(JNIEnv& env) {
|
||||
const auto& actionJournal = map->getActionJournal();
|
||||
if (!actionJournal) {
|
||||
return jni::Local<jni::Array<jni::String>>();
|
||||
}
|
||||
|
||||
const auto& events = actionJournal->getLog();
|
||||
auto jEvents = jni::Array<jni::String>::New(env, events.size());
|
||||
|
||||
uint32_t index = 0;
|
||||
for (const auto& event : events) {
|
||||
jEvents.Set(env, index++, jni::Make<jni::String>(env, event));
|
||||
}
|
||||
|
||||
return jEvents;
|
||||
}
|
||||
|
||||
void NativeMapView::clearActionJournalLog(JNIEnv&) {
|
||||
const auto& actionJournal = map->getActionJournal();
|
||||
if (actionJournal) {
|
||||
actionJournal->clearLog();
|
||||
}
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::isFullyLoaded(JNIEnv&) {
|
||||
return map->isFullyLoaded();
|
||||
}
|
||||
@@ -1246,8 +1289,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
const jni::Object<NativeMapView>&,
|
||||
const jni::Object<FileSource>&,
|
||||
const jni::Object<MapRenderer>&,
|
||||
jni::jfloat,
|
||||
jni::jboolean>,
|
||||
const jni::Object<NativeMapOptions>&>,
|
||||
"nativeInitialize",
|
||||
"nativeDestroy",
|
||||
METHOD(&NativeMapView::resizeView, "nativeResizeView"),
|
||||
@@ -1292,6 +1334,9 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::addMarkers, "nativeAddMarkers"),
|
||||
METHOD(&NativeMapView::setDebug, "nativeSetDebug"),
|
||||
METHOD(&NativeMapView::getDebug, "nativeGetDebug"),
|
||||
METHOD(&NativeMapView::getActionJournalLogFiles, "nativeGetActionJournalLogFiles"),
|
||||
METHOD(&NativeMapView::getActionJournalLog, "nativeGetActionJournalLog"),
|
||||
METHOD(&NativeMapView::clearActionJournalLog, "nativeClearActionJournalLog"),
|
||||
METHOD(&NativeMapView::isFullyLoaded, "nativeIsFullyLoaded"),
|
||||
METHOD(&NativeMapView::onLowMemory, "nativeOnLowMemory"),
|
||||
METHOD(&NativeMapView::getMetersPerPixelAtLatitude, "nativeGetMetersPerPixelAtLatitude"),
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "map/camera_position.hpp"
|
||||
#include "map/image.hpp"
|
||||
#include "style/light.hpp"
|
||||
#include "native_map_options.hpp"
|
||||
#include "bitmap.hpp"
|
||||
|
||||
#include <exception>
|
||||
@@ -49,8 +50,7 @@ public:
|
||||
const jni::Object<NativeMapView>&,
|
||||
const jni::Object<FileSource>&,
|
||||
const jni::Object<MapRenderer>&,
|
||||
jni::jfloat,
|
||||
jni::jboolean);
|
||||
const jni::Object<NativeMapOptions>&);
|
||||
|
||||
virtual ~NativeMapView();
|
||||
|
||||
@@ -199,6 +199,12 @@ public:
|
||||
|
||||
jni::jboolean getDebug(JNIEnv&);
|
||||
|
||||
jni::Local<jni::Array<jni::String>> getActionJournalLogFiles(JNIEnv&);
|
||||
|
||||
jni::Local<jni::Array<jni::String>> getActionJournalLog(JNIEnv&);
|
||||
|
||||
void clearActionJournalLog(JNIEnv&);
|
||||
|
||||
jni::jboolean isFullyLoaded(JNIEnv&);
|
||||
|
||||
jni::jdouble getMetersPerPixelAtLatitude(JNIEnv&, jni::jdouble, jni::jdouble);
|
||||
|
||||
@@ -897,6 +897,49 @@ public final class MapLibreMap {
|
||||
nativeMapView.setDebug(debugActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Get the list of action journal log files from oldest to newest.
|
||||
* </p>
|
||||
*/
|
||||
public String[] getActionJournalLogFiles() {
|
||||
return nativeMapView.getActionJournalLogFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Get the action journal events from oldest to newest.
|
||||
* </p>
|
||||
* Each element contains a serialized json object with the event data.
|
||||
* Example
|
||||
* `{
|
||||
* "name" : "onTileAction",
|
||||
* "time" : "2025-04-17T13:13:13.974Z",
|
||||
* "styleName" : "Streets",
|
||||
* "styleURL" : "maptiler://maps/streets",
|
||||
* "event" : {
|
||||
* "action" : "RequestedFromNetwork",
|
||||
* "tileX" : 0,
|
||||
* "tileY" : 0,
|
||||
* "tileZ" : 0,
|
||||
* "overscaledZ" : 0,
|
||||
* "sourceID" : "openmaptiles"
|
||||
* }
|
||||
* }`
|
||||
*/
|
||||
public String[] getActionJournalLog() {
|
||||
return nativeMapView.getActionJournalLog();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Clear stored action journal events.
|
||||
* </p>
|
||||
*/
|
||||
public void clearActionJournalLog() {
|
||||
nativeMapView.clearActionJournalLog();
|
||||
}
|
||||
|
||||
//
|
||||
// API endpoint config
|
||||
//
|
||||
|
||||
@@ -94,6 +94,11 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
|
||||
private boolean crossSourceCollisions = true;
|
||||
|
||||
private boolean actionJournalEnabled = false;
|
||||
private String actionJournalPath = "";
|
||||
private long actionJournalLogFileSize = 1024 * 1024;
|
||||
private long actionJournalLogFileCount = 5;
|
||||
|
||||
/**
|
||||
* Creates a new MapLibreMapOptions object.
|
||||
*
|
||||
@@ -151,6 +156,11 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
pixelRatio = in.readFloat();
|
||||
foregroundLoadColor = in.readInt();
|
||||
crossSourceCollisions = in.readByte() != 0;
|
||||
|
||||
actionJournalEnabled = in.readByte() != 0;
|
||||
actionJournalPath = in.readString();
|
||||
actionJournalLogFileSize = in.readLong();
|
||||
actionJournalLogFileCount = in.readLong();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,6 +192,8 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
@NonNull Context context,
|
||||
@Nullable TypedArray typedArray) {
|
||||
float pxlRatio = context.getResources().getDisplayMetrics().density;
|
||||
maplibreMapOptions.actionJournalPath(context.getFilesDir().getAbsolutePath());
|
||||
|
||||
try {
|
||||
maplibreMapOptions.camera(new CameraPosition.Builder(typedArray).build());
|
||||
|
||||
@@ -305,6 +317,16 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
maplibreMapOptions.crossSourceCollisions(
|
||||
typedArray.getBoolean(R.styleable.maplibre_MapView_maplibre_cross_source_collisions, true)
|
||||
);
|
||||
|
||||
maplibreMapOptions.actionJournalEnabled(
|
||||
typedArray.getBoolean(R.styleable.maplibre_MapView_maplibre_actionJournalEnabled, false)
|
||||
);
|
||||
maplibreMapOptions.actionJournalLogFileSize(
|
||||
typedArray.getInteger(R.styleable.maplibre_MapView_maplibre_actionJournalLogFileSize, 1024 * 1024)
|
||||
);
|
||||
maplibreMapOptions.actionJournalLogFileCount(
|
||||
typedArray.getInteger(R.styleable.maplibre_MapView_maplibre_actionJournalLogFileCount, 5)
|
||||
);
|
||||
} finally {
|
||||
typedArray.recycle();
|
||||
}
|
||||
@@ -730,6 +752,65 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable action journal event logging, defaults to false.
|
||||
* <p>
|
||||
* If set to true, enables map event file logging (obtainable via MapView#getActionJournalLog)
|
||||
* </p>
|
||||
*
|
||||
* @param actionJournalEnabled true to enable, false to disable
|
||||
* @return This
|
||||
*/
|
||||
@NonNull
|
||||
public MapLibreMapOptions actionJournalEnabled(boolean actionJournalEnabled) {
|
||||
this.actionJournalEnabled = actionJournalEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action journal log path.
|
||||
*
|
||||
* @param actionJournalPath Path to be used
|
||||
* @return This
|
||||
*/
|
||||
@NonNull
|
||||
public MapLibreMapOptions actionJournalPath(@NonNull String actionJournalPath) {
|
||||
this.actionJournalPath = actionJournalPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action journal log file size.
|
||||
* <p>
|
||||
* The action journal uses a rolling log with multiple files.
|
||||
* Total log size is equal to `actionJournalLogFileSize * actionJournalLogFileCount`.
|
||||
* </p>
|
||||
*
|
||||
* @param actionJournalLogFileSize maximum log file size
|
||||
* @return This
|
||||
*/
|
||||
@NonNull
|
||||
public MapLibreMapOptions actionJournalLogFileSize(long actionJournalLogFileSize) {
|
||||
this.actionJournalLogFileSize = actionJournalLogFileSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action journal log file count.
|
||||
* <p>
|
||||
* The action journal uses a rolling log with multiple files.
|
||||
* Total log size is equal to `actionJournalLogFileSize * actionJournalLogFileCount`.
|
||||
* </p>
|
||||
*
|
||||
* @param actionJournalLogFileCount maximum number of log files
|
||||
* @return This
|
||||
*/
|
||||
@NonNull
|
||||
public MapLibreMapOptions actionJournalLogFileCount(long actionJournalLogFileCount) {
|
||||
this.actionJournalLogFileCount = actionJournalLogFileCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable local ideograph font family, defaults to true.
|
||||
*
|
||||
@@ -821,6 +902,44 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
return crossSourceCollisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether action journal logging is enabled.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
public boolean getActionJournalEnabled() {
|
||||
return actionJournalEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured action journal log path.
|
||||
*
|
||||
* @return log file path
|
||||
*/
|
||||
public String getActionJournalPath() {
|
||||
return actionJournalPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured action journal log file size.
|
||||
* Total log size is equal to `actionJournalLogFileSize * actionJournalLogFileCount`.
|
||||
*
|
||||
* @return maximum file size
|
||||
*/
|
||||
public long getActionJournalLogFileSize() {
|
||||
return actionJournalLogFileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured action journal log file count.
|
||||
* Total log size is equal to `actionJournalLogFileSize * actionJournalLogFileCount`.
|
||||
*
|
||||
* @return maximum log files used
|
||||
*/
|
||||
public long getActionJournalLogFileCount() {
|
||||
return actionJournalLogFileCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the flag to render the map surface on top of another surface.
|
||||
*
|
||||
@@ -1205,6 +1324,11 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
dest.writeFloat(pixelRatio);
|
||||
dest.writeInt(foregroundLoadColor);
|
||||
dest.writeByte((byte) (crossSourceCollisions ? 1 : 0));
|
||||
|
||||
dest.writeByte((byte) (actionJournalEnabled ? 1 : 0));
|
||||
dest.writeString(actionJournalPath);
|
||||
dest.writeLong(actionJournalLogFileSize);
|
||||
dest.writeLong(actionJournalLogFileCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1325,6 +1449,22 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (actionJournalEnabled != options.actionJournalEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (actionJournalPath.equals(options.actionJournalPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (actionJournalLogFileSize != options.actionJournalLogFileSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (actionJournalLogFileCount != options.actionJournalLogFileCount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1372,6 +1512,10 @@ public class MapLibreMapOptions implements Parcelable {
|
||||
result = 31 * result + Arrays.hashCode(localIdeographFontFamilies);
|
||||
result = 31 * result + (int) pixelRatio;
|
||||
result = 31 * result + (crossSourceCollisions ? 1 : 0);
|
||||
result = 31 * result + (actionJournalEnabled ? 1 : 0);
|
||||
result = 31 * result + (actionJournalPath != null ? actionJournalPath.hashCode() : 0);
|
||||
result = 31 * result + (int) actionJournalLogFileSize;
|
||||
result = 31 * result + (int) actionJournalLogFileCount;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,15 +306,13 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
|
||||
private void initializeDrawingSurface(MapLibreMapOptions options) {
|
||||
mapRenderer = MapRenderer.create(options, getContext(), () -> MapView.this.onSurfaceCreated());
|
||||
mapRenderer = MapRenderer.create(options, getContext(), MapView.this::onSurfaceCreated);
|
||||
renderView = mapRenderer.getView();
|
||||
|
||||
addView(renderView, 0);
|
||||
|
||||
boolean crossSourceCollisions = options.getCrossSourceCollisions();
|
||||
nativeMapView = new NativeMapView(
|
||||
getContext(), getPixelRatio(), crossSourceCollisions, this, mapChangeReceiver, mapRenderer
|
||||
);
|
||||
options.pixelRatio(getPixelRatio());
|
||||
nativeMapView = new NativeMapView(getContext(), options, this, mapChangeReceiver, mapRenderer);
|
||||
}
|
||||
|
||||
private void onSurfaceCreated() {
|
||||
|
||||
@@ -221,6 +221,12 @@ interface NativeMap {
|
||||
|
||||
boolean getDebug();
|
||||
|
||||
String[] getActionJournalLogFiles();
|
||||
|
||||
String[] getActionJournalLog();
|
||||
|
||||
void clearActionJournalLog();
|
||||
|
||||
void setReachability(boolean status);
|
||||
|
||||
void setApiBaseUrl(String baseUrl);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.maplibre.android.maps;
|
||||
|
||||
public class NativeMapOptions {
|
||||
|
||||
private final float pixelRatio;
|
||||
private final boolean crossSourceCollisions;
|
||||
|
||||
private final boolean actionJournalEnabled;
|
||||
private final String actionJournalPath;
|
||||
private final long actionJournalLogFileSize;
|
||||
private final long actionJournalLogFileCount;
|
||||
|
||||
public NativeMapOptions(MapLibreMapOptions options) {
|
||||
pixelRatio = options.getPixelRatio();
|
||||
crossSourceCollisions = options.getCrossSourceCollisions();
|
||||
|
||||
actionJournalEnabled = options.getActionJournalEnabled();
|
||||
actionJournalPath = options.getActionJournalPath();
|
||||
actionJournalLogFileSize = options.getActionJournalLogFileSize();
|
||||
actionJournalLogFileCount = options.getActionJournalLogFileCount();
|
||||
}
|
||||
|
||||
public NativeMapOptions(float pixelRatio, boolean crossSourceCollisions) {
|
||||
this.pixelRatio = pixelRatio;
|
||||
this.crossSourceCollisions = crossSourceCollisions;
|
||||
|
||||
actionJournalEnabled = false;
|
||||
actionJournalPath = "";
|
||||
actionJournalLogFileSize = 0;
|
||||
actionJournalLogFileCount = 0;
|
||||
}
|
||||
|
||||
public float pixelRatio() {
|
||||
return pixelRatio;
|
||||
}
|
||||
|
||||
public boolean crossSourceCollisions() {
|
||||
return crossSourceCollisions;
|
||||
}
|
||||
|
||||
public boolean actionJournalEnabled() {
|
||||
return actionJournalEnabled;
|
||||
}
|
||||
|
||||
public String actionJournalPath() {
|
||||
return actionJournalPath;
|
||||
}
|
||||
|
||||
public long actionJournalLogFileSize() {
|
||||
return actionJournalLogFileSize;
|
||||
}
|
||||
|
||||
public long actionJournalLogFileCount() {
|
||||
return actionJournalLogFileCount;
|
||||
}
|
||||
}
|
||||
@@ -91,23 +91,29 @@ final class NativeMapView implements NativeMap {
|
||||
// Constructors
|
||||
//
|
||||
|
||||
public NativeMapView(@NonNull final Context context, final boolean crossSourceCollisions,
|
||||
public NativeMapView(@NonNull final Context context,
|
||||
final ViewCallback viewCallback, final StateCallback stateCallback,
|
||||
final MapRenderer mapRenderer) {
|
||||
this(context, context.getResources().getDisplayMetrics().density, crossSourceCollisions, viewCallback,
|
||||
stateCallback, mapRenderer);
|
||||
this(context, new NativeMapOptions(context.getResources().getDisplayMetrics().density, false),
|
||||
viewCallback, stateCallback, mapRenderer);
|
||||
}
|
||||
|
||||
public NativeMapView(final Context context, final float pixelRatio, final boolean crossSourceCollisions,
|
||||
public NativeMapView(@NonNull final Context context, final MapLibreMapOptions options,
|
||||
final ViewCallback viewCallback, final StateCallback stateCallback,
|
||||
final MapRenderer mapRenderer) {
|
||||
this(context, new NativeMapOptions(options), viewCallback, stateCallback, mapRenderer);
|
||||
}
|
||||
|
||||
public NativeMapView(@NonNull final Context context, final NativeMapOptions nativeOptions,
|
||||
final ViewCallback viewCallback, final StateCallback stateCallback,
|
||||
final MapRenderer mapRenderer) {
|
||||
this.mapRenderer = mapRenderer;
|
||||
this.viewCallback = viewCallback;
|
||||
this.fileSource = FileSource.getInstance(context);
|
||||
this.pixelRatio = pixelRatio;
|
||||
this.pixelRatio = nativeOptions.pixelRatio();
|
||||
this.thread = Thread.currentThread();
|
||||
this.stateCallback = stateCallback;
|
||||
nativeInitialize(this, fileSource, mapRenderer, pixelRatio, crossSourceCollisions);
|
||||
nativeInitialize(this, fileSource, mapRenderer, nativeOptions);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -646,6 +652,30 @@ final class NativeMapView implements NativeMap {
|
||||
return nativeGetDebug();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getActionJournalLogFiles() {
|
||||
if (checkState("getActionJournalLogFiles")) {
|
||||
return null;
|
||||
}
|
||||
return nativeGetActionJournalLogFiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getActionJournalLog() {
|
||||
if (checkState("getActionJournalLog")) {
|
||||
return null;
|
||||
}
|
||||
return nativeGetActionJournalLog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearActionJournalLog() {
|
||||
if (checkState("clearActionJournalLog")) {
|
||||
return;
|
||||
}
|
||||
nativeClearActionJournalLog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullyLoaded() {
|
||||
if (checkState("isFullyLoaded")) {
|
||||
@@ -1275,8 +1305,7 @@ final class NativeMapView implements NativeMap {
|
||||
private native void nativeInitialize(NativeMapView nativeMap,
|
||||
FileSource fileSource,
|
||||
MapRenderer mapRenderer,
|
||||
float pixelRatio,
|
||||
boolean crossSourceCollisions);
|
||||
NativeMapOptions nativeOptions);
|
||||
|
||||
@Keep
|
||||
private native void nativeDestroy();
|
||||
@@ -1429,6 +1458,15 @@ final class NativeMapView implements NativeMap {
|
||||
@Keep
|
||||
private native boolean nativeGetDebug();
|
||||
|
||||
@Keep
|
||||
private native String[] nativeGetActionJournalLogFiles();
|
||||
|
||||
@Keep
|
||||
private native String[] nativeGetActionJournalLog();
|
||||
|
||||
@Keep
|
||||
private native void nativeClearActionJournalLog();
|
||||
|
||||
@Keep
|
||||
private native boolean nativeIsFullyLoaded();
|
||||
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
<public name="maplibre_cross_source_collisions" type="attr" />
|
||||
<public name="maplibre_pixelRatio" type="float" />
|
||||
|
||||
<!--Action Journal-->
|
||||
<public name="maplibre_actionJournalEnabled" type="attr"/>
|
||||
<public name="maplibre_actionJournalLogFileSize" type="attr"/>
|
||||
<public name="maplibre_actionJournalLogFileCount" type="attr"/>
|
||||
|
||||
<!--Camera-->
|
||||
<public name="maplibre_cameraTargetLng" type="attr" />
|
||||
<public name="maplibre_cameraTargetLat" type="attr" />
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
<attr name="maplibre_localIdeographFontFamilies" format="reference"/>
|
||||
<attr name="maplibre_cross_source_collisions" format="boolean"/>
|
||||
|
||||
<!--Action Journal-->
|
||||
<attr name="maplibre_actionJournalEnabled" format="boolean"/>
|
||||
<attr name="maplibre_actionJournalLogFileSize" format="integer"/>
|
||||
<attr name="maplibre_actionJournalLogFileCount" format="integer"/>
|
||||
|
||||
<!--Camera-->
|
||||
<attr name="maplibre_cameraTargetLat" format="float"/>
|
||||
<attr name="maplibre_cameraTargetLng" format="float"/>
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.maplibre.android.maps.MapView
|
||||
import org.maplibre.android.utils.ConfigUtils.Companion.getMockedOptions
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mockito
|
||||
import java.io.File
|
||||
|
||||
class MapLibreTest {
|
||||
private var context: Context? = null
|
||||
@@ -68,8 +69,10 @@ class MapLibreTest {
|
||||
fun testNoInstance() {
|
||||
val displayMetrics = Mockito.mock(DisplayMetrics::class.java)
|
||||
val resources = Mockito.mock(Resources::class.java)
|
||||
val files = Mockito.mock(File::class.java)
|
||||
Mockito.`when`(resources.displayMetrics).thenReturn(displayMetrics)
|
||||
Mockito.`when`(context!!.resources).thenReturn(resources)
|
||||
Mockito.`when`(context!!.filesDir).thenReturn(files)
|
||||
val typedArray = Mockito.mock(TypedArray::class.java)
|
||||
Mockito.`when`(context!!.obtainStyledAttributes(ArgumentMatchers.nullable(AttributeSet::class.java), ArgumentMatchers.any(IntArray::class.java), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt()))
|
||||
.thenReturn(typedArray)
|
||||
|
||||
Reference in New Issue
Block a user