From 69664cbcb3def29e6ec6deada77101f8a200bc37 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 14 May 2024 19:37:47 +0200 Subject: [PATCH 1/4] maplibre v11 --- android/build.gradle | 2 +- android/settings.gradle | 2 +- .../java/com/mapbox/mapboxgl/MapBoxUtils.java | 12 -- .../maplibre/maplibregl}/Convert.java | 30 ++-- .../maplibregl}/GlobalMethodHandler.java | 8 +- .../maplibregl}/LayerPropertyConverter.java | 10 +- .../maplibregl/MapLibreHttpRequestUtil.java} | 6 +- .../maplibregl/MapLibreMapBuilder.java} | 22 +-- .../maplibregl/MapLibreMapController.java} | 155 +++++++++--------- .../maplibregl/MapLibreMapFactory.java} | 16 +- .../maplibregl/MapLibreMapOptionsSink.kt} | 8 +- .../maplibregl/MapLibreMapsPlugin.java} | 12 +- .../maplibre/maplibregl/MapLibreUtils.java | 12 ++ .../OfflineChannelHandlerImpl.java | 2 +- .../maplibregl}/OfflineManagerUtils.java | 24 +-- .../maplibregl}/SourcePropertyConverter.java | 26 +-- .../maplibre/maplibregl}/setMapLanguage.kt | 14 +- pubspec.yaml | 4 +- 18 files changed, 182 insertions(+), 183 deletions(-) delete mode 100644 android/src/main/java/com/mapbox/mapboxgl/MapBoxUtils.java rename android/src/main/java/{com/mapbox/mapboxgl => org/maplibre/maplibregl}/Convert.java (91%) rename android/src/main/java/{com/mapbox/mapboxgl => org/maplibre/maplibregl}/GlobalMethodHandler.java (96%) rename android/src/main/java/{com/mapbox/mapboxgl => org/maplibre/maplibregl}/LayerPropertyConverter.java (98%) rename android/src/main/java/{com/mapbox/mapboxgl/MapboxHttpRequestUtil.java => org/maplibre/maplibregl/MapLibreHttpRequestUtil.java} (91%) rename android/src/main/java/{com/mapbox/mapboxgl/MapboxMapBuilder.java => org/maplibre/maplibregl/MapLibreMapBuilder.java} (91%) rename android/src/main/java/{com/mapbox/mapboxgl/MapboxMapController.java => org/maplibre/maplibregl/MapLibreMapController.java} (94%) rename android/src/main/java/{com/mapbox/mapboxgl/MapboxMapFactory.java => org/maplibre/maplibregl/MapLibreMapFactory.java} (71%) rename android/src/main/java/{com/mapbox/mapboxgl/MapboxMapOptionsSink.kt => org/maplibre/maplibregl/MapLibreMapOptionsSink.kt} (87%) rename android/src/main/java/{com/mapbox/mapboxgl/MapboxMapsPlugin.java => org/maplibre/maplibregl/MapLibreMapsPlugin.java} (89%) create mode 100644 android/src/main/java/org/maplibre/maplibregl/MapLibreUtils.java rename android/src/main/java/{com/mapbox/mapboxgl => org/maplibre/maplibregl}/OfflineChannelHandlerImpl.java (97%) rename android/src/main/java/{com/mapbox/mapboxgl => org/maplibre/maplibregl}/OfflineManagerUtils.java (95%) rename android/src/main/java/{com/mapbox/mapboxgl => org/maplibre/maplibregl}/SourcePropertyConverter.java (91%) rename android/src/main/java/{com/mapbox/mapboxgl => org/maplibre/maplibregl}/setMapLanguage.kt (68%) diff --git a/android/build.gradle b/android/build.gradle index 9c6836329..de94837fe 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -46,7 +46,7 @@ android { jvmTarget = JavaVersion.VERSION_1_8 } dependencies { - implementation 'org.maplibre.gl:android-sdk:10.2.0' + implementation 'org.maplibre.gl:android-sdk:11.0.0' implementation 'org.maplibre.gl:android-plugin-annotation-v9:2.0.0' implementation 'org.maplibre.gl:android-plugin-offline-v9:2.0.0' implementation 'com.squareup.okhttp3:okhttp:4.10.0' diff --git a/android/settings.gradle b/android/settings.gradle index e907b9818..2ea73f089 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1 +1 @@ -rootProject.name = 'mapbox_gl' +rootProject.name = 'maplibre_gl' diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapBoxUtils.java b/android/src/main/java/com/mapbox/mapboxgl/MapBoxUtils.java deleted file mode 100644 index e5bc1cb21..000000000 --- a/android/src/main/java/com/mapbox/mapboxgl/MapBoxUtils.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mapbox.mapboxgl; - -import android.content.Context; -import com.mapbox.mapboxsdk.Mapbox; - -abstract class MapBoxUtils { - private static final String TAG = "MapboxMapController"; - - static Mapbox getMapbox(Context context) { - return Mapbox.getInstance(context); - } -} diff --git a/android/src/main/java/com/mapbox/mapboxgl/Convert.java b/android/src/main/java/org/maplibre/maplibregl/Convert.java similarity index 91% rename from android/src/main/java/com/mapbox/mapboxgl/Convert.java rename to android/src/main/java/org/maplibre/maplibregl/Convert.java index f22b9d068..c15fc69be 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/Convert.java +++ b/android/src/main/java/org/maplibre/maplibregl/Convert.java @@ -2,25 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import android.content.Context; import android.graphics.Point; import android.util.DisplayMetrics; -import com.mapbox.geojson.Polygon; -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.camera.CameraUpdate; -import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.geometry.LatLngBounds; -import com.mapbox.mapboxsdk.maps.MapboxMap; +import org.maplibre.geojson.Polygon; +import org.maplibre.android.camera.CameraPosition; +import org.maplibre.android.camera.CameraUpdate; +import org.maplibre.android.camera.CameraUpdateFactory; +import org.maplibre.android.geometry.LatLng; +import org.maplibre.android.geometry.LatLngBounds; +import org.maplibre.android.maps.MapLibreMap; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -/** Conversions between JSON-like values and MapboxMaps data types. */ +/** Conversions between JSON-like values and MapLibreMaps data types. */ class Convert { private static final String TAG = "Convert"; @@ -43,7 +43,7 @@ static boolean isScrollByCameraUpdate(Object o) { return toString(toList(o).get(0)).equals("scrollBy"); } - static CameraUpdate toCameraUpdate(Object o, MapboxMap mapboxMap, float density) { + static CameraUpdate toCameraUpdate(Object o, MapLibreMap maplibreMap, float density) { final List data = toList(o); switch (toString(data.get(0))) { case "newCameraPosition": @@ -60,7 +60,7 @@ static CameraUpdate toCameraUpdate(Object o, MapboxMap mapboxMap, float density) case "newLatLngZoom": return CameraUpdateFactory.newLatLngZoom(toLatLng(data.get(1)), toFloat(data.get(2))); case "scrollBy": - mapboxMap.scrollBy( + maplibreMap.scrollBy( toFractionalPixels(data.get(1), density), toFractionalPixels(data.get(2), density)); return null; case "zoomBy": @@ -164,12 +164,12 @@ private static List> toLatLngListList(Object o) { } static Polygon interpretListLatLng(List> geometry) { - List> points = new ArrayList<>(geometry.size()); + List> points = new ArrayList<>(geometry.size()); for (List innerGeometry : geometry) { - List innerPoints = new ArrayList<>(innerGeometry.size()); + List innerPoints = new ArrayList<>(innerGeometry.size()); for (LatLng latLng : innerGeometry) { innerPoints.add( - com.mapbox.geojson.Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())); + org.maplibre.geojson.Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())); } points.add(innerPoints); } @@ -205,7 +205,7 @@ static String toString(Object o) { return (String) o; } - static void interpretMapboxMapOptions(Object o, MapboxMapOptionsSink sink, Context context) { + static void interpretMapLibreMapOptions(Object o, MapLibreMapOptionsSink sink, Context context) { final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); final Map data = toMap(o); final Object cameraTargetBounds = data.get("cameraTargetBounds"); diff --git a/android/src/main/java/com/mapbox/mapboxgl/GlobalMethodHandler.java b/android/src/main/java/org/maplibre/maplibregl/GlobalMethodHandler.java similarity index 96% rename from android/src/main/java/com/mapbox/mapboxgl/GlobalMethodHandler.java rename to android/src/main/java/org/maplibre/maplibregl/GlobalMethodHandler.java index 6b064eab5..a94b7cf5b 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/GlobalMethodHandler.java +++ b/android/src/main/java/org/maplibre/maplibregl/GlobalMethodHandler.java @@ -1,10 +1,10 @@ -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import android.content.Context; import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.mapbox.mapboxsdk.net.ConnectivityReceiver; +import org.maplibre.android.net.ConnectivityReceiver; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; @@ -70,7 +70,7 @@ private static void copy(InputStream input, OutputStream output) throws IOExcept @Override public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { - MapBoxUtils.getMapbox(context); + MapLibreUtils.getMapLibre(context); switch (methodCall.method) { case "installOfflineMapTiles": @@ -92,7 +92,7 @@ public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { break; case "setHttpHeaders": Map headers = (Map) methodCall.argument("headers"); - MapboxHttpRequestUtil.setHttpHeaders(headers, result); + MapLibreHttpRequestUtil.setHttpHeaders(headers, result); break; case "downloadOfflineRegion#setup": String channelName = methodCall.argument("channelName"); diff --git a/android/src/main/java/com/mapbox/mapboxgl/LayerPropertyConverter.java b/android/src/main/java/org/maplibre/maplibregl/LayerPropertyConverter.java similarity index 98% rename from android/src/main/java/com/mapbox/mapboxgl/LayerPropertyConverter.java rename to android/src/main/java/org/maplibre/maplibregl/LayerPropertyConverter.java index de584703b..832e7705f 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/LayerPropertyConverter.java +++ b/android/src/main/java/org/maplibre/maplibregl/LayerPropertyConverter.java @@ -1,11 +1,11 @@ // This file is generated by // ./scripts/lib/generate.dart -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; -import com.mapbox.mapboxsdk.style.expressions.Expression; -import com.mapbox.mapboxsdk.style.layers.PropertyFactory; -import com.mapbox.mapboxsdk.style.layers.PropertyValue; +import org.maplibre.android.style.expressions.Expression; +import org.maplibre.android.style.layers.PropertyFactory; +import org.maplibre.android.style.layers.PropertyValue; import java.util.LinkedList; import java.util.List; @@ -16,7 +16,7 @@ import com.google.gson.JsonPrimitive; -import static com.mapbox.mapboxgl.Convert.toMap; +import static org.maplibre.maplibregl.Convert.toMap; class LayerPropertyConverter { static PropertyValue[] interpretSymbolLayerProperties(Object o) { diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxHttpRequestUtil.java b/android/src/main/java/org/maplibre/maplibregl/MapLibreHttpRequestUtil.java similarity index 91% rename from android/src/main/java/com/mapbox/mapboxgl/MapboxHttpRequestUtil.java rename to android/src/main/java/org/maplibre/maplibregl/MapLibreHttpRequestUtil.java index 185bccd91..5a796e6f6 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxHttpRequestUtil.java +++ b/android/src/main/java/org/maplibre/maplibregl/MapLibreHttpRequestUtil.java @@ -1,12 +1,12 @@ -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; -import com.mapbox.mapboxsdk.module.http.HttpRequestUtil; +import org.maplibre.android.module.http.HttpRequestUtil; import io.flutter.plugin.common.MethodChannel; import java.util.Map; import okhttp3.OkHttpClient; import okhttp3.Request; -abstract class MapboxHttpRequestUtil { +abstract class MapLibreHttpRequestUtil { public static void setHttpHeaders(Map headers, MethodChannel.Result result) { HttpRequestUtil.setOkHttpClient(getOkHttpClient(headers, result).build()); diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapBuilder.java b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapBuilder.java similarity index 91% rename from android/src/main/java/com/mapbox/mapboxgl/MapboxMapBuilder.java rename to android/src/main/java/org/maplibre/maplibregl/MapLibreMapBuilder.java index 28e4476a9..96fae2af7 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapBuilder.java +++ b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapBuilder.java @@ -2,20 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import android.content.Context; import android.view.Gravity; import androidx.annotation.NonNull; -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.geometry.LatLngBounds; -import com.mapbox.mapboxsdk.maps.MapboxMapOptions; +import org.maplibre.android.camera.CameraPosition; +import org.maplibre.android.geometry.LatLngBounds; +import org.maplibre.android.maps.MapLibreMapOptions; import io.flutter.plugin.common.BinaryMessenger; -class MapboxMapBuilder implements MapboxMapOptionsSink { +class MapLibreMapBuilder implements MapLibreMapOptionsSink { public final String TAG = getClass().getSimpleName(); - private final MapboxMapOptions options = - new MapboxMapOptions().attributionEnabled(true).logoEnabled(false).textureMode(true); + private final MapLibreMapOptions options = + new MapLibreMapOptions().attributionEnabled(true).logoEnabled(false).textureMode(true); private boolean trackCameraPosition = false; private boolean myLocationEnabled = false; private boolean dragEnabled = true; @@ -24,14 +24,14 @@ class MapboxMapBuilder implements MapboxMapOptionsSink { private String styleString = ""; private LatLngBounds bounds = null; - MapboxMapController build( + MapLibreMapController build( int id, Context context, BinaryMessenger messenger, - MapboxMapsPlugin.LifecycleProvider lifecycleProvider) { + MapLibreMapsPlugin.LifecycleProvider lifecycleProvider) { - final MapboxMapController controller = - new MapboxMapController( + final MapLibreMapController controller = + new MapLibreMapController( id, context, messenger, lifecycleProvider, options, styleString, dragEnabled); controller.init(); controller.setMyLocationEnabled(myLocationEnabled); diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java similarity index 94% rename from android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java rename to android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java index d9187fd65..b38e05481 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java +++ b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import android.Manifest; import android.annotation.SuppressLint; @@ -33,49 +33,48 @@ import com.google.gson.JsonParser; import com.mapbox.android.gestures.AndroidGesturesManager; import com.mapbox.android.gestures.MoveGestureDetector; -import com.mapbox.geojson.Feature; -import com.mapbox.geojson.FeatureCollection; -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.camera.CameraUpdate; -import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.geometry.LatLngBounds; -import com.mapbox.mapboxsdk.geometry.LatLngQuad; -import com.mapbox.mapboxsdk.geometry.VisibleRegion; -import com.mapbox.mapboxsdk.location.LocationComponent; -import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions; -import com.mapbox.mapboxsdk.location.LocationComponentOptions; -import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener; -import com.mapbox.mapboxsdk.location.engine.LocationEngineCallback; -import com.mapbox.mapboxsdk.location.engine.LocationEngineResult; -import com.mapbox.mapboxsdk.location.modes.CameraMode; -import com.mapbox.mapboxsdk.location.modes.RenderMode; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.MapboxMapOptions; -import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.offline.OfflineManager; -import com.mapbox.mapboxsdk.style.expressions.Expression; -import com.mapbox.mapboxsdk.style.layers.CircleLayer; -import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer; -import com.mapbox.mapboxsdk.style.layers.FillLayer; -import com.mapbox.mapboxsdk.style.layers.HeatmapLayer; -import com.mapbox.mapboxsdk.style.layers.HillshadeLayer; -import com.mapbox.mapboxsdk.style.layers.Layer; -import com.mapbox.mapboxsdk.style.layers.LineLayer; -import com.mapbox.mapboxsdk.style.layers.Property; -import com.mapbox.mapboxsdk.style.layers.PropertyValue; -import com.mapbox.mapboxsdk.style.layers.RasterLayer; -import com.mapbox.mapboxsdk.style.layers.SymbolLayer; -import com.mapbox.mapboxsdk.style.layers.PropertyFactory; -import com.mapbox.mapboxsdk.style.sources.CustomGeometrySource; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; -import com.mapbox.mapboxsdk.style.sources.ImageSource; -import com.mapbox.mapboxsdk.style.sources.Source; -import com.mapbox.mapboxsdk.style.sources.VectorSource; -import com.mapbox.mapboxsdk.style.types.Formatted; +import org.maplibre.geojson.Feature; +import org.maplibre.geojson.FeatureCollection; +import org.maplibre.android.camera.CameraPosition; +import org.maplibre.android.camera.CameraUpdate; +import org.maplibre.android.camera.CameraUpdateFactory; +import org.maplibre.android.constants.MapLibreConstants; +import org.maplibre.android.geometry.LatLng; +import org.maplibre.android.geometry.LatLngBounds; +import org.maplibre.android.geometry.LatLngQuad; +import org.maplibre.android.geometry.VisibleRegion; +import org.maplibre.android.location.LocationComponent; +import org.maplibre.android.location.LocationComponentActivationOptions; +import org.maplibre.android.location.LocationComponentOptions; +import org.maplibre.android.location.OnCameraTrackingChangedListener; +import org.maplibre.android.location.engine.LocationEngineCallback; +import org.maplibre.android.location.engine.LocationEngineResult; +import org.maplibre.android.location.modes.CameraMode; +import org.maplibre.android.location.modes.RenderMode; +import org.maplibre.android.maps.MapView; +import org.maplibre.android.maps.MapLibreMap; +import org.maplibre.android.maps.MapLibreMapOptions; +import org.maplibre.android.maps.OnMapReadyCallback; +import org.maplibre.android.maps.Style; +import org.maplibre.android.offline.OfflineManager; +import org.maplibre.android.style.expressions.Expression; +import org.maplibre.android.style.layers.CircleLayer; +import org.maplibre.android.style.layers.FillExtrusionLayer; +import org.maplibre.android.style.layers.FillLayer; +import org.maplibre.android.style.layers.HeatmapLayer; +import org.maplibre.android.style.layers.HillshadeLayer; +import org.maplibre.android.style.layers.Layer; +import org.maplibre.android.style.layers.LineLayer; +import org.maplibre.android.style.layers.Property; +import org.maplibre.android.style.layers.PropertyValue; +import org.maplibre.android.style.layers.RasterLayer; +import org.maplibre.android.style.layers.SymbolLayer; +import org.maplibre.android.style.layers.PropertyFactory; +import org.maplibre.android.style.sources.CustomGeometrySource; +import org.maplibre.android.style.sources.GeoJsonSource; +import org.maplibre.android.style.sources.ImageSource; +import org.maplibre.android.style.sources.Source; +import org.maplibre.android.style.sources.VectorSource; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; @@ -94,35 +93,35 @@ import java.util.Set; -/** Controller of a single MapboxMaps MapView instance. */ +/** Controller of a single MapLibreMaps MapView instance. */ @SuppressLint("MissingPermission") -final class MapboxMapController +final class MapLibreMapController implements DefaultLifecycleObserver, - MapboxMap.OnCameraIdleListener, - MapboxMap.OnCameraMoveListener, - MapboxMap.OnCameraMoveStartedListener, + MapLibreMap.OnCameraIdleListener, + MapLibreMap.OnCameraMoveListener, + MapLibreMap.OnCameraMoveStartedListener, MapView.OnDidBecomeIdleListener, - MapboxMap.OnMapClickListener, - MapboxMap.OnMapLongClickListener, - MapboxMapOptionsSink, + MapLibreMap.OnMapClickListener, + MapLibreMap.OnMapLongClickListener, + MapLibreMapOptionsSink, MethodChannel.MethodCallHandler, OnMapReadyCallback, OnCameraTrackingChangedListener, PlatformView { - private static final String TAG = "MapboxMapController"; + private static final String TAG = "MapLibreMapController"; private final int id; private final MethodChannel methodChannel; - private final MapboxMapsPlugin.LifecycleProvider lifecycleProvider; + private final MapLibreMapsPlugin.LifecycleProvider lifecycleProvider; private final float density; private final Context context; private final String styleStringInitial; /** * This container is returned as the final platform view instead of returning `mapView`. - * See {@link MapboxMapController#destroyMapViewIfNecessary()} for details. + * See {@link MapLibreMapController#destroyMapViewIfNecessary()} for details. */ private FrameLayout mapViewContainer; private MapView mapView; - private MapboxMap mapboxMap; + private MapLibreMap mapboxMap; private boolean trackCameraPosition = false; private boolean myLocationEnabled = false; private int myLocationTrackingMode = 0; @@ -147,7 +146,7 @@ final class MapboxMapController new Style.OnStyleLoaded() { @Override public void onStyleLoaded(@NonNull Style style) { - MapboxMapController.this.style = style; + MapLibreMapController.this.style = style; // commented out while cherry-picking upstream956 // if (myLocationEnabled) { @@ -161,22 +160,22 @@ public void onStyleLoaded(@NonNull Style style) { mapboxMap.setLatLngBoundsForCameraTarget(bounds); } - mapboxMap.addOnMapClickListener(MapboxMapController.this); - mapboxMap.addOnMapLongClickListener(MapboxMapController.this); + mapboxMap.addOnMapClickListener(MapLibreMapController.this); + mapboxMap.addOnMapLongClickListener(MapLibreMapController.this); methodChannel.invokeMethod("map#onStyleLoaded", null); } }; - MapboxMapController( + MapLibreMapController( int id, Context context, BinaryMessenger messenger, - MapboxMapsPlugin.LifecycleProvider lifecycleProvider, - MapboxMapOptions options, + MapLibreMapsPlugin.LifecycleProvider lifecycleProvider, + MapLibreMapOptions options, String styleStringInitial, boolean dragEnabled) { - MapBoxUtils.getMapbox(context); + MapLibreUtils.getMapLibre(context); this.id = id; this.context = context; this.dragEnabled = dragEnabled; @@ -219,7 +218,7 @@ private CameraPosition getCameraPosition() { } @Override - public void onMapReady(MapboxMap mapboxMap) { + public void onMapReady(MapLibreMap mapboxMap) { this.mapboxMap = mapboxMap; if (mapReadyResult != null) { mapReadyResult.success(null); @@ -275,7 +274,7 @@ public void setStyleString(@NonNull String styleString) { && !styleString.startsWith("https://") && !styleString.startsWith("mapbox://")) { // We are assuming that the style will be loaded from an asset here. - String key = MapboxMapsPlugin.flutterAssets.getAssetFilePathByName(styleString); + String key = MapLibreMapsPlugin.flutterAssets.getAssetFilePathByName(styleString); mapboxMap.setStyle(new Style.Builder().fromUri("asset://" + key), onStyleLoadedCallback); } else { mapboxMap.setStyle(new Style.Builder().fromUri(styleString), onStyleLoadedCallback); @@ -686,7 +685,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { break; case "map#update": { - Convert.interpretMapboxMapOptions(call.argument("options"), this, context); + Convert.interpretMapLibreMapOptions(call.argument("options"), this, context); result.success(Convert.toJson(getCameraPosition())); break; } @@ -701,7 +700,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { { try { final Locale deviceLocale = Locale.getDefault(); - MapboxMapUtils.setMapLanguage(mapboxMap, deviceLocale.getLanguage()); + MapLibreMapUtils.setMapLanguage(mapboxMap, deviceLocale.getLanguage()); result.success(null); } catch (RuntimeException exception) { @@ -731,7 +730,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { { final String language = call.argument("language"); try { - MapboxMapUtils.setMapLanguage(mapboxMap, language); + MapLibreMapUtils.setMapLanguage(mapboxMap, language); result.success(null); } catch (RuntimeException exception) { @@ -1597,7 +1596,7 @@ public void onFailure(@NonNull Exception exception) { @Override public void onCameraMoveStarted(int reason) { final Map arguments = new HashMap<>(2); - boolean isGesture = reason == MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE; + boolean isGesture = reason == MapLibreMap.OnCameraMoveStartedListener.REASON_API_GESTURE; arguments.put("isGesture", isGesture); methodChannel.invokeMethod("camera#onMoveStarted", arguments); } @@ -1835,7 +1834,7 @@ public void onDestroy(@NonNull LifecycleOwner owner) { destroyMapViewIfNecessary(); } - // MapboxMapOptionsSink methods + // MapLibreMapOptionsSink methods @Override public void setCameraTargetBounds(LatLngBounds bounds) { @@ -1869,8 +1868,8 @@ public void setTiltGesturesEnabled(boolean tiltGesturesEnabled) { @Override public void setMinMaxZoomPreference(Float min, Float max) { - mapboxMap.setMinZoomPreference(min != null ? min : MapboxConstants.MINIMUM_ZOOM); - mapboxMap.setMaxZoomPreference(max != null ? max : MapboxConstants.MAXIMUM_ZOOM); + mapboxMap.setMinZoomPreference(min != null ? min : MapLibreConstants.MINIMUM_ZOOM); + mapboxMap.setMaxZoomPreference(max != null ? max : MapLibreConstants.MAXIMUM_ZOOM); } @Override @@ -2090,7 +2089,7 @@ private Bitmap getScaledImage(String imageId, float density) { String assetPath; if (i == 1) { // If density is 1.0x then simply take the default asset path - assetPath = MapboxMapsPlugin.flutterAssets.getAssetFilePathByName(imageId); + assetPath = MapLibreMapsPlugin.flutterAssets.getAssetFilePathByName(imageId); } else { // Build a resolution aware asset path as follows: // // @@ -2103,7 +2102,7 @@ private Bitmap getScaledImage(String imageId, float density) { stringBuilder.append(((float) i) + "x"); stringBuilder.append("/"); stringBuilder.append(imagePathList.get(imagePathList.size() - 1)); - assetPath = MapboxMapsPlugin.flutterAssets.getAssetFilePathByName(stringBuilder.toString()); + assetPath = MapLibreMapsPlugin.flutterAssets.getAssetFilePathByName(stringBuilder.toString()); } // Build up a list of resolution aware asset paths. assetPathList.add(assetPath); @@ -2203,7 +2202,7 @@ void stopDragging() { } /** Simple Listener to listen for the status of camera movements. */ - public class OnCameraMoveFinishedListener implements MapboxMap.CancelableCallback { + public class OnCameraMoveFinishedListener implements MapLibreMap.CancelableCallback { @Override public void onFinish() {} @@ -2215,17 +2214,17 @@ private class MoveGestureListener implements MoveGestureDetector.OnMoveGestureLi @Override public boolean onMoveBegin(MoveGestureDetector detector) { - return MapboxMapController.this.onMoveBegin(detector); + return MapLibreMapController.this.onMoveBegin(detector); } @Override public boolean onMove(MoveGestureDetector detector, float distanceX, float distanceY) { - return MapboxMapController.this.onMove(detector); + return MapLibreMapController.this.onMove(detector); } @Override public void onMoveEnd(MoveGestureDetector detector, float velocityX, float velocityY) { - MapboxMapController.this.onMoveEnd(detector); + MapLibreMapController.this.onMoveEnd(detector); } } } diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapFactory.java b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapFactory.java similarity index 71% rename from android/src/main/java/com/mapbox/mapboxgl/MapboxMapFactory.java rename to android/src/main/java/org/maplibre/maplibregl/MapLibreMapFactory.java index d36ab4f86..7fdda1d63 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapFactory.java +++ b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapFactory.java @@ -1,23 +1,23 @@ -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import android.content.Context; import androidx.annotation.NonNull; -import com.mapbox.mapboxsdk.camera.CameraPosition; +import org.maplibre.android.camera.CameraPosition; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.StandardMessageCodec; import io.flutter.plugin.platform.PlatformView; import io.flutter.plugin.platform.PlatformViewFactory; import java.util.Map; -public class MapboxMapFactory extends PlatformViewFactory { +public class MapLibreMapFactory extends PlatformViewFactory { private final BinaryMessenger messenger; - private final MapboxMapsPlugin.LifecycleProvider lifecycleProvider; + private final MapLibreMapsPlugin.LifecycleProvider lifecycleProvider; - public MapboxMapFactory( - BinaryMessenger messenger, MapboxMapsPlugin.LifecycleProvider lifecycleProvider) { + public MapLibreMapFactory( + BinaryMessenger messenger, MapLibreMapsPlugin.LifecycleProvider lifecycleProvider) { super(StandardMessageCodec.INSTANCE); this.messenger = messenger; this.lifecycleProvider = lifecycleProvider; @@ -27,9 +27,9 @@ public MapboxMapFactory( @Override public PlatformView create(Context context, int id, Object args) { Map params = (Map) args; - final MapboxMapBuilder builder = new MapboxMapBuilder(); + final MapLibreMapBuilder builder = new MapLibreMapBuilder(); - Convert.interpretMapboxMapOptions(params.get("options"), builder, context); + Convert.interpretMapLibreMapOptions(params.get("options"), builder, context); if (params.containsKey("initialCameraPosition")) { CameraPosition position = Convert.toCameraPosition(params.get("initialCameraPosition")); builder.setInitialCameraPosition(position); diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapOptionsSink.kt b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapOptionsSink.kt similarity index 87% rename from android/src/main/java/com/mapbox/mapboxgl/MapboxMapOptionsSink.kt rename to android/src/main/java/org/maplibre/maplibregl/MapLibreMapOptionsSink.kt index ae9bdaed4..49fa1647f 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapOptionsSink.kt +++ b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapOptionsSink.kt @@ -1,12 +1,12 @@ // Copyright 2018 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package com.mapbox.mapboxgl +package org.maplibre.maplibregl -import com.mapbox.mapboxsdk.geometry.LatLngBounds +import org.maplibre.android.geometry.LatLngBounds -/** Receiver of MapboxMap configuration options. */ -internal interface MapboxMapOptionsSink { +/** Receiver of MapLibreMap configuration options. */ +internal interface MapLibreMapOptionsSink { // todo: dddd replace with CameraPosition.Builder target fun setCameraTargetBounds(bounds: LatLngBounds) diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapsPlugin.java b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapsPlugin.java similarity index 89% rename from android/src/main/java/com/mapbox/mapboxgl/MapboxMapsPlugin.java rename to android/src/main/java/org/maplibre/maplibregl/MapLibreMapsPlugin.java index a7e59f27c..4213ca38e 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapsPlugin.java +++ b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapsPlugin.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import android.app.Activity; import android.app.Application; @@ -20,19 +20,19 @@ import io.flutter.plugin.common.PluginRegistry.Registrar; /** - * Plugin for controlling a set of MapboxMap views to be shown as overlays on top of the Flutter + * Plugin for controlling a set of MapLibreMap views to be shown as overlays on top of the Flutter * view. The overlay should be hidden during transformations or while Flutter is rendering on top of - * the map. A Texture drawn using MapboxMap bitmap snapshots can then be shown instead of the + * the map. A Texture drawn using MapLibreMap bitmap snapshots can then be shown instead of the * overlay. */ -public class MapboxMapsPlugin implements FlutterPlugin, ActivityAware { +public class MapLibreMapsPlugin implements FlutterPlugin, ActivityAware { private static final String VIEW_TYPE = "plugins.flutter.io/mapbox_gl"; static FlutterAssets flutterAssets; private Lifecycle lifecycle; - public MapboxMapsPlugin() { + public MapLibreMapsPlugin() { // no-op } @@ -50,7 +50,7 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { .getPlatformViewRegistry() .registerViewFactory( "plugins.flutter.io/mapbox_gl", - new MapboxMapFactory( + new MapLibreMapFactory( binding.getBinaryMessenger(), new LifecycleProvider() { @Nullable diff --git a/android/src/main/java/org/maplibre/maplibregl/MapLibreUtils.java b/android/src/main/java/org/maplibre/maplibregl/MapLibreUtils.java new file mode 100644 index 000000000..dadbd16ce --- /dev/null +++ b/android/src/main/java/org/maplibre/maplibregl/MapLibreUtils.java @@ -0,0 +1,12 @@ +package org.maplibre.maplibregl; + +import android.content.Context; +import org.maplibre.android.MapLibre; + +abstract class MapLibreUtils { + private static final String TAG = "MapLibreMapController"; + + static MapLibre getMapLibre(Context context) { + return MapLibre.getInstance(context); + } +} diff --git a/android/src/main/java/com/mapbox/mapboxgl/OfflineChannelHandlerImpl.java b/android/src/main/java/org/maplibre/maplibregl/OfflineChannelHandlerImpl.java similarity index 97% rename from android/src/main/java/com/mapbox/mapboxgl/OfflineChannelHandlerImpl.java rename to android/src/main/java/org/maplibre/maplibregl/OfflineChannelHandlerImpl.java index 64164f792..c29fe17e4 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/OfflineChannelHandlerImpl.java +++ b/android/src/main/java/org/maplibre/maplibregl/OfflineChannelHandlerImpl.java @@ -1,4 +1,4 @@ -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import androidx.annotation.Nullable; import com.google.gson.Gson; diff --git a/android/src/main/java/com/mapbox/mapboxgl/OfflineManagerUtils.java b/android/src/main/java/org/maplibre/maplibregl/OfflineManagerUtils.java similarity index 95% rename from android/src/main/java/com/mapbox/mapboxgl/OfflineManagerUtils.java rename to android/src/main/java/org/maplibre/maplibregl/OfflineManagerUtils.java index ded2db1ea..b0585a194 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/OfflineManagerUtils.java +++ b/android/src/main/java/org/maplibre/maplibregl/OfflineManagerUtils.java @@ -1,16 +1,16 @@ -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import android.content.Context; import android.util.Log; import com.google.gson.Gson; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.geometry.LatLngBounds; -import com.mapbox.mapboxsdk.offline.OfflineManager; -import com.mapbox.mapboxsdk.offline.OfflineRegion; -import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition; -import com.mapbox.mapboxsdk.offline.OfflineRegionError; -import com.mapbox.mapboxsdk.offline.OfflineRegionStatus; -import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition; +import org.maplibre.android.geometry.LatLng; +import org.maplibre.android.geometry.LatLngBounds; +import org.maplibre.android.offline.OfflineManager; +import org.maplibre.android.offline.OfflineRegion; +import org.maplibre.android.offline.OfflineRegionDefinition; +import org.maplibre.android.offline.OfflineRegionError; +import org.maplibre.android.offline.OfflineRegionStatus; +import org.maplibre.android.offline.OfflineTilePyramidRegionDefinition; import io.flutter.plugin.common.MethodChannel; import java.util.ArrayList; import java.util.Arrays; @@ -121,15 +121,15 @@ public void onError(OfflineRegionError error) { @Override public void mapboxTileCountLimitExceeded(long limit) { - Log.e(TAG, "Mapbox tile count" + " limit exceeded: " + limit); + Log.e(TAG, "MapLibre tile count" + " limit exceeded: " + limit); // Reset downloading state _offlineRegion.setDownloadState(OfflineRegion.STATE_INACTIVE); isComplete.set(true); channelHandler.onError( "mapboxTileCountLimitExceeded", - "Mapbox tile count " + "limit " + "exceeded: " + limit, + "MapLibre tile count " + "limit " + "exceeded: " + limit, null); - // Mapbox even after crash + // MapLibre even after crash // and not downloading fully // region still keeps part // of it in database, so we diff --git a/android/src/main/java/com/mapbox/mapboxgl/SourcePropertyConverter.java b/android/src/main/java/org/maplibre/maplibregl/SourcePropertyConverter.java similarity index 91% rename from android/src/main/java/com/mapbox/mapboxgl/SourcePropertyConverter.java rename to android/src/main/java/org/maplibre/maplibregl/SourcePropertyConverter.java index 9840d43c5..de750dd04 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/SourcePropertyConverter.java +++ b/android/src/main/java/org/maplibre/maplibregl/SourcePropertyConverter.java @@ -1,19 +1,19 @@ -package com.mapbox.mapboxgl; +package org.maplibre.maplibregl; import android.net.Uri; import com.google.gson.Gson; -import com.mapbox.geojson.FeatureCollection; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.geometry.LatLngQuad; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; -import com.mapbox.mapboxsdk.style.sources.ImageSource; -import com.mapbox.mapboxsdk.style.sources.RasterDemSource; -import com.mapbox.mapboxsdk.style.sources.RasterSource; -import com.mapbox.mapboxsdk.style.sources.Source; -import com.mapbox.mapboxsdk.style.sources.TileSet; -import com.mapbox.mapboxsdk.style.sources.VectorSource; +import org.maplibre.geojson.FeatureCollection; +import org.maplibre.android.geometry.LatLng; +import org.maplibre.android.geometry.LatLngQuad; +import org.maplibre.android.maps.Style; +import org.maplibre.android.style.sources.GeoJsonOptions; +import org.maplibre.android.style.sources.GeoJsonSource; +import org.maplibre.android.style.sources.ImageSource; +import org.maplibre.android.style.sources.RasterDemSource; +import org.maplibre.android.style.sources.RasterSource; +import org.maplibre.android.style.sources.Source; +import org.maplibre.android.style.sources.TileSet; +import org.maplibre.android.style.sources.VectorSource; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; diff --git a/android/src/main/java/com/mapbox/mapboxgl/setMapLanguage.kt b/android/src/main/java/org/maplibre/maplibregl/setMapLanguage.kt similarity index 68% rename from android/src/main/java/com/mapbox/mapboxgl/setMapLanguage.kt rename to android/src/main/java/org/maplibre/maplibregl/setMapLanguage.kt index 870967478..bfcd66038 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/setMapLanguage.kt +++ b/android/src/main/java/org/maplibre/maplibregl/setMapLanguage.kt @@ -1,13 +1,13 @@ -@file:JvmName("MapboxMapUtils") +@file:JvmName("MapLibreMapUtils") -package com.mapbox.mapboxgl +package org.maplibre.maplibregl -import com.mapbox.mapboxsdk.maps.MapboxMap -import com.mapbox.mapboxsdk.style.expressions.Expression -import com.mapbox.mapboxsdk.style.layers.PropertyFactory -import com.mapbox.mapboxsdk.style.layers.SymbolLayer +import org.maplibre.android.maps.MapLibreMap +import org.maplibre.android.style.expressions.Expression +import org.maplibre.android.style.layers.PropertyFactory +import org.maplibre.android.style.layers.SymbolLayer -fun MapboxMap.setMapLanguage(language: String) { +fun MapLibreMap.setMapLanguage(language: String) { val layers = this.style?.layers ?: emptyList() val languageRegex = Regex("(name:[a-z]+)") diff --git a/pubspec.yaml b/pubspec.yaml index f6a9c4615..c955334e6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,8 +21,8 @@ flutter: plugin: platforms: android: - package: com.mapbox.mapboxgl - pluginClass: MapboxMapsPlugin + package: org.maplibre.maplibregl + pluginClass: MapLibreMapsPlugin ios: pluginClass: MapboxMapsPlugin web: From f0fe6eb67b15ae412d0f1905adc8f038d10a5382 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:23:10 +0200 Subject: [PATCH 2/4] change package name, update changelog --- CHANGELOG.md | 2 ++ android/build.gradle | 4 ++-- android/src/main/AndroidManifest.xml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fd967a43..4efcabec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ iOS Devices with an Apple A7 GPU or later are supported onwards. See the [maplibre-native changelog](https://github.com/maplibre/maplibre-native/blob/main/platform/ios/CHANGELOG.md#600) for more information. +* Updated maplibre-native for android to v11.0.0. This version uses + OpenGL ES 3.0. ## 0.19.0 diff --git a/android/build.gradle b/android/build.gradle index de94837fe..41b2c3684 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,4 +1,4 @@ -group 'com.mapbox.mapboxgl' +group 'org.maplibre.maplibregl' version '1.0-SNAPSHOT' buildscript { @@ -24,7 +24,7 @@ apply plugin: 'org.jetbrains.kotlin.android' android { if (project.android.hasProperty("namespace")) { - namespace 'com.mapbox.mapboxgl' + namespace 'org.maplibre.maplibregl' } compileSdkVersion 34 diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 5f4189a1b..1d2dc33dd 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ + package="org.maplibre.maplibregl"> From fd894836b9b17a32f91620d4f4ca69598fba07a6 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:39:32 +0200 Subject: [PATCH 3/4] rename `mapboxMap` to `mapLibreMap` --- .../maplibregl/MapLibreMapController.java | 152 +++++++++--------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java index b38e05481..c77fd6426 100644 --- a/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java +++ b/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java @@ -121,7 +121,7 @@ final class MapLibreMapController */ private FrameLayout mapViewContainer; private MapView mapView; - private MapLibreMap mapboxMap; + private MapLibreMap mapLibreMap; private boolean trackCameraPosition = false; private boolean myLocationEnabled = false; private int myLocationTrackingMode = 0; @@ -157,11 +157,11 @@ public void onStyleLoaded(@NonNull Style style) { updateMyLocationEnabled(); if (null != bounds) { - mapboxMap.setLatLngBoundsForCameraTarget(bounds); + mapLibreMap.setLatLngBoundsForCameraTarget(bounds); } - mapboxMap.addOnMapClickListener(MapLibreMapController.this); - mapboxMap.addOnMapLongClickListener(MapLibreMapController.this); + mapLibreMap.addOnMapClickListener(MapLibreMapController.this); + mapLibreMap.addOnMapLongClickListener(MapLibreMapController.this); methodChannel.invokeMethod("map#onStyleLoaded", null); } @@ -206,27 +206,27 @@ void init() { } private void moveCamera(CameraUpdate cameraUpdate) { - mapboxMap.moveCamera(cameraUpdate); + mapLibreMap.moveCamera(cameraUpdate); } private void animateCamera(CameraUpdate cameraUpdate) { - mapboxMap.animateCamera(cameraUpdate); + mapLibreMap.animateCamera(cameraUpdate); } private CameraPosition getCameraPosition() { - return trackCameraPosition ? mapboxMap.getCameraPosition() : null; + return trackCameraPosition ? mapLibreMap.getCameraPosition() : null; } @Override - public void onMapReady(MapLibreMap mapboxMap) { - this.mapboxMap = mapboxMap; + public void onMapReady(MapLibreMap mapLibreMap) { + this.mapLibreMap = mapLibreMap; if (mapReadyResult != null) { mapReadyResult.success(null); mapReadyResult = null; } - mapboxMap.addOnCameraMoveStartedListener(this); - mapboxMap.addOnCameraMoveListener(this); - mapboxMap.addOnCameraIdleListener(this); + mapLibreMap.addOnCameraMoveStartedListener(this); + mapLibreMap.addOnCameraMoveListener(this); + mapLibreMap.addOnCameraIdleListener(this); if (androidGesturesManager != null) { androidGesturesManager.setMoveGestureListener(new MoveGestureListener()); @@ -246,7 +246,7 @@ public boolean onTouch(View v, MotionEvent event) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); final Bitmap bitmap = getScaledImage(id, displayMetrics.density); if (bitmap != null) { - mapboxMap.getStyle().addImage(id, bitmap); + mapLibreMap.getStyle().addImage(id, bitmap); } }); @@ -265,19 +265,19 @@ public void setStyleString(@NonNull String styleString) { if (styleString == null || styleString.isEmpty()) { Log.e(TAG, "setStyleString - string empty or null"); } else if (styleString.startsWith("{") || styleString.startsWith("[")) { - mapboxMap.setStyle(new Style.Builder().fromJson(styleString), onStyleLoadedCallback); + mapLibreMap.setStyle(new Style.Builder().fromJson(styleString), onStyleLoadedCallback); } else if (styleString.startsWith("/")) { // Absolute path - mapboxMap.setStyle( + mapLibreMap.setStyle( new Style.Builder().fromUri("file://" + styleString), onStyleLoadedCallback); } else if (!styleString.startsWith("http://") && !styleString.startsWith("https://") && !styleString.startsWith("mapbox://")) { // We are assuming that the style will be loaded from an asset here. String key = MapLibreMapsPlugin.flutterAssets.getAssetFilePathByName(styleString); - mapboxMap.setStyle(new Style.Builder().fromUri("asset://" + key), onStyleLoadedCallback); + mapLibreMap.setStyle(new Style.Builder().fromUri("asset://" + key), onStyleLoadedCallback); } else { - mapboxMap.setStyle(new Style.Builder().fromUri(styleString), onStyleLoadedCallback); + mapLibreMap.setStyle(new Style.Builder().fromUri(styleString), onStyleLoadedCallback); } } @@ -287,7 +287,7 @@ public void setStyleString(@NonNull String styleString) { private void enableLocationComponent(@NonNull Style style) { if (hasLocationPermission()) { - locationComponent = mapboxMap.getLocationComponent(); + locationComponent = mapLibreMap.getLocationComponent(); LocationComponentActivationOptions options = LocationComponentActivationOptions @@ -663,7 +663,7 @@ private Feature firstFeatureOnLayers(RectF in) { Collections.reverse(layersInOrder); for (String id : layersInOrder) { - List features = mapboxMap.queryRenderedFeatures(in, id); + List features = mapLibreMap.queryRenderedFeatures(in, id); if (!features.isEmpty()) { return features.get(0); } @@ -677,7 +677,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { switch (call.method) { case "map#waitForMap": - if (mapboxMap != null) { + if (mapLibreMap != null) { result.success(null); return; } @@ -700,7 +700,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { { try { final Locale deviceLocale = Locale.getDefault(); - MapLibreMapUtils.setMapLanguage(mapboxMap, deviceLocale.getLanguage()); + MapLibreMapUtils.setMapLanguage(mapLibreMap, deviceLocale.getLanguage()); result.success(null); } catch (RuntimeException exception) { @@ -730,7 +730,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { { final String language = call.argument("language"); try { - MapLibreMapUtils.setMapLanguage(mapboxMap, language); + MapLibreMapUtils.setMapLanguage(mapLibreMap, language); result.success(null); } catch (RuntimeException exception) { @@ -742,7 +742,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { case "map#getVisibleRegion": { Map reply = new HashMap<>(); - VisibleRegion visibleRegion = mapboxMap.getProjection().getVisibleRegion(); + VisibleRegion visibleRegion = mapLibreMap.getProjection().getVisibleRegion(); reply.put( "sw", Arrays.asList( @@ -759,7 +759,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { { Map reply = new HashMap<>(); PointF pointf = - mapboxMap + mapLibreMap .getProjection() .toScreenLocation( new LatLng(call.argument("latitude"), call.argument("longitude"))); @@ -775,7 +775,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { for (int i = 0; i < param.length; i += 2) { PointF pointf = - mapboxMap.getProjection().toScreenLocation(new LatLng(param[i], param[i + 1])); + mapLibreMap.getProjection().toScreenLocation(new LatLng(param[i], param[i + 1])); reply[i] = pointf.x; reply[i + 1] = pointf.y; } @@ -787,7 +787,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { { Map reply = new HashMap<>(); LatLng latlng = - mapboxMap + mapLibreMap .getProjection() .fromScreenLocation( new PointF( @@ -802,7 +802,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { { Map reply = new HashMap<>(); Double retVal = - mapboxMap + mapLibreMap .getProjection() .getMetersPerPixelAtLatitude((Double) call.argument("latitude")); reply.put("metersperpixel", retVal); @@ -812,10 +812,10 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { case "camera#move": { final CameraUpdate cameraUpdate = - Convert.toCameraUpdate(call.argument("cameraUpdate"), mapboxMap, density); + Convert.toCameraUpdate(call.argument("cameraUpdate"), mapLibreMap, density); if (cameraUpdate != null) { // camera transformation not handled yet - mapboxMap.moveCamera( + mapLibreMap.moveCamera( cameraUpdate, new OnCameraMoveFinishedListener() { @Override @@ -840,7 +840,7 @@ public void onCancel() { case "camera#animate": { final CameraUpdate cameraUpdate = - Convert.toCameraUpdate(call.argument("cameraUpdate"), mapboxMap, density); + Convert.toCameraUpdate(call.argument("cameraUpdate"), mapLibreMap, density); final Integer duration = call.argument("duration"); final OnCameraMoveFinishedListener onCameraMoveFinishedListener = @@ -859,10 +859,10 @@ public void onCancel() { }; if (cameraUpdate != null && duration != null) { // camera transformation not handled yet - mapboxMap.animateCamera(cameraUpdate, duration, onCameraMoveFinishedListener); + mapLibreMap.animateCamera(cameraUpdate, duration, onCameraMoveFinishedListener); } else if (cameraUpdate != null) { // camera transformation not handled yet - mapboxMap.animateCamera(cameraUpdate, onCameraMoveFinishedListener); + mapLibreMap.animateCamera(cameraUpdate, onCameraMoveFinishedListener); } else { result.success(false); } @@ -887,7 +887,7 @@ public void onCancel() { Double x = call.argument("x"); Double y = call.argument("y"); PointF pixel = new PointF(x.floatValue(), y.floatValue()); - features = mapboxMap.queryRenderedFeatures(pixel, filterExpression, layerIds); + features = mapLibreMap.queryRenderedFeatures(pixel, filterExpression, layerIds); } else { Double left = call.argument("left"); Double top = call.argument("top"); @@ -896,7 +896,7 @@ public void onCancel() { RectF rectF = new RectF( left.floatValue(), top.floatValue(), right.floatValue(), bottom.floatValue()); - features = mapboxMap.queryRenderedFeatures(rectF, filterExpression, layerIds); + features = mapLibreMap.queryRenderedFeatures(rectF, filterExpression, layerIds); } List featuresJson = new ArrayList<>(); for (Feature feature : features) { @@ -1226,7 +1226,7 @@ public void onError(@NonNull String message) { if (this.myLocationEnabled && locationComponent != null) { Map reply = new HashMap<>(); - mapboxMap.getLocationComponent().getLocationEngine().getLastLocation( + mapLibreMap.getLocationComponent().getLocationEngine().getLastLocation( new LocationEngineCallback() { @Override public void onSuccess(LocationEngineResult locationEngineResult) { @@ -1408,7 +1408,7 @@ public void onFailure(@NonNull Exception exception) { .include(locationOne) // Northeast .include(locationTwo) // Southwest .build(); - mapboxMap.easeCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, + mapLibreMap.easeCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, padding), 200); break; @@ -1607,7 +1607,7 @@ public void onCameraMove() { return; } final Map arguments = new HashMap<>(2); - arguments.put("position", Convert.toJson(mapboxMap.getCameraPosition())); + arguments.put("position", Convert.toJson(mapLibreMap.getCameraPosition())); methodChannel.invokeMethod("camera#onMove", arguments); } @@ -1615,7 +1615,7 @@ public void onCameraMove() { public void onCameraIdle() { final Map arguments = new HashMap<>(2); if (trackCameraPosition) { - arguments.put("position", Convert.toJson(mapboxMap.getCameraPosition())); + arguments.put("position", Convert.toJson(mapLibreMap.getCameraPosition())); } methodChannel.invokeMethod("camera#onIdle", arguments); } @@ -1657,7 +1657,7 @@ public void onDidBecomeIdle() { @Override public boolean onMapClick(@NonNull LatLng point) { - PointF pointf = mapboxMap.getProjection().toScreenLocation(point); + PointF pointf = mapLibreMap.getProjection().toScreenLocation(point); RectF rectF = new RectF(pointf.x - 10, pointf.y - 10, pointf.x + 10, pointf.y + 10); Feature feature = firstFeatureOnLayers(rectF); final Map arguments = new HashMap<>(); @@ -1676,7 +1676,7 @@ public boolean onMapClick(@NonNull LatLng point) { @Override public boolean onMapLongClick(@NonNull LatLng point) { - PointF pointf = mapboxMap.getProjection().toScreenLocation(point); + PointF pointf = mapLibreMap.getProjection().toScreenLocation(point); final Map arguments = new HashMap<>(5); arguments.put("x", pointf.x); arguments.put("y", pointf.y); @@ -1703,7 +1703,7 @@ public void dispose() { private void moveCamera(CameraUpdate cameraUpdate, MethodChannel.Result result) { if (cameraUpdate != null) { // camera transformation not handled yet - mapboxMap.moveCamera( + mapLibreMap.moveCamera( cameraUpdate, new OnCameraMoveFinishedListener() { @Override @@ -1743,10 +1743,10 @@ public void onCancel() { }; if (cameraUpdate != null && duration != null) { // camera transformation not handled yet - mapboxMap.animateCamera(cameraUpdate, duration, onCameraMoveFinishedListener); + mapLibreMap.animateCamera(cameraUpdate, duration, onCameraMoveFinishedListener); } else if (cameraUpdate != null) { // camera transformation not handled yet - mapboxMap.animateCamera(cameraUpdate, onCameraMoveFinishedListener); + mapLibreMap.animateCamera(cameraUpdate, onCameraMoveFinishedListener); } else { result.success(false); } @@ -1843,7 +1843,7 @@ public void setCameraTargetBounds(LatLngBounds bounds) { @Override public void setCompassEnabled(boolean compassEnabled) { - mapboxMap.getUiSettings().setCompassEnabled(compassEnabled); + mapLibreMap.getUiSettings().setCompassEnabled(compassEnabled); } @Override @@ -1853,28 +1853,28 @@ public void setTrackCameraPosition(boolean trackCameraPosition) { @Override public void setRotateGesturesEnabled(boolean rotateGesturesEnabled) { - mapboxMap.getUiSettings().setRotateGesturesEnabled(rotateGesturesEnabled); + mapLibreMap.getUiSettings().setRotateGesturesEnabled(rotateGesturesEnabled); } @Override public void setScrollGesturesEnabled(boolean scrollGesturesEnabled) { - mapboxMap.getUiSettings().setScrollGesturesEnabled(scrollGesturesEnabled); + mapLibreMap.getUiSettings().setScrollGesturesEnabled(scrollGesturesEnabled); } @Override public void setTiltGesturesEnabled(boolean tiltGesturesEnabled) { - mapboxMap.getUiSettings().setTiltGesturesEnabled(tiltGesturesEnabled); + mapLibreMap.getUiSettings().setTiltGesturesEnabled(tiltGesturesEnabled); } @Override public void setMinMaxZoomPreference(Float min, Float max) { - mapboxMap.setMinZoomPreference(min != null ? min : MapLibreConstants.MINIMUM_ZOOM); - mapboxMap.setMaxZoomPreference(max != null ? max : MapLibreConstants.MAXIMUM_ZOOM); + mapLibreMap.setMinZoomPreference(min != null ? min : MapLibreConstants.MINIMUM_ZOOM); + mapLibreMap.setMaxZoomPreference(max != null ? max : MapLibreConstants.MAXIMUM_ZOOM); } @Override public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) { - mapboxMap.getUiSettings().setZoomGesturesEnabled(zoomGesturesEnabled); + mapLibreMap.getUiSettings().setZoomGesturesEnabled(zoomGesturesEnabled); } @Override @@ -1883,14 +1883,14 @@ public void setMyLocationEnabled(boolean myLocationEnabled) { return; } this.myLocationEnabled = myLocationEnabled; - if (mapboxMap != null) { + if (mapLibreMap != null) { updateMyLocationEnabled(); } } @Override public void setMyLocationTrackingMode(int myLocationTrackingMode) { - if (mapboxMap != null) { + if (mapLibreMap != null) { // ensure that location is trackable updateMyLocationEnabled(); } @@ -1898,7 +1898,7 @@ public void setMyLocationTrackingMode(int myLocationTrackingMode) { return; } this.myLocationTrackingMode = myLocationTrackingMode; - if (mapboxMap != null && locationComponent != null) { + if (mapLibreMap != null && locationComponent != null) { updateMyLocationTrackingMode(); } } @@ -1909,49 +1909,49 @@ public void setMyLocationRenderMode(int myLocationRenderMode) { return; } this.myLocationRenderMode = myLocationRenderMode; - if (mapboxMap != null && locationComponent != null) { + if (mapLibreMap != null && locationComponent != null) { updateMyLocationRenderMode(); } } public void setLogoViewMargins(int x, int y) { - mapboxMap.getUiSettings().setLogoMargins(x, 0, 0, y); + mapLibreMap.getUiSettings().setLogoMargins(x, 0, 0, y); } @Override public void setCompassGravity(int gravity) { switch (gravity) { case 0: - mapboxMap.getUiSettings().setCompassGravity(Gravity.TOP | Gravity.START); + mapLibreMap.getUiSettings().setCompassGravity(Gravity.TOP | Gravity.START); break; default: case 1: - mapboxMap.getUiSettings().setCompassGravity(Gravity.TOP | Gravity.END); + mapLibreMap.getUiSettings().setCompassGravity(Gravity.TOP | Gravity.END); break; case 2: - mapboxMap.getUiSettings().setCompassGravity(Gravity.BOTTOM | Gravity.START); + mapLibreMap.getUiSettings().setCompassGravity(Gravity.BOTTOM | Gravity.START); break; case 3: - mapboxMap.getUiSettings().setCompassGravity(Gravity.BOTTOM | Gravity.END); + mapLibreMap.getUiSettings().setCompassGravity(Gravity.BOTTOM | Gravity.END); break; } } @Override public void setCompassViewMargins(int x, int y) { - switch (mapboxMap.getUiSettings().getCompassGravity()) { + switch (mapLibreMap.getUiSettings().getCompassGravity()) { case Gravity.TOP | Gravity.START: - mapboxMap.getUiSettings().setCompassMargins(x, y, 0, 0); + mapLibreMap.getUiSettings().setCompassMargins(x, y, 0, 0); break; default: case Gravity.TOP | Gravity.END: - mapboxMap.getUiSettings().setCompassMargins(0, y, x, 0); + mapLibreMap.getUiSettings().setCompassMargins(0, y, x, 0); break; case Gravity.BOTTOM | Gravity.START: - mapboxMap.getUiSettings().setCompassMargins(x, 0, 0, y); + mapLibreMap.getUiSettings().setCompassMargins(x, 0, 0, y); break; case Gravity.BOTTOM | Gravity.END: - mapboxMap.getUiSettings().setCompassMargins(0, 0, x, y); + mapLibreMap.getUiSettings().setCompassMargins(0, 0, x, y); break; } } @@ -1960,43 +1960,43 @@ public void setCompassViewMargins(int x, int y) { public void setAttributionButtonGravity(int gravity) { switch (gravity) { case 0: - mapboxMap.getUiSettings().setAttributionGravity(Gravity.TOP | Gravity.START); + mapLibreMap.getUiSettings().setAttributionGravity(Gravity.TOP | Gravity.START); break; default: case 1: - mapboxMap.getUiSettings().setAttributionGravity(Gravity.TOP | Gravity.END); + mapLibreMap.getUiSettings().setAttributionGravity(Gravity.TOP | Gravity.END); break; case 2: - mapboxMap.getUiSettings().setAttributionGravity(Gravity.BOTTOM | Gravity.START); + mapLibreMap.getUiSettings().setAttributionGravity(Gravity.BOTTOM | Gravity.START); break; case 3: - mapboxMap.getUiSettings().setAttributionGravity(Gravity.BOTTOM | Gravity.END); + mapLibreMap.getUiSettings().setAttributionGravity(Gravity.BOTTOM | Gravity.END); break; } } @Override public void setAttributionButtonMargins(int x, int y) { - switch (mapboxMap.getUiSettings().getAttributionGravity()) { + switch (mapLibreMap.getUiSettings().getAttributionGravity()) { case Gravity.TOP | Gravity.START: - mapboxMap.getUiSettings().setAttributionMargins(x, y, 0, 0); + mapLibreMap.getUiSettings().setAttributionMargins(x, y, 0, 0); break; default: case Gravity.TOP | Gravity.END: - mapboxMap.getUiSettings().setAttributionMargins(0, y, x, 0); + mapLibreMap.getUiSettings().setAttributionMargins(0, y, x, 0); break; case Gravity.BOTTOM | Gravity.START: - mapboxMap.getUiSettings().setAttributionMargins(x, 0, 0, y); + mapLibreMap.getUiSettings().setAttributionMargins(x, 0, 0, y); break; case Gravity.BOTTOM | Gravity.END: - mapboxMap.getUiSettings().setAttributionMargins(0, 0, x, y); + mapLibreMap.getUiSettings().setAttributionMargins(0, 0, x, y); break; } } private void updateMyLocationEnabled() { if (this.locationComponent == null && myLocationEnabled) { - enableLocationComponent(mapboxMap.getStyle()); + enableLocationComponent(mapLibreMap.getStyle()); } if (myLocationEnabled) { @@ -2133,7 +2133,7 @@ boolean onMoveBegin(MoveGestureDetector detector) { if (detector.getPreviousEvent().getActionMasked() == MotionEvent.ACTION_DOWN && detector.getPointersCount() == 1) { PointF pointf = detector.getFocalPoint(); - LatLng origin = mapboxMap.getProjection().fromScreenLocation(pointf); + LatLng origin = mapLibreMap.getProjection().fromScreenLocation(pointf); RectF rectF = new RectF(pointf.x - 10, pointf.y - 10, pointf.x + 10, pointf.y + 10); Feature feature = firstFeatureOnLayers(rectF); if (feature != null && startDragging(feature, origin)) { @@ -2145,7 +2145,7 @@ boolean onMoveBegin(MoveGestureDetector detector) { } private void invokeFeatureDrag(PointF pointf, String eventType) { - LatLng current = mapboxMap.getProjection().fromScreenLocation(pointf); + LatLng current = mapLibreMap.getProjection().fromScreenLocation(pointf); final Map arguments = new HashMap<>(9); arguments.put("id", draggedFeature.id()); From f1e629b8c9b66b165a9ece5de5c718ed932093c1 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:01:03 +0200 Subject: [PATCH 4/4] bump gradle dependencies --- android/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 41b2c3684..1c8ea3903 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -47,9 +47,9 @@ android { } dependencies { implementation 'org.maplibre.gl:android-sdk:11.0.0' - implementation 'org.maplibre.gl:android-plugin-annotation-v9:2.0.0' - implementation 'org.maplibre.gl:android-plugin-offline-v9:2.0.0' - implementation 'com.squareup.okhttp3:okhttp:4.10.0' + implementation 'org.maplibre.gl:android-plugin-annotation-v9:3.0.0' + implementation 'org.maplibre.gl:android-plugin-offline-v9:3.0.0' + implementation 'com.squareup.okhttp3:okhttp:4.12.0' } }