Skip to content

Commit

Permalink
remove old localization module, fix android + web
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanschaller committed Aug 7, 2023
1 parent ec9808e commit 79650c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
1 change: 0 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ android {
dependencies {
implementation 'org.maplibre.gl:android-sdk:10.2.0'
implementation 'org.maplibre.gl:android-plugin-annotation-v9:2.0.0'
implementation 'org.maplibre.gl:android-plugin-localization-v9:2.0.0'
implementation 'org.maplibre.gl:android-plugin-offline-v9:2.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
}
Expand Down
26 changes: 21 additions & 5 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.offline.OfflineManager;
import com.mapbox.mapboxsdk.plugins.localization.LocalizationPlugin;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
Expand Down Expand Up @@ -89,6 +88,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -131,7 +131,6 @@ final class MapboxMapController
private MethodChannel.Result mapReadyResult;
private LocationComponent locationComponent = null;
private LocationEngineCallback<LocationEngineResult> locationEngineCallback = null;
private LocalizationPlugin localizationPlugin;
private Style style;
private Feature draggedFeature;
private AndroidGesturesManager androidGesturesManager;
Expand Down Expand Up @@ -163,7 +162,6 @@ public void onStyleLoaded(@NonNull Style style) {

mapboxMap.addOnMapClickListener(MapboxMapController.this);
mapboxMap.addOnMapLongClickListener(MapboxMapController.this);
localizationPlugin = new LocalizationPlugin(mapView, mapboxMap, style);

methodChannel.invokeMethod("map#onStyleLoaded", null);
}
Expand Down Expand Up @@ -644,7 +642,10 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
case "map#matchMapLanguageWithDeviceDefault":
{
try {
localizationPlugin.matchMapLanguageWithDeviceDefault();
final Locale deviceLocale = Locale.getDefault();

setMapLanguage(deviceLocale.getLanguage());

result.success(null);
} catch (RuntimeException exception) {
Log.d(TAG, exception.toString());
Expand Down Expand Up @@ -673,7 +674,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
{
final String language = call.argument("language");
try {
localizationPlugin.setMapLanguage(language);
setMapLanguage(language);
result.success(null);
} catch (RuntimeException exception) {
Log.d(TAG, exception.toString());
Expand Down Expand Up @@ -1794,6 +1795,21 @@ public void setAttributionButtonMargins(int x, int y) {
}
}

private void setMapLanguage(String language){
final List<Layer> layers = mapboxMap.getStyle().getLayers();

final String expressionValue = String.format("['get', 'name:%s']", language);

final PropertyValue<Expression> newExpression =
PropertyFactory.textField(Expression.raw(expressionValue));

for (final Layer layer : layers) {
if(layer instanceof SymbolLayer) {
layer.setProperties(newExpression);
}
}
}

private void updateMyLocationEnabled() {
if (this.locationComponent == null && myLocationEnabled) {
enableLocationComponent(mapboxMap.getStyle());
Expand Down
14 changes: 9 additions & 5 deletions maplibre_gl_web/lib/src/mapbox_web_gl_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,15 @@ class MaplibreMapController extends MapLibreGlPlatform

@override
Future<void> setMapLanguage(String language) async {
_map.setLayoutProperty(
'country-label',
'text-field',
['get', 'name_' + language],
);
final List<dynamic> layers = _map.getStyle().layers;

final newExpression = ['get', 'name:' + language];

for (final layer in layers) {
if (layer.type == 'symbol') {
_map.setLayoutProperty(layer.id, 'text-field', newExpression);
}
}
}

@override
Expand Down

0 comments on commit 79650c0

Please sign in to comment.