Skip to content

Commit

Permalink
Expose Style.localizeLabels API.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunikkk committed Dec 22, 2022
1 parent 0817403 commit 43fc841
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 0 deletions.

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import android.graphics.BitmapFactory
import com.mapbox.bindgen.Value
import com.mapbox.common.Logger
import com.mapbox.maps.*
import com.mapbox.maps.extension.localization.localizeLabels
import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionName
import com.mapbox.maps.extension.style.projection.generated.Projection
import com.mapbox.maps.extension.style.projection.generated.getProjection
import com.mapbox.maps.extension.style.projection.generated.setProjection
import com.mapbox.maps.pigeons.FLTMapInterfaces
import java.nio.ByteBuffer
import java.util.Locale

class StyleController(private val mapboxMap: MapboxMap) : FLTMapInterfaces.StyleManager {
override fun getStyleURI(result: FLTMapInterfaces.Result<String>) {
Expand Down Expand Up @@ -584,6 +586,17 @@ class StyleController(private val mapboxMap: MapboxMap) : FLTMapInterfaces.Style
}
}

override fun localizeLabels(
locale: String,
layerIds: MutableList<String>?,
result: FLTMapInterfaces.Result<Void>
) {
mapboxMap.getStyle {
it.localizeLabels(Locale(locale), layerIds)
result.success(null)
}
}

override fun addStyleImage(
imageId: String,
scale: Double,
Expand Down
16 changes: 16 additions & 0 deletions example/lib/style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class StylePageBodyState extends State<StylePageBody> {

MapboxMap? mapboxMap;
var mapProject = 'globe';
var locale = 'en';

_onMapCreated(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
Expand Down Expand Up @@ -446,6 +447,20 @@ class StylePageBodyState extends State<StylePageBody> {
);
}

Widget _changeLocale() {
return TextButton(
child: Text('changeLocale'),
onPressed: () {
if (locale == 'en') {
locale = 'de';
} else {
locale = 'en';
}
mapboxMap?.style.localizeLabels(locale, null);
},
);
}

@override
Widget build(BuildContext context) {
final MapWidget mapWidget = MapWidget(
Expand Down Expand Up @@ -484,6 +499,7 @@ class StylePageBodyState extends State<StylePageBody> {
_isStyleLoaded(),
_getProjection(),
_setProjection(),
_changeLocale(),
],
);

Expand Down
1 change: 1 addition & 0 deletions ios/Classes/MapInterfaces.h

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

21 changes: 21 additions & 0 deletions ios/Classes/MapInterfaces.m

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

5 changes: 5 additions & 0 deletions ios/Classes/StyleController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,10 @@ class StyleController: NSObject, FLTStyleManager {
completion(nil)
}

func localizeLabelsLocale(_ locale: String, layerIds: [String]?, completion: @escaping (FlutterError?) -> Void) {
try! mapboxMap.style.localizeLabels(into: Locale(identifier: locale), forLayerIds: layerIds)
completion(nil)
}

private static let errorCode = "0"
}
25 changes: 25 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.

25 changes: 25 additions & 0 deletions lib/src/pigeons/map_interfaces.dart.orig

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

15 changes: 15 additions & 0 deletions scripts/check-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

echo "-> Running 'flutter format' to check project dart style."

RESULT=$(flutter format -n lib example/lib example/integration_test)

if [[ $? != 0 ]]; then
echo "----> Command failed."
elif [[ $RESULT == *"0 changed"* ]]; then
echo "----> All format is good ✅"
else
echo "----> Some files are not well formated:"
echo "$RESULT"
exit 1
fi

0 comments on commit 43fc841

Please sign in to comment.