Skip to content

Commit 0c09b57

Browse files
committed
(feat) annotation and log checking
1 parent fa4b6bf commit 0c09b57

File tree

9 files changed

+65
-19
lines changed

9 files changed

+65
-19
lines changed

example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ final List<ExamplePage> _allPages = <ExamplePage>[
4141
PlaceCirclePage(),
4242
PlaceFillPage(),
4343
ScrollingMapPage(),
44-
OfflineRegionsPage(),
44+
// OfflineRegionsPage(),
4545
AnnotationOrderPage(),
4646
CustomMarkerPage(),
4747
BatchAddPage(),
4848
TakeSnapPage(),
4949
ClickAnnotationPage(),
50-
Sources(),
50+
// Sources(),
5151
TrackCurrentLocationPage()
5252
];
5353

ios/Classes/NextbillionMapController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,6 @@ class NextbillionMapController: NSObject, FlutterPlatformView, NGLMapViewDelegat
16431643
let source = NGLShapeSource(identifier: sourceId, shape: parsed, options: [:])
16441644
addedShapesByLayer[sourceId] = parsed
16451645
mapView.style?.addSource(source)
1646-
print(source)
16471646
} catch {}
16481647
}
16491648

ios/Classes/OfflinePackDownloadManager.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class OfflinePackDownloader {
4141
}
4242

4343
deinit {
44-
print("Removing offline pack notification observers")
4544
NotificationCenter.default.removeObserver(self)
4645
}
4746

@@ -111,7 +110,6 @@ class OfflinePackDownloader {
111110
)
112111
// Check if downloading is complete
113112
if pack.state == .complete {
114-
print("Region downloaded successfully")
115113
// set download state to inactive
116114
// This can be called multiple times but result can only be called once. We use this
117115
// check to ensure that
@@ -123,7 +121,6 @@ class OfflinePackDownloader {
123121
OfflineManagerUtils.releaseDownloader(id: region.id)
124122
}
125123
} else {
126-
print("Region download progress \(downloadProgress)")
127124
channelHandler.onProgress(progress: downloadProgress)
128125
}
129126
}
@@ -132,7 +129,6 @@ class OfflinePackDownloader {
132129
guard let pack = notification.object as? NGLOfflinePack,
133130
verifyPack(pack: pack) else { return }
134131
let error = notification.userInfo?[NGLOfflinePackUserInfoKey.error] as? NSError
135-
print("Pack download error: \(String(describing: error?.localizedDescription))")
136132
// set download state to inactive
137133
isCompleted = true
138134
channelHandler.onError(
@@ -155,7 +151,6 @@ class OfflinePackDownloader {
155151
verifyPack(pack: pack) else { return }
156152
let maximumCount = (notification.userInfo?[NGLOfflinePackUserInfoKey.maximumCount]
157153
as AnyObject).uint64Value ?? 0
158-
print("NbMaps tile count limit exceeded: \(maximumCount)")
159154
// set download state to inactive
160155
isCompleted = true
161156
channelHandler.onError(

ios/Classes/SwiftNbMapsFlutterPlugin.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ public class SwiftNbMapsFlutterPlugin: NSObject, FlutterPlugin {
106106
let defintion = OfflineRegionDefinition.fromDictionary(definitionDictionary),
107107
let channelName = args["channelName"] as? String
108108
else {
109-
print(
110-
"downloadOfflineRegion unexpected arguments: \(String(describing: methodCall.arguments))"
111-
)
112109
result(nil)
113110
return
114111
}

lib/src/controller.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,16 @@ class NextbillionMapController extends ChangeNotifier {
283283

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

lib/src/platform_interface/method_channel_nbmaps.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ class MethodChannelNbMapsGl extends NbMapsGlPlatform {
769769
@override
770770
Future<String> takeSnapshot(SnapshotOptions snapshotOptions) async {
771771
try {
772-
debugPrint("${snapshotOptions.toJson()}");
772+
debugLog("${snapshotOptions.toJson()}");
773773
var uri = await _channel.invokeMethod(
774774
'snapshot#takeSnapshot', snapshotOptions.toJson());
775775
return uri;

lib/src/platform_interface/nextbillion.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,80 @@ class NextBillion {
1111
_nextBillionChannel = channel;
1212
}
1313

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

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

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

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

44+
/// Sets the base URI.
45+
///
46+
/// To set a new base URI used for Map Style API requests.
47+
///
48+
/// [baseUri] The base URI to be set.
3449
static Future<void> setBaseUri(String baseUri) async {
3550
Map<String, dynamic> config = {"baseUri": baseUri};
3651
return await _nextBillionChannel.invokeMethod(
3752
"nextbillion/set_base_uri", config);
3853
}
3954

55+
/// Sets the API key header name.
56+
///
57+
/// To set a new header name used for the API key in HTTP requests.
58+
///
59+
/// [apiKeyHeaderName] The name of the API key header to be set.
60+
///
4061
static Future<void> setApiKeyHeaderName(String apiKeyHeaderName) async {
4162
Map<String, dynamic> config = {"apiKeyHeaderName": apiKeyHeaderName};
4263
return await _nextBillionChannel.invokeMethod(
4364
"nextbillion/set_key_header_name", config);
4465
}
4566

67+
/// Retrieves the API key header name.
68+
///
69+
/// To get the current header name used for the API key in HTTP requests.
4670
static Future<String> getApiKeyHeaderName() async {
4771
return await _nextBillionChannel
4872
.invokeMethod("nextbillion/get_key_header_name");
4973
}
5074

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

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

87+
/// Get the user ID for the current user if you need to add a user ID to the navigation request user-agent.
6188
static Future<String?> getUserId() async {
6289
return await _nextBillionChannel.invokeMethod("nextbillion/get_user_id");
6390
}

lib/src/util.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
part of nb_maps_flutter;
22

3-
Map<String, dynamic> buildFeatureCollection(
4-
List<Map<String, dynamic>> features) {
3+
Map<String, dynamic> buildFeatureCollection(List<Map<String, dynamic>> features) {
54
return {"type": "FeatureCollection", "features": features};
65
}
76

87
final _random = Random();
98
String getRandomString([int length = 10]) {
10-
const charSet =
11-
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
12-
return String.fromCharCodes(Iterable.generate(
13-
length, (_) => charSet.codeUnitAt(_random.nextInt(charSet.length))));
9+
const charSet = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
10+
return String.fromCharCodes(Iterable.generate(length, (_) => charSet.codeUnitAt(_random.nextInt(charSet.length))));
11+
}
12+
13+
/// Logs a debug message.
14+
///
15+
/// This method prints the [message] to the console only if the app is in
16+
/// debug mode. In release mode, it does nothing.
17+
///
18+
/// [message] The message to log.
19+
void debugLog(String message) {
20+
if (!kReleaseMode) {
21+
print('$message');
22+
}
1423
}

test/src/util_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/foundation.dart';
13
import 'package:nb_maps_flutter/nb_maps_flutter.dart';
24
import 'package:test/test.dart';
35

@@ -28,4 +30,19 @@ void main() {
2830
// Assert
2931
expect(result.length, equals(length));
3032
});
33+
34+
test('log prints message in debug mode', () {
35+
var logOutput = <String>[];
36+
debugPrint = (String? message, {int? wrapWidth}) {
37+
if (message != null) {
38+
logOutput.add(message);
39+
}
40+
};
41+
42+
debugLog('Test message');
43+
expect(logOutput, contains('Test message'));
44+
45+
// Reset debugPrint
46+
debugPrint = debugPrintThrottled;
47+
});
3148
}

0 commit comments

Comments
 (0)