Skip to content

Commit

Permalink
Add styleGlyphURL property (#753)
Browse files Browse the repository at this point in the history
* format

* Expose styleGlyphURL API
  • Loading branch information
evil159 authored Oct 31, 2024
1 parent bb48849 commit 92aa0b3
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class MapInterfaceController(
callback(Result.success(Unit))
}

override fun styleGlyphURL(): String = mapboxMap.getStyleGlyphURL()

override fun setStyleGlyphURL(glyphURL: String) = mapboxMap.setStyleGlyphURL(glyphURL)

override fun loadStyleURI(styleURI: String, callback: (Result<Unit>) -> Unit) {
mapboxMap.loadStyleUri(
styleURI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3215,6 +3215,20 @@ interface _MapInterface {
* Note: This method has no effect on iOS platform.
*/
fun setSnapshotLegacyMode(enabled: Boolean, callback: (Result<Unit>) -> Unit)
/**
* The URL that points to the glyphs used by the style for rendering text labels on the map.
*
* This property allows setting a custom glyph URL at runtime, making it easier to
* apply custom fonts to the map without modifying the base style.
*/
fun styleGlyphURL(): String
/**
* The URL that points to the glyphs used by the style for rendering text labels on the map.
*
* This property allows setting a custom glyph URL at runtime, making it easier to
* apply custom fonts to the map without modifying the base style.
*/
fun setStyleGlyphURL(glyphURL: String)

companion object {
/** The codec used by _MapInterface. */
Expand Down Expand Up @@ -3807,6 +3821,39 @@ interface _MapInterface {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.styleGlyphURL$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
val wrapped: List<Any?> = try {
listOf(api.styleGlyphURL())
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.setStyleGlyphURL$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val glyphURLArg = args[0] as String
val wrapped: List<Any?> = try {
api.setStyleGlyphURL(glyphURLArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions example/integration_test/map_interface_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import 'empty_map_widget.dart' as app;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('styleGlyphURL', (WidgetTester tester) async {
final mapFuture = app.main();
await tester.pumpAndSettle();
final mapboxMap = await mapFuture;
final styleGlyphURL = 'test://test/test/{fontstack}/{range}.pbf';

await mapboxMap.setStyleGlyphURL(styleGlyphURL);
expect(await mapboxMap.styleGlyphURL(), styleGlyphURL);
});

testWidgets('loadStyleURI', (WidgetTester tester) async {
final mapFuture = app.main();
await tester.pumpAndSettle();
Expand Down
4 changes: 3 additions & 1 deletion example/integration_test/snapshotter/snapshotter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void main() {
final snapshotter = await Snapshotter.create(
options: options,
onStyleLoadedListener: styleLoaded.complete,
onStyleDataLoadedListener: (e) { if(!styleDataLoaded.isCompleted) styleDataLoaded.complete(e); },
onStyleDataLoadedListener: (e) {
if (!styleDataLoaded.isCompleted) styleDataLoaded.complete(e);
},
);

await snapshotter.style.setStyleURI(MapboxStyles.LIGHT);
Expand Down
50 changes: 35 additions & 15 deletions example/lib/traffic_route_line_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class TrafficRouteLineExample extends StatefulWidget implements Example {
@override
final String title = 'Style a route showing traffic';
@override
final String subtitle = "Use LineLayer to style a route line with traffic data.";
final String subtitle =
"Use LineLayer to style a route line with traffic data.";

@override
State createState() => TrafficRouteLineExampleState();
Expand All @@ -31,7 +32,6 @@ class TrafficRouteLineExampleState extends State<TrafficRouteLineExample> {
}

_addRouteLine() async {

await mapboxMap.style.addLayer(LineLayer(
id: "line-layer",
sourceId: "line",
Expand All @@ -40,23 +40,43 @@ class TrafficRouteLineExampleState extends State<TrafficRouteLineExample> {
// by interpolating exponentially between stops.
// Doc: https://docs.mapbox.com/style-spec/reference/expressions/
lineWidthExpression: [
'interpolate', ['exponential', 1.5], ['zoom'],
4.0, 6.0,
10.0, 7.0,
13.0, 9.0,
16.0, 3.0,
19.0, 7.0,
22.0, 21.0,
'interpolate',
['exponential', 1.5],
['zoom'],
4.0,
6.0,
10.0,
7.0,
13.0,
9.0,
16.0,
3.0,
19.0,
7.0,
22.0,
21.0,
],
lineBorderWidthExpression: [
'interpolate', ['exponential', 1.5], ['zoom'],
9.0, 1.0,
16.0, 3.0,
'interpolate',
['exponential', 1.5],
['zoom'],
9.0,
1.0,
16.0,
3.0,
],
lineColorExpression: [
'interpolate', ['linear'], ['zoom'],
8.0, 'rgb(51, 102, 255)',
11.0, ['coalesce', ['get', 'route-color'], 'rgb(51, 102, 255)'],
'interpolate',
['linear'],
['zoom'],
8.0,
'rgb(51, 102, 255)',
11.0,
[
'coalesce',
['get', 'route-color'],
'rgb(51, 102, 255)'
],
],
));
}
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.3.0"
version: "2.4.0-beta.1"
matcher:
dependency: transitive
description:
Expand Down
46 changes: 46 additions & 0 deletions ios/Classes/Generated/MapInterfaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2973,6 +2973,16 @@ protocol _MapInterface {
///
/// Note: This method has no effect on iOS platform.
func setSnapshotLegacyMode(enabled: Bool, completion: @escaping (Result<Void, Error>) -> Void)
/// The URL that points to the glyphs used by the style for rendering text labels on the map.
///
/// This property allows setting a custom glyph URL at runtime, making it easier to
/// apply custom fonts to the map without modifying the base style.
func styleGlyphURL() throws -> String
/// The URL that points to the glyphs used by the style for rendering text labels on the map.
///
/// This property allows setting a custom glyph URL at runtime, making it easier to
/// apply custom fonts to the map without modifying the base style.
func setStyleGlyphURL(glyphURL: String) throws
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
Expand Down Expand Up @@ -3612,6 +3622,42 @@ class _MapInterfaceSetup {
} else {
setSnapshotLegacyModeChannel.setMessageHandler(nil)
}
/// The URL that points to the glyphs used by the style for rendering text labels on the map.
///
/// This property allows setting a custom glyph URL at runtime, making it easier to
/// apply custom fonts to the map without modifying the base style.
let styleGlyphURLChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.styleGlyphURL\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
styleGlyphURLChannel.setMessageHandler { _, reply in
do {
let result = try api.styleGlyphURL()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
styleGlyphURLChannel.setMessageHandler(nil)
}
/// The URL that points to the glyphs used by the style for rendering text labels on the map.
///
/// This property allows setting a custom glyph URL at runtime, making it easier to
/// apply custom fonts to the map without modifying the base style.
let setStyleGlyphURLChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.setStyleGlyphURL\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
setStyleGlyphURLChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let glyphURLArg = args[0] as! String
do {
try api.setStyleGlyphURL(glyphURL: glyphURLArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
setStyleGlyphURLChannel.setMessageHandler(nil)
}
}
}
/// Collection of [Spherical Mercator](http://docs.openlayers.org/library/spherical_mercator.html) projection methods.
Expand Down
9 changes: 9 additions & 0 deletions ios/Classes/MapInterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Flutter
import Turf

final class MapInterfaceController: _MapInterface {

private static let errorCode = "0"
private let mapboxMap: MapboxMap
private let mapView: MapView
Expand All @@ -18,6 +19,14 @@ final class MapInterfaceController: _MapInterface {
completion(.success(()))
}

func styleGlyphURL() throws -> String {
return mapboxMap.styleGlyphURL
}

func setStyleGlyphURL(glyphURL: String) throws {
mapboxMap.styleGlyphURL = glyphURL
}

func loadStyleURI(styleURI: String, completion: @escaping (Result<Void, Error>) -> Void) {
self.mapboxMap.loadStyle(StyleURI(rawValue: styleURI)!) { error in
if let error {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/annotation/annotation_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class AnnotationManager {
/// The super class for all AnnotationManagers.
class BaseAnnotationManager {
BaseAnnotationManager._(
{required String id,
required BinaryMessenger messenger})
{required String id, required BinaryMessenger messenger})
: this.id = id,
_messenger = messenger;
final String id;
Expand Down
13 changes: 13 additions & 0 deletions lib/src/mapbox_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ class MapboxMap extends ChangeNotifier {
/// Returns the `map options`.
Future<MapOptions> getMapOptions() => _mapInterface.getMapOptions();

/// The URL that points to the glyphs used by the style for rendering text labels on the map.
///
/// This property allows setting a custom glyph URL at runtime, making it easier to
/// apply custom fonts to the map without modifying the base style.
Future<String> styleGlyphURL() => _mapInterface.styleGlyphURL();

/// The URL that points to the glyphs used by the style for rendering text labels on the map.
///
/// This property allows setting a custom glyph URL at runtime, making it easier to
/// apply custom fonts to the map without modifying the base style.
Future<void> setStyleGlyphURL(String glyphURL) =>
_mapInterface.setStyleGlyphURL(glyphURL);

/// Debug options for the widget associated with the map.
Future<List<MapWidgetDebugOptions>> getDebugOptions() async {
return _mapInterface.getDebugOptions().then((value) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/offline/offline_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ final class OfflineManager {
OnStylePackLoadProgressListener? progressListener) async {
if (progressListener != null) {
await _api.addStylePackLoadProgressListener(styleURI);
final eventChannel =
EventChannel("com.mapbox.maps.flutter/${_messageChannel}/${styleURI}");
final eventChannel = EventChannel(
"com.mapbox.maps.flutter/${_messageChannel}/${styleURI}");
eventChannel.receiveBroadcastStream().listen((event) {
progressListener(StylePackLoadProgress.decode(event));
});
Expand Down
4 changes: 2 additions & 2 deletions lib/src/offline/tile_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ final class TileStore {
OnTileRegionLoadProgressListener? progressListener) async {
if (progressListener != null) {
await _api.addTileRegionLoadProgressListener(id);
final eventChannel =
EventChannel("com.mapbox.maps.flutter/${_messageChannel}/tile-region-${id}");
final eventChannel = EventChannel(
"com.mapbox.maps.flutter/${_messageChannel}/tile-region-${id}");
eventChannel.receiveBroadcastStream().listen((event) {
progressListener(TileRegionLoadProgress.decode(event));
});
Expand Down
61 changes: 61 additions & 0 deletions lib/src/pigeons/map_interfaces.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 92aa0b3

Please sign in to comment.