Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
longPress.require(toFail: recognizer)
}
mapView.addGestureRecognizer(longPress)

if let args = args as? [String: Any] {
Convert.interpretMapboxMapOptions(options: args["options"], delegate: self)
if let initialCameraPosition = args["initialCameraPosition"] as? [String: Any],
Expand All @@ -72,8 +72,14 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
if let annotationConsumeTapEventsArg = args["annotationConsumeTapEvents"] as? [String] {
annotationConsumeTapEvents = annotationConsumeTapEventsArg
}
if let onAttributionClickOverride = args["onAttributionClickOverride"] as? Bool {
if onAttributionClickOverride {
setupAttribution(mapView)
}
}
}
}

func removeAllForController(controller: MGLAnnotationController, ids: [String]){
let idSet = Set(ids)
let annotations = controller.styleAnnotations()
Expand Down Expand Up @@ -813,7 +819,24 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
}
return MGLAnnotationView(frame: CGRect(x: 0, y: 0, width: 10, height: 10))
}


/*
* Override the attribution button's click target to handle the event locally.
* Called if the application supplies an onAttributionClick handler.
*/
func setupAttribution(_ mapView: MGLMapView) {
mapView.attributionButton.removeTarget(mapView, action: #selector(mapView.showAttribution), for: .touchUpInside)
mapView.attributionButton.addTarget(self, action: #selector(showAttribution), for: UIControl.Event.touchUpInside)
}

/*
* Custom click handler for the attribution button. This callback is bound when
* the application specifies an onAttributionClick handler.
*/
@objc func showAttribution() {
channel?.invokeMethod("map#onAttributionClick", arguments: [])
}

/*
* MGLMapViewDelegate
*/
Expand Down
12 changes: 12 additions & 0 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ part of mapbox_gl;
typedef void OnMapClickCallback(Point<double> point, LatLng coordinates);
typedef void OnMapLongClickCallback(Point<double> point, LatLng coordinates);

typedef void OnAttributionClickCallback();

typedef void OnStyleLoadedCallback();

typedef void OnUserLocationUpdated(UserLocation location);
Expand Down Expand Up @@ -38,6 +40,7 @@ class MapboxMapController extends ChangeNotifier {
{this.onStyleLoadedCallback,
this.onMapClick,
this.onMapLongClick,
this.onAttributionClick,
this.onCameraTrackingDismissed,
this.onCameraTrackingChanged,
this.onMapIdle,
Expand Down Expand Up @@ -125,6 +128,12 @@ class MapboxMapController extends ChangeNotifier {
}
});

MapboxGlPlatform.getInstance(_id).onAttributionClickPlatform.add((_) {
if (onAttributionClick != null) {
onAttributionClick!();
}
});

MapboxGlPlatform.getInstance(_id)
.onCameraTrackingChangedPlatform
.add((mode) {
Expand Down Expand Up @@ -158,6 +167,7 @@ class MapboxMapController extends ChangeNotifier {
OnMapClickCallback? onMapClick,
OnUserLocationUpdated? onUserLocationUpdated,
OnMapLongClickCallback? onMapLongClick,
OnAttributionClickCallback? onAttributionClick,
OnCameraTrackingDismissedCallback? onCameraTrackingDismissed,
OnCameraTrackingChangedCallback? onCameraTrackingChanged,
OnCameraIdleCallback? onCameraIdle,
Expand All @@ -167,6 +177,7 @@ class MapboxMapController extends ChangeNotifier {
onMapClick: onMapClick,
onUserLocationUpdated: onUserLocationUpdated,
onMapLongClick: onMapLongClick,
onAttributionClick: onAttributionClick,
onCameraTrackingDismissed: onCameraTrackingDismissed,
onCameraTrackingChanged: onCameraTrackingChanged,
onCameraIdle: onCameraIdle,
Expand All @@ -183,6 +194,7 @@ class MapboxMapController extends ChangeNotifier {
final OnMapLongClickCallback? onMapLongClick;

final OnUserLocationUpdated? onUserLocationUpdated;
final OnAttributionClickCallback? onAttributionClick;

final OnCameraTrackingDismissedCallback? onCameraTrackingDismissed;
final OnCameraTrackingChangedCallback? onCameraTrackingChanged;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/mapbox_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MapboxMap extends StatefulWidget {
this.onMapClick,
this.onUserLocationUpdated,
this.onMapLongClick,
this.onAttributionClick,
this.onCameraTrackingDismissed,
this.onCameraTrackingChanged,
this.onCameraIdle,
Expand Down Expand Up @@ -172,6 +173,8 @@ class MapboxMap extends StatefulWidget {
final OnMapClickCallback? onMapClick;
final OnMapClickCallback? onMapLongClick;

final OnAttributionClickCallback? onAttributionClick;

/// While the `myLocationEnabled` property is set to `true`, this method is
/// called whenever a new location update is received by the map view.
final OnUserLocationUpdated? onUserLocationUpdated;
Expand Down Expand Up @@ -217,6 +220,7 @@ class _MapboxMapState extends State<MapboxMap> {
'accessToken': widget.accessToken,
'annotationOrder': annotationOrder,
'annotationConsumeTapEvents': annotationConsumeTapEvents,
'onAttributionClickOverride': widget.onAttributionClick != null,
};
return _mapboxGlPlatform.buildView(
creationParams, onPlatformViewCreated, widget.gestureRecognizers);
Expand Down Expand Up @@ -267,6 +271,7 @@ class _MapboxMapState extends State<MapboxMap> {
onMapClick: widget.onMapClick,
onUserLocationUpdated: widget.onUserLocationUpdated,
onMapLongClick: widget.onMapLongClick,
onAttributionClick: widget.onAttributionClick,
onCameraTrackingDismissed: widget.onCameraTrackingDismissed,
onCameraTrackingChanged: widget.onCameraTrackingChanged,
onCameraIdle: widget.onCameraIdle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ abstract class MapboxGlPlatform {

final onMapLongClickPlatform = ArgumentCallbacks<Map<String, dynamic>>();

final onCameraTrackingChangedPlatform =
final ArgumentCallbacks<void> onAttributionClickPlatform =
ArgumentCallbacks<void>();

final ArgumentCallbacks<MyLocationTrackingMode>
onCameraTrackingChangedPlatform =
ArgumentCallbacks<MyLocationTrackingMode>();

final onCameraTrackingDismissedPlatform = ArgumentCallbacks<void>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class MethodChannelMapboxGl extends MapboxGlPlatform {
onMapLongClickPlatform(
{'point': Point<double>(x, y), 'latLng': LatLng(lat, lng)});

break;
case 'map#onAttributionClick':
onAttributionClickPlatform(null);
break;
case 'map#onCameraTrackingChanged':
final int mode = call.arguments['mode'];
Expand Down