Skip to content

Commit

Permalink
(feat) annotation and log checking
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuyulv committed Jul 30, 2024
1 parent fa4b6bf commit efe33e3
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 19 deletions.
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ final List<ExamplePage> _allPages = <ExamplePage>[
PlaceCirclePage(),
PlaceFillPage(),
ScrollingMapPage(),
OfflineRegionsPage(),
// OfflineRegionsPage(),
AnnotationOrderPage(),
CustomMarkerPage(),
BatchAddPage(),
TakeSnapPage(),
ClickAnnotationPage(),
Sources(),
// Sources(),
TrackCurrentLocationPage()
];

Expand Down
1 change: 0 additions & 1 deletion ios/Classes/NextbillionMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,6 @@ class NextbillionMapController: NSObject, FlutterPlatformView, NGLMapViewDelegat
let source = NGLShapeSource(identifier: sourceId, shape: parsed, options: [:])
addedShapesByLayer[sourceId] = parsed
mapView.style?.addSource(source)
print(source)
} catch {}
}

Expand Down
5 changes: 0 additions & 5 deletions ios/Classes/OfflinePackDownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class OfflinePackDownloader {
}

deinit {
print("Removing offline pack notification observers")
NotificationCenter.default.removeObserver(self)
}

Expand Down Expand Up @@ -111,7 +110,6 @@ class OfflinePackDownloader {
)
// Check if downloading is complete
if pack.state == .complete {
print("Region downloaded successfully")
// set download state to inactive
// This can be called multiple times but result can only be called once. We use this
// check to ensure that
Expand All @@ -123,7 +121,6 @@ class OfflinePackDownloader {
OfflineManagerUtils.releaseDownloader(id: region.id)
}
} else {
print("Region download progress \(downloadProgress)")
channelHandler.onProgress(progress: downloadProgress)
}
}
Expand All @@ -132,7 +129,6 @@ class OfflinePackDownloader {
guard let pack = notification.object as? NGLOfflinePack,
verifyPack(pack: pack) else { return }
let error = notification.userInfo?[NGLOfflinePackUserInfoKey.error] as? NSError
print("Pack download error: \(String(describing: error?.localizedDescription))")
// set download state to inactive
isCompleted = true
channelHandler.onError(
Expand All @@ -155,7 +151,6 @@ class OfflinePackDownloader {
verifyPack(pack: pack) else { return }
let maximumCount = (notification.userInfo?[NGLOfflinePackUserInfoKey.maximumCount]
as AnyObject).uint64Value ?? 0
print("NbMaps tile count limit exceeded: \(maximumCount)")
// set download state to inactive
isCompleted = true
channelHandler.onError(
Expand Down
3 changes: 0 additions & 3 deletions ios/Classes/SwiftNbMapsFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ public class SwiftNbMapsFlutterPlugin: NSObject, FlutterPlugin {
let defintion = OfflineRegionDefinition.fromDictionary(definitionDictionary),
let channelName = args["channelName"] as? String
else {
print(
"downloadOfflineRegion unexpected arguments: \(String(describing: methodCall.arguments))"
)
result(nil)
return
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,16 @@ class NextbillionMapController extends ChangeNotifier {

/// Starts an animated change of the map camera position.
///
/// [duration] is the amount of time, that the transition animation should take.
/// [duration] is the amount of time, that the transition animation should take. This must be strictly
/// positive, otherwise an IllegalArgumentException will be thrown.
///
/// The returned [Future] completes after the change has been started on the
/// platform side.
/// It returns true if the camera was successfully moved and false if the movement was canceled.
/// Note: this currently always returns immediately with a value of null on iOS
Future<bool?> animateCamera(CameraUpdate cameraUpdate,
{Duration? duration}) async {
assert(duration == null || duration > Duration.zero, 'Duration must be greater than zero');

Check warning on line 295 in lib/src/controller.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/controller.dart#L295

Added line #L295 was not covered by tests
if (_disposed) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/platform_interface/method_channel_nbmaps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ class MethodChannelNbMapsGl extends NbMapsGlPlatform {
@override
Future<String> takeSnapshot(SnapshotOptions snapshotOptions) async {
try {
debugPrint("${snapshotOptions.toJson()}");
debugLog("${snapshotOptions.toJson()}");

Check warning on line 772 in lib/src/platform_interface/method_channel_nbmaps.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/platform_interface/method_channel_nbmaps.dart#L772

Added line #L772 was not covered by tests
var uri = await _channel.invokeMethod(
'snapshot#takeSnapshot', snapshotOptions.toJson());
return uri;
Expand Down
27 changes: 27 additions & 0 deletions lib/src/platform_interface/nextbillion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,80 @@ class NextBillion {
_nextBillionChannel = channel;
}

/// Initializes the NextBillion SDK with the provided [accessKey].
static Future<void> initNextBillion(String accessKey) async {
Map<String, dynamic> config = {"accessKey": accessKey};
return await _nextBillionChannel.invokeMethod(
"nextbillion/init_nextbillion", config);
}

/// Retrieves the access key.
/// To get the current access key used for initNextBillion.
/// Returns a [Future] that completes with the access key as a [String].
static Future<String> getAccessKey() async {
return await _nextBillionChannel.invokeMethod("nextbillion/get_access_key");
}

/// Sets the access key.
/// [accessKey] The access key to be set.
static Future<void> setAccessKey(String accessKey) async {
Map<String, dynamic> config = {"accessKey": accessKey};
return await _nextBillionChannel.invokeMethod(
"nextbillion/set_access_key", config);
}

/// Retrieves the base URI.
/// To get the current base URI used for Map Style API requests.
///
/// Returns a [Future] that completes with the base URI as a [String].
static Future<String> getBaseUri() async {
return await _nextBillionChannel.invokeMethod("nextbillion/get_base_uri");
}

/// Sets the base URI.
///
/// To set a new base URI used for Map Style API requests.
///
/// [baseUri] The base URI to be set.
static Future<void> setBaseUri(String baseUri) async {
Map<String, dynamic> config = {"baseUri": baseUri};
return await _nextBillionChannel.invokeMethod(
"nextbillion/set_base_uri", config);
}

/// Sets the API key header name.
///
/// To set a new header name used for the API key in HTTP requests.
///
/// [apiKeyHeaderName] The name of the API key header to be set.
///
static Future<void> setApiKeyHeaderName(String apiKeyHeaderName) async {
Map<String, dynamic> config = {"apiKeyHeaderName": apiKeyHeaderName};
return await _nextBillionChannel.invokeMethod(
"nextbillion/set_key_header_name", config);
}

/// Retrieves the API key header name.
///
/// To get the current header name used for the API key in HTTP requests.
static Future<String> getApiKeyHeaderName() async {
return await _nextBillionChannel
.invokeMethod("nextbillion/get_key_header_name");
}

/// Get the NextBillion ID for the current user.
static Future<String> getNbId() async {
return await _nextBillionChannel.invokeMethod("nextbillion/get_nb_id");
}

/// Set the user ID for the current user if you need to add a user ID to the navigation request user-agent.
static Future<void> setUserId(String id) async {
Map<String, dynamic> config = {"userId": id};
return await _nextBillionChannel.invokeMethod(
"nextbillion/set_user_id", config);
}

/// Get the user ID for the current user if you need to add a user ID to the navigation request user-agent.
static Future<String?> getUserId() async {
return await _nextBillionChannel.invokeMethod("nextbillion/get_user_id");
}
Expand Down
21 changes: 15 additions & 6 deletions lib/src/util.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
part of nb_maps_flutter;

Map<String, dynamic> buildFeatureCollection(
List<Map<String, dynamic>> features) {
Map<String, dynamic> buildFeatureCollection(List<Map<String, dynamic>> features) {
return {"type": "FeatureCollection", "features": features};
}

final _random = Random();
String getRandomString([int length = 10]) {
const charSet =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
return String.fromCharCodes(Iterable.generate(
length, (_) => charSet.codeUnitAt(_random.nextInt(charSet.length))));
const charSet = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
return String.fromCharCodes(Iterable.generate(length, (_) => charSet.codeUnitAt(_random.nextInt(charSet.length))));
}

/// Logs a debug message.
///
/// This method prints the [message] to the console only if the app is in
/// debug mode. In release mode, it does nothing.
///
/// [message] The message to log.
void debugLog(String message) {

Check warning on line 19 in lib/src/util.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/util.dart#L19

Added line #L19 was not covered by tests
if (!kReleaseMode) {
print('$message');

Check warning on line 21 in lib/src/util.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/util.dart#L21

Added line #L21 was not covered by tests
}
}

0 comments on commit efe33e3

Please sign in to comment.