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:
Adrian Cojocaru
2025-05-27 16:15:56 +03:00
committed by GitHub
parent 5ec8430fa3
commit 08eb760acd
66 changed files with 2773 additions and 75 deletions

View File

@@ -5,6 +5,7 @@
#import "MLNFoundation.h"
#import "MLNGeometry.h"
#import "MLNMapCamera.h"
#import "MLNMapOptions.h"
#import "MLNStyle.h"
#import "MLNTypes.h"
@@ -219,6 +220,16 @@ MLN_EXPORT
*/
- (instancetype)initWithFrame:(CGRect)frame styleJSON:(NSString *)styleJSON;
/**
Initializes and returns a newly allocated map view with the specified frame
and the default style.
@param frame The frame for the view, measured in points.
@param options The map instance options
@return An initialized map view.
*/
- (instancetype)initWithFrame:(CGRect)frame options:(MLNMapOptions *)options;
// MARK: Accessing the Delegate
/**
@@ -2146,6 +2157,40 @@ vertically on the map.
*/
@property (nonatomic) MLNMapDebugMaskOptions debugMask;
/**
Get the list of action journal log files from oldest to newest.
@return An array of log file paths.
*/
- (NSArray<NSString *> *)getActionJournalLogFiles;
/**
Get the action journal events from oldest to newest.
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"
}
}`
*/
- (NSArray<NSString *> *)getActionJournalLog;
/**
Clear stored action journal events.
*/
- (void)clearActionJournalLog;
- (MLNBackendResource *)backendResource;
/**

View File

@@ -15,6 +15,7 @@
#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/math/wrap.hpp>
#include <mbgl/util/action_journal.hpp>
#include <mbgl/util/client_options.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/geo.hpp>
@@ -68,6 +69,7 @@
#import "MLNNetworkConfiguration_Private.h"
#import "MLNReachability.h"
#import "MLNSettings_Private.h"
#import "MLNActionJournalOptions_Private.h"
#import "MLNMapProjection.h"
#include <algorithm>
@@ -503,7 +505,7 @@ public:
{
MLNLogInfo(@"Starting %@ initialization.", NSStringFromClass([self class]));
MLNLogDebug(@"Initializing frame: %@", NSStringFromCGRect(frame));
[self commonInit];
[self commonInitWithOptions:nil];
self.styleURL = nil;
MLNLogInfo(@"Finalizing %@ initialization.", NSStringFromClass([self class]));
}
@@ -516,7 +518,7 @@ public:
{
MLNLogInfo(@"Starting %@ initialization.", NSStringFromClass([self class]));
MLNLogDebug(@"Initializing frame: %@ styleURL: %@", NSStringFromCGRect(frame), styleURL);
[self commonInit];
[self commonInitWithOptions:nil];
self.styleURL = styleURL;
MLNLogInfo(@"Finalizing %@ initialization.", NSStringFromClass([self class]));
}
@@ -529,7 +531,7 @@ public:
{
MLNLogInfo(@"Starting %@ initialization.", NSStringFromClass([self class]));
MLNLogDebug(@"Initializing frame: %@ styleJSON: %@", NSStringFromCGRect(frame), styleJSON);
[self commonInit];
[self commonInitWithOptions:nil];
self.styleJSON = styleJSON;
_initialStyleJSON = [styleJSON copy];
MLNLogInfo(@"Finalizing %@ initialization.", NSStringFromClass([self class]));
@@ -537,12 +539,39 @@ public:
return self;
}
- (instancetype)initWithFrame:(CGRect)frame options:(MLNMapOptions *)options
{
if (self = [super initWithFrame:frame])
{
MLNLogInfo(@"Starting %@ initialization.", NSStringFromClass([self class]));
MLNLogDebug(@"Initializing frame: %@ with options", NSStringFromCGRect(frame));
[self commonInitWithOptions:options];
if (options)
{
if (options.styleURL) {
self.styleURL = options.styleURL;
} else if (options.styleJSON) {
self.styleJSON = options.styleJSON;
_initialStyleJSON = [options.styleJSON copy];
} else {
self.styleURL = nil;
}
} else {
self.styleURL = nil;
}
MLNLogInfo(@"Finalizing %@ initialization.", NSStringFromClass([self class]));
}
return self;
}
- (instancetype)initWithCoder:(nonnull NSCoder *)decoder
{
if (self = [super initWithCoder:decoder])
{
MLNLogInfo(@"Starting %@ initialization.", NSStringFromClass([self class]));
[self commonInit];
[self commonInitWithOptions:nil];
self.styleURL = nil;
MLNLogInfo(@"Finalizing %@ initialization.", NSStringFromClass([self class]));
}
@@ -621,8 +650,13 @@ public:
return _rendererFrontend->getRenderer();
}
- (void)commonInit
- (void)commonInitWithOptions:(MLNMapOptions*)mlnMapoptions
{
if (mlnMapoptions == nil)
{
mlnMapoptions = [[MLNMapOptions alloc] init];
}
_opaque = NO;
// setup accessibility
@@ -683,8 +717,11 @@ public:
resourceOptions.withApiKey([apiKey UTF8String]);
}
const mbgl::util::ActionJournalOptions& actionJournalOptions = [mlnMapoptions.actionJournalOptions getCoreOptions];
NSAssert(!_mbglMap, @"_mbglMap should be NULL");
_mbglMap = std::make_unique<mbgl::Map>(*_rendererFrontend, *_mbglView, mapOptions, resourceOptions, clientOptions);
_mbglMap = std::make_unique<mbgl::Map>(*_rendererFrontend, *_mbglView, mapOptions,
resourceOptions, clientOptions, actionJournalOptions);
// start paused if launch into the background
if (background) {
@@ -7525,6 +7562,50 @@ static void *windowScreenContext = &windowScreenContext;
_mbglMap->triggerRepaint();
}
- (NSArray<NSString*>*)getActionJournalLogFiles
{
const auto& actionJournal = _mbglMap->getActionJournal();
if (!actionJournal) {
return nil;
}
const auto& files = actionJournal->getLogFiles();
NSMutableArray<NSString*>* objcFiles = [NSMutableArray new];
for (const auto& file : files) {
[objcFiles addObject:[NSString stringWithUTF8String:file.c_str()]];
}
return objcFiles;
}
- (NSArray<NSString*>*)getActionJournalLog
{
const auto& actionJournal = _mbglMap->getActionJournal();
if (!actionJournal) {
return nil;
}
const auto& log = actionJournal->getLog();
NSMutableArray<NSString*>* objcLog = [NSMutableArray new];
for (const auto& event : log) {
[objcLog addObject:[NSString stringWithUTF8String:event.c_str()]];
}
return objcLog;
}
- (void)clearActionJournalLog
{
const auto& actionJournal = _mbglMap->getActionJournal();
if (!actionJournal) {
return;
}
actionJournal->clearLog();
}
- (MLNBackendResource *)backendResource {
return _mbglView->getObject();
}