Skip to content

Commit 3a40009

Browse files
committed
Revert "[FEATURE] Returns layer Id on Feature Tap & update NDK version to fix crash on Android 15 (maplibre#475)"
This reverts commit 8246a84.
1 parent 14ebb4c commit 3a40009

File tree

7 files changed

+63
-73
lines changed

7 files changed

+63
-73
lines changed

example/lib/layer.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,10 @@ class LayerState extends State {
145145
// controller.onFeatureTapped.add(onFeatureTap);
146146
}
147147

148-
void onFeatureTap(
149-
dynamic featureId, Point<double> point, LatLng latLng, String layerId) {
148+
void onFeatureTap(dynamic featureId, Point<double> point, LatLng latLng) {
150149
final snackBar = SnackBar(
151150
content: Text(
152-
'Tapped feature with id $featureId on layer $layerId',
151+
'Tapped feature with id $featureId',
153152
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
154153
),
155154
backgroundColor: Theme.of(context).primaryColor,

maplibre_gl/android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ android {
3030
}
3131

3232
compileSdkVersion 34
33-
ndkVersion "27.0.12077973"
33+
ndkVersion "26.1.10909125"
3434

3535
defaultConfig {
3636
minSdkVersion 21
@@ -48,9 +48,9 @@ android {
4848
jvmTarget = JavaVersion.VERSION_1_8
4949
}
5050
dependencies {
51-
implementation 'org.maplibre.gl:android-sdk:11.6.1'
52-
implementation 'org.maplibre.gl:android-plugin-annotation-v9:3.0.2'
53-
implementation 'org.maplibre.gl:android-plugin-offline-v9:3.0.2'
51+
implementation 'org.maplibre.gl:android-sdk:11.0.0'
52+
implementation 'org.maplibre.gl:android-plugin-annotation-v9:3.0.0'
53+
implementation 'org.maplibre.gl:android-plugin-offline-v9:3.0.0'
5454
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
5555
}
5656
}

maplibre_gl/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import android.view.TextureView;
2323
import android.view.View;
2424
import android.widget.FrameLayout;
25-
import android.util.Pair;
2625

2726
import androidx.annotation.NonNull;
2827
import androidx.lifecycle.DefaultLifecycleObserver;
@@ -32,8 +31,8 @@
3231
import com.google.gson.JsonArray;
3332
import com.google.gson.JsonElement;
3433
import com.google.gson.JsonParser;
35-
import org.maplibre.android.gestures.AndroidGesturesManager;
36-
import org.maplibre.android.gestures.MoveGestureDetector;
34+
import com.mapbox.android.gestures.AndroidGesturesManager;
35+
import com.mapbox.android.gestures.MoveGestureDetector;
3736
import org.maplibre.geojson.Feature;
3837
import org.maplibre.geojson.FeatureCollection;
3938
import org.maplibre.android.camera.CameraPosition;
@@ -653,7 +652,7 @@ private void addHeatmapLayer(
653652
}
654653
}
655654

656-
private Pair<Feature, String> firstFeatureOnLayers(RectF in) {
655+
private Feature firstFeatureOnLayers(RectF in) {
657656
if (style != null) {
658657
final List<Layer> layers = style.getLayers();
659658
final List<String> layersInOrder = new ArrayList<String>();
@@ -666,7 +665,7 @@ private Pair<Feature, String> firstFeatureOnLayers(RectF in) {
666665
for (String id : layersInOrder) {
667666
List<Feature> features = mapLibreMap.queryRenderedFeatures(in, id);
668667
if (!features.isEmpty()) {
669-
return new Pair<Feature, String>(features.get(0), id);
668+
return features.get(0);
670669
}
671670
}
672671
}
@@ -1660,15 +1659,14 @@ public void onDidBecomeIdle() {
16601659
public boolean onMapClick(@NonNull LatLng point) {
16611660
PointF pointf = mapLibreMap.getProjection().toScreenLocation(point);
16621661
RectF rectF = new RectF(pointf.x - 10, pointf.y - 10, pointf.x + 10, pointf.y + 10);
1663-
Pair<Feature, String> featureLayerPair = firstFeatureOnLayers(rectF);
1662+
Feature feature = firstFeatureOnLayers(rectF);
16641663
final Map<String, Object> arguments = new HashMap<>();
16651664
arguments.put("x", pointf.x);
16661665
arguments.put("y", pointf.y);
16671666
arguments.put("lng", point.getLongitude());
16681667
arguments.put("lat", point.getLatitude());
1669-
if (featureLayerPair != null && featureLayerPair.first != null) {
1670-
arguments.put("layerId", featureLayerPair.second);
1671-
arguments.put("id", featureLayerPair.first.id());
1668+
if (feature != null) {
1669+
arguments.put("id", feature.id());
16721670
methodChannel.invokeMethod("feature#onTap", arguments);
16731671
} else {
16741672
methodChannel.invokeMethod("map#onMapClick", arguments);
@@ -2139,8 +2137,8 @@ boolean onMoveBegin(MoveGestureDetector detector) {
21392137
PointF pointf = detector.getFocalPoint();
21402138
LatLng origin = mapLibreMap.getProjection().fromScreenLocation(pointf);
21412139
RectF rectF = new RectF(pointf.x - 10, pointf.y - 10, pointf.x + 10, pointf.y + 10);
2142-
Pair<Feature, String> featureLayerPair = firstFeatureOnLayers(rectF);
2143-
if (featureLayerPair != null && featureLayerPair.first != null && startDragging(featureLayerPair.first, origin)) {
2140+
Feature feature = firstFeatureOnLayers(rectF);
2141+
if (feature != null && startDragging(feature, origin)) {
21442142
invokeFeatureDrag(pointf, "start");
21452143
return true;
21462144
}

maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
7171
longPress.require(toFail: recognizer)
7272
}
7373
var longPressRecognizerAdded = false
74-
74+
7575
if let args = args as? [String: Any] {
76-
76+
7777
Convert.interpretMapLibreMapOptions(options: args["options"], delegate: self)
7878
if let initialCameraPosition = args["initialCameraPosition"] as? [String: Any],
7979
let camera = MLNMapCamera.fromDict(initialCameraPosition, mapView: mapView),
@@ -170,7 +170,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
170170
if let langStr = Locale.current.languageCode {
171171
setMapLanguage(language: langStr)
172172
}
173-
173+
174174
result(nil)
175175
case "map#updateContentInsets":
176176
guard let arguments = methodCall.arguments as? [String: Any] else { return }
@@ -316,7 +316,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
316316
case "camera#move":
317317
guard let arguments = methodCall.arguments as? [String: Any] else { return }
318318
guard let cameraUpdate = arguments["cameraUpdate"] as? [Any] else { return }
319-
319+
320320
if let camera = Convert.parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView) {
321321
mapView.setCamera(camera, animated: false)
322322
}
@@ -325,12 +325,12 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
325325
guard let arguments = methodCall.arguments as? [String: Any] else { return }
326326
guard let cameraUpdate = arguments["cameraUpdate"] as? [Any] else { return }
327327
guard let camera = Convert.parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView) else { return }
328-
329-
328+
329+
330330
let completion = {
331331
result(nil)
332332
}
333-
333+
334334
if let duration = arguments["duration"] as? TimeInterval {
335335
if let padding = Convert.parseLatLngBoundsPadding(cameraUpdate) {
336336
mapView.fly(to: camera, edgePadding: padding, withDuration: duration / 1000, completionHandler: completion)
@@ -537,7 +537,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
537537
properties: properties
538538
)
539539
result(nil)
540-
540+
541541
case "heatmapLayer#add":
542542
guard let arguments = methodCall.arguments as? [String: Any] else { return }
543543
guard let sourceId = arguments["sourceId"] as? String else { return }
@@ -840,11 +840,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
840840
}
841841
layer.isVisible = visible
842842
result(nil)
843-
843+
844844
case "map#querySourceFeatures":
845845
guard let arguments = methodCall.arguments as? [String: Any] else { return }
846846
guard let sourceId = arguments["sourceId"] as? String else { return }
847-
847+
848848
var sourceLayerId = Set<String>()
849849
if let layerId = arguments["sourceLayerId"] as? String {
850850
sourceLayerId.insert(layerId)
@@ -853,10 +853,10 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
853853
if let filter = arguments["filter"] as? [Any] {
854854
filterExpression = NSPredicate(mglJSONObject: filter)
855855
}
856-
856+
857857
var reply = [String: NSObject]()
858858
var features: [MLNFeature] = []
859-
859+
860860
guard let style = mapView.style else { return }
861861
if let source = style.source(withIdentifier: sourceId) {
862862
if let vectorSource = source as? MLNVectorTileSource {
@@ -865,7 +865,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
865865
features = shapeSource.features(matching: filterExpression)
866866
}
867867
}
868-
868+
869869
var featuresJson = [String]()
870870
for feature in features {
871871
let dictionary = feature.geoJSONDictionary()
@@ -883,11 +883,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
883883

884884
case "style#getLayerIds":
885885
var layerIds = [String]()
886-
886+
887887
guard let style = mapView.style else { return }
888-
888+
889889
style.layers.forEach { layer in layerIds.append(layer.identifier) }
890-
890+
891891
var reply = [String: NSObject]()
892892
reply["layers"] = layerIds as NSObject
893893
result(reply)
@@ -902,18 +902,18 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
902902
var reply = [String: NSObject]()
903903
reply["sources"] = sourceIds as NSObject
904904
result(reply)
905-
905+
906906
case "style#getFilter":
907907
guard let arguments = methodCall.arguments as? [String: Any] else { return }
908908
guard let layerId = arguments["layerId"] as? String else { return }
909-
909+
910910
guard let style = mapView.style else { return }
911911
guard let layer = style.layer(withIdentifier: layerId) else { return }
912-
912+
913913
var currentLayerFilter : String = ""
914914
if let vectorLayer = layer as? MLNVectorStyleLayer {
915915
if let layerFilter = vectorLayer.predicate {
916-
916+
917917
let jsonExpression = layerFilter.mgl_jsonExpressionObject
918918
if let data = try? JSONSerialization.data(withJSONObject: jsonExpression, options: []) {
919919
currentLayerFilter = String(data: data, encoding: String.Encoding.utf8) ?? ""
@@ -925,11 +925,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
925925
).flutterError)
926926
return;
927927
}
928-
928+
929929
var reply = [String: NSObject]()
930930
reply["filter"] = currentLayerFilter as NSObject
931931
result(reply)
932-
932+
933933
default:
934934
result(FlutterMethodNotImplemented)
935935
}
@@ -967,16 +967,16 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
967967
private func getCamera() -> MLNMapCamera? {
968968
return trackCameraPosition ? mapView.camera : nil
969969
}
970-
970+
971971
private func setMapLanguage(language: String) {
972972
self.mapView.setMapLanguage(language)
973973
}
974974

975975
/*
976976
* Scan layers from top to bottom and return the first matching feature
977977
*/
978-
private func firstFeatureOnLayers(at: CGPoint) -> (feature: MLNFeature?, layerId: String?) {
979-
guard let style = mapView.style else { return (nil, nil) }
978+
private func firstFeatureOnLayers(at: CGPoint) -> MLNFeature? {
979+
guard let style = mapView.style else { return nil }
980980

981981
// get layers in order (interactiveFeatureLayerIds is unordered)
982982
let clickableLayers = style.layers.filter { layer in
@@ -989,10 +989,10 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
989989
styleLayerIdentifiers: [layer.identifier]
990990
)
991991
if let feature = features.first {
992-
return (feature, layer.identifier)
992+
return feature
993993
}
994994
}
995-
return (nil, nil)
995+
return nil
996996
}
997997

998998
/*
@@ -1004,15 +1004,13 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
10041004
let point = sender.location(in: mapView)
10051005
let coordinate = mapView.convert(point, toCoordinateFrom: mapView)
10061006

1007-
let result = firstFeatureOnLayers(at: point)
1008-
if let feature = result.feature {
1007+
if let feature = firstFeatureOnLayers(at: point) {
10091008
channel?.invokeMethod("feature#onTap", arguments: [
10101009
"id": feature.identifier,
10111010
"x": point.x,
10121011
"y": point.y,
10131012
"lng": coordinate.longitude,
10141013
"lat": coordinate.latitude,
1015-
"layerId": result.layerId,
10161014
])
10171015
} else {
10181016
channel?.invokeMethod("map#onMapClick", arguments: [
@@ -1055,23 +1053,22 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
10551053
let point = sender.location(in: mapView)
10561054
let coordinate = mapView.convert(point, toCoordinateFrom: mapView)
10571055

1058-
if dragFeature == nil, began, sender.numberOfTouches == 1 {
1059-
let result = firstFeatureOnLayers(at: point)
1060-
if let feature = result.feature,
1061-
let draggable = feature.attribute(forKey: "draggable") as? Bool,
1062-
draggable {
1063-
sender.state = UIGestureRecognizer.State.began
1064-
dragFeature = feature
1065-
originDragCoordinate = coordinate
1066-
previousDragCoordinate = coordinate
1067-
mapView.allowsScrolling = false
1068-
let eventType = "start"
1069-
invokeFeatureDrag(point, coordinate, eventType)
1070-
for gestureRecognizer in mapView.gestureRecognizers! {
1071-
if let _ = gestureRecognizer as? UIPanGestureRecognizer {
1072-
gestureRecognizer.addTarget(self, action: #selector(handleMapPan))
1073-
break
1074-
}
1056+
if dragFeature == nil, began, sender.numberOfTouches == 1,
1057+
let feature = firstFeatureOnLayers(at: point),
1058+
let draggable = feature.attribute(forKey: "draggable") as? Bool,
1059+
draggable
1060+
{
1061+
sender.state = UIGestureRecognizer.State.began
1062+
dragFeature = feature
1063+
originDragCoordinate = coordinate
1064+
previousDragCoordinate = coordinate
1065+
mapView.allowsScrolling = false
1066+
let eventType = "start"
1067+
invokeFeatureDrag(point, coordinate, eventType)
1068+
for gestureRecognizer in mapView.gestureRecognizers! {
1069+
if let _ = gestureRecognizer as? UIPanGestureRecognizer {
1070+
gestureRecognizer.addTarget(self, action: #selector(handleMapPan))
1071+
break
10751072
}
10761073
}
10771074
}

maplibre_gl/lib/src/annotation_manager.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ abstract class AnnotationManager<T extends Annotation> {
5555
}
5656
}
5757

58-
_onFeatureTapped(
59-
dynamic id, Point<double> point, LatLng coordinates, String layerId) {
58+
_onFeatureTapped(dynamic id, Point<double> point, LatLng coordinates) {
6059
final annotation = _idToAnnotation[id];
6160
if (annotation != null) {
6261
onTap!(annotation);

maplibre_gl/lib/src/controller.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ typedef OnMapClickCallback = void Function(
88
Point<double> point, LatLng coordinates);
99

1010
typedef OnFeatureInteractionCallback = void Function(
11-
dynamic id, Point<double> point, LatLng coordinates, String layerId);
11+
dynamic id, Point<double> point, LatLng coordinates);
1212

1313
typedef OnFeatureDragnCallback = void Function(dynamic id,
1414
{required Point<double> point,
@@ -93,8 +93,7 @@ class MapLibreMapController extends ChangeNotifier {
9393
_maplibrePlatform.onFeatureTappedPlatform.add((payload) {
9494
for (final fun
9595
in List<OnFeatureInteractionCallback>.from(onFeatureTapped)) {
96-
fun(payload["id"], payload["point"], payload["latLng"],
97-
payload["layerId"]);
96+
fun(payload["id"], payload["point"], payload["latLng"]);
9897
}
9998
});
10099

maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ class MapLibreMethodChannel extends MapLibrePlatform {
1818
final double y = call.arguments['y'];
1919
final double lng = call.arguments['lng'];
2020
final double lat = call.arguments['lat'];
21-
final String layerId = call.arguments['layerId'];
2221
onFeatureTappedPlatform({
2322
'id': id,
2423
'point': Point<double>(x, y),
25-
'latLng': LatLng(lat, lng),
26-
'layerId': layerId
24+
'latLng': LatLng(lat, lng)
2725
});
2826
case 'feature#onDrag':
2927
final id = call.arguments['id'];

0 commit comments

Comments
 (0)