Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iOS/macOS observer hooks #3245

Merged
merged 11 commits into from
Feb 27, 2025
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 24, 2025
commit 0b75b152935480cacff2783ead6a4d6158c084e7
18 changes: 9 additions & 9 deletions platform/darwin/src/MLNTileOperation.h
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@
#endif

typedef NS_ENUM(NSInteger, MLNTileOperation) {
MLNTileOperationRequestedFromCache, ///< A read request from the cache
MLNTileOperationRequestedFromNetwork, ///< A read request from the online source
MLNTileOperationLoadFromNetwork, ///< Tile data from the network has been retrieved
MLNTileOperationLoadFromCache, ///< Tile data from the cache has been retrieved
MLNTileOperationStartParse, ///< Background processing of tile data has been initiated
MLNTileOperationEndParse, ///< Background processing of tile data has been completed
MLNTileOperationError, ///< An error occurred while loading the tile
MLNTileOperationCancelled, ///< Loading of a tile was cancelled
MLNTileOperationNullOp, ///< No operation has taken place
MLNTileOperationRequestedFromCache, ///< A read request from the cache
MLNTileOperationRequestedFromNetwork, ///< A read request from the online source
MLNTileOperationLoadFromNetwork, ///< Tile data from the network has been retrieved
MLNTileOperationLoadFromCache, ///< Tile data from the cache has been retrieved
MLNTileOperationStartParse, ///< Background processing of tile data has been initiated
MLNTileOperationEndParse, ///< Background processing of tile data has been completed
MLNTileOperationError, ///< An error occurred while loading the tile
MLNTileOperationCancelled, ///< Loading of a tile was cancelled
MLNTileOperationNullOp, ///< No operation has taken place
};
55 changes: 22 additions & 33 deletions platform/ios/app-swift/Sources/ObserverExample.swift
Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@ import UIKit
// #-example-code(ObserverExample)
class ObserverExampleView: UIViewController, MLNMapViewDelegate {
var mapView: MLNMapView!

override func viewDidLoad() {
super.viewDidLoad()

mapView = MLNMapView(frame: view.bounds, styleURL: AMERICANA_STYLE)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

@@ -21,21 +21,21 @@ class ObserverExampleView: UIViewController, MLNMapViewDelegate {

mapView.delegate = self
}

// MARK: - MLNMapViewDelegate methods

func mapView(_: MLNMapView, shaderWillCompile id: Int, backend: Int, defines: String) {
print("A new shader is being compiled - shaderID:\(id), backend type:\(backend), program configuration:\(defines)")
}

func mapView(_: MLNMapView, shaderDidCompile id: Int, backend: Int, defines: String) {
print("A shader has been compiled - shaderID:\(id), backend type:\(backend), program configuration:\(defines)")
}

func mapView(_: MLNMapView, glyphsWillLoad fontStack: [String], range: NSRange) {
print("Glyphs are being requested for the font stack \(fontStack), ranging from \(range.location) to \(range.location + range.length)")
}

func mapView(_: MLNMapView, glyphsDidLoad fontStack: [String], range: NSRange) {
print("Glyphs have been loaded for the font stack \(fontStack), ranging from \(range.location) to \(range.location + range.length)")
}
@@ -46,59 +46,48 @@ class ObserverExampleView: UIViewController, MLNMapViewDelegate {
z: Int,
wrap: Int,
overscaledZ: Int,
sourceID: String) {
let tileStr = String(format:"(x: %ld, y: %ld, z: %ld, wrap: %ld, overscaledZ: %ld, sourceID: %@)",
sourceID: String)
{
let tileStr = String(format: "(x: %ld, y: %ld, z: %ld, wrap: %ld, overscaledZ: %ld, sourceID: %@)",
x, y, z, wrap, overscaledZ, sourceID)
switch (operation) {

switch operation {
case MLNTileOperation.requestedFromCache:
print("Requesting tile \(tileStr) from cache")
break


case MLNTileOperation.requestedFromNetwork:
print("Requesting tile \(tileStr) from network")
break


case MLNTileOperation.loadFromCache:
print("Loading tile \(tileStr), requested from the cache")
break


case MLNTileOperation.loadFromNetwork:
print("Loading tile \(tileStr), requested from the network")
break


case MLNTileOperation.startParse:
print("Parsing tile \(tileStr)")
break


case MLNTileOperation.endParse:
print("Completed parsing tile \(tileStr)")
break


case MLNTileOperation.error:
print("An error occured during proccessing for tile \(tileStr)")
break


case MLNTileOperation.cancelled:
print("Pending work on tile \(tileStr)")
break


case MLNTileOperation.nullOp:
print("An unknown tile operation was emitted for tile \(tileStr)")
break

@unknown default:
assertionFailure()
}
}

func mapView(_: MLNMapView, spriteWillLoad _: String, url _: String) {

}

func mapView(_: MLNMapView, spriteDidLoad _: String, url _: String) {

}
func mapView(_: MLNMapView, spriteWillLoad _: String, url _: String) {}

func mapView(_: MLNMapView, spriteDidLoad _: String, url _: String) {}
}

// #-end-example-code
18 changes: 9 additions & 9 deletions platform/ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
@@ -2315,40 +2315,40 @@ - (void)mapView:(MLNMapView *)mapView
{
NSString* tileStr = [NSString stringWithFormat:@"(x: %ld, y: %ld, z: %ld, wrap: %ld, overscaledZ: %ld, sourceID: %@)",
x, y, z, wrap, overscaledZ, sourceID];

switch (operation) {
case MLNTileOperationRequestedFromCache:
NSLog(@"Requesting tile %@ from cache", tileStr);
break;

case MLNTileOperationRequestedFromNetwork:
NSLog(@"Requesting tile %@ from network", tileStr);
break;

case MLNTileOperationLoadFromCache:
NSLog(@"Loading tile %@, requested from the cache", tileStr);
break;

case MLNTileOperationLoadFromNetwork:
NSLog(@"Loading tile %@, requested from the network", tileStr);
break;

case MLNTileOperationStartParse:
NSLog(@"Parsing tile %@", tileStr);
break;

case MLNTileOperationEndParse:
NSLog(@"Completed parsing tile %@", tileStr);
break;

case MLNTileOperationError:
NSLog(@"An error occured during proccessing for tile %@", tileStr);
break;

case MLNTileOperationCancelled:
NSLog(@"Pending work on tile %@", tileStr);
break;

case MLNTileOperationNullOp:
NSLog(@"An unknown tile operation was emitted for tile %@", tileStr);
break;