Skip to content
Open
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
12 changes: 8 additions & 4 deletions example/lib/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ class LocationPageBodyState extends State<LocationPageBody> {
mapboxMap?.location.getSettings().then(
(value) => ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("""
Location settings :
enabled : ${value.enabled},
Location settings :
enabled : ${value.enabled},
puckBearingEnabled : ${value.puckBearingEnabled}
puckBearing : ${value.puckBearing}
pulsing : ${value.pulsingEnabled}
Expand All @@ -250,8 +250,12 @@ class LocationPageBodyState extends State<LocationPageBody> {

@override
Widget build(BuildContext context) {
final MapWidget mapWidget =
MapWidget(key: ValueKey("mapWidget"), onMapCreated: _onMapCreated);
final MapWidget mapWidget = MapWidget(key: ValueKey("mapWidget"),
onMapCreated: _onMapCreated,
onLocationChangeListener: (mapLocationChangeEventData) {
print(mapLocationChangeEventData);
}
);

final List<Widget> listViewChildren = <Widget>[];

Expand Down
1 change: 1 addition & 0 deletions ios/Classes/Generated/MapInterfaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ enum _MapEvent: Int {
case renderFrameStarted = 11
case renderFrameFinished = 12
case resourceRequest = 13
case locationChange = 14
}

/// The distance on each side between rectangles, when one is contained into other.
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/GesturesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ final class GesturesController: NSObject, GesturesSettingsInterface, UIGestureRe
return
}

let point = Point(mapView.mapboxMap.coordinate(for: gestureManager.singleTapGestureRecognizer.location(in: mapView)))
self.onGestureListener?.onTap(coordinate: ScreenCoordinate(x: point.coordinates.latitude, y: point.coordinates.longitude), completion: {_ in })
let touchPoint = gestureManager.singleTapGestureRecognizer.location(in: mapView)
onGestureListener?.onTap(coordinate: touchPoint.toFLTScreenCoordinate(), completion: { _ in })
}

func gestureManager(_ gestureManager: MapboxMaps.GestureManager, didEndAnimatingFor gestureType: MapboxMaps.GestureType) {}
Expand Down
12 changes: 12 additions & 0 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ class MapboxMapController: NSObject, FlutterPlatformView {
mapboxMap.onResourceRequest.observe { [weak self] payload in
self?.channel.invokeMethod(event.methodName, arguments: payload.toJSONString)
}.store(in: &cancelables)
case .locationChange:
mapView.location.onLocationChange.observe { [weak self] payload in
var data = ""
do {
let jsonData = try JSONSerialization.data(withJSONObject: payload.first!.coordinate.toDict())
data = String(data: jsonData, encoding: String.Encoding.utf8) ?? ""
} catch {
data = ""
}

self?.channel.invokeMethod(event.methodName, arguments: data)
}.store(in: &cancelables)
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/callbacks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ typedef void OnMapLongTapListener(ScreenCoordinate coordinate);

/// Gesture listener called on map scroll.
typedef void OnMapScrollListener(ScreenCoordinate coordinate);

/// Definition for listener invoked when the map location updates.
typedef void OnLocationChangeListener(
MapLocationChangeEventData mapLocationChangeEventData);
10 changes: 10 additions & 0 deletions lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ class ResourceEventData {
cancelled = json['cancelled'];
}

/// The class for map-loaded event in Observer
class MapLocationChangeEventData {
/// The `timeInterval.begin` represents the time when a style is set, and the
/// `timeInterval.end` is taken when the `map` is fully loaded.
final turf.Position position;

MapLocationChangeEventData.fromJson(Map<String, dynamic> json)
: position = turf.Position(json['coordinates'][0], json["coordinates"][1]);
}

/// Describes data source of request for resource-request event.
/// @param value String value of this enum
enum DataSourceType {
Expand Down
8 changes: 8 additions & 0 deletions lib/src/map_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class MapWidget extends StatefulWidget {
this.onTapListener,
this.onLongTapListener,
this.onScrollListener,
this.onLocationChangeListener,
}) : super(key: key) {
if (onStyleLoadedListener != null) {
_eventTypes.add(_MapEvent.styleLoaded);
Expand Down Expand Up @@ -110,6 +111,9 @@ class MapWidget extends StatefulWidget {
if (onResourceRequestListener != null) {
_eventTypes.add(_MapEvent.resourceRequest);
}
if (onLocationChangeListener != null) {
_eventTypes.add(_MapEvent.locationChange);
}
}

/// Describes the map options value when using a MapWidget.
Expand Down Expand Up @@ -183,6 +187,9 @@ class MapWidget extends StatefulWidget {
/// Invoked when map makes a request to load required resources.
final OnResourceRequestListener? onResourceRequestListener;

/// Invoked when the Map's location has been updated.
final OnLocationChangeListener? onLocationChangeListener;

/// Which gestures should be consumed by the map.
///
/// It is possible for other gesture recognizers to be competing with the map on pointer
Expand Down Expand Up @@ -271,6 +278,7 @@ class _MapWidgetState extends State<MapWidget> {
onMapTapListener: widget.onTapListener,
onMapLongTapListener: widget.onLongTapListener,
onMapScrollListener: widget.onScrollListener,
onLocationChangeListener: widget.onLocationChangeListener
);
_controller.complete(controller);
if (widget.onMapCreated != null) {
Expand Down
9 changes: 9 additions & 0 deletions lib/src/mapbox_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MapboxMap extends ChangeNotifier {
this.onMapTapListener,
this.onMapLongTapListener,
this.onMapScrollListener,
this.onLocationChangeListener,
}) : _mapboxMapsPlatform = mapboxMapsPlatform {
_proxyBinaryMessenger = _mapboxMapsPlatform.binaryMessenger;

Expand Down Expand Up @@ -95,6 +96,11 @@ class MapboxMap extends ChangeNotifier {
onResourceRequestListener?.call(argument);
});
}
if (onLocationChangeListener != null) {
_mapboxMapsPlatform.onLocationChangePlatform.add((argument) {
onLocationChangeListener?.call(argument);
});
}
_setupGestures();
}

Expand Down Expand Up @@ -148,6 +154,9 @@ class MapboxMap extends ChangeNotifier {
/// Invoked when map makes a request to load required resources.
final OnResourceRequestListener? onResourceRequestListener;

/// Invoked when the Map's location has been updated.
final OnLocationChangeListener? onLocationChangeListener;

/// The currently loaded Style]object.
late StyleManager style =
StyleManager(binaryMessenger: _proxyBinaryMessenger);
Expand Down
6 changes: 6 additions & 0 deletions lib/src/mapbox_maps_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class _MapboxMapsPlatform {
final onStyleImageUnusedPlatform =
ArgumentCallbacks<StyleImageUnusedEventData>();
final onResourceRequestPlatform = ArgumentCallbacks<ResourceEventData>();
final onLocationChangePlatform =
ArgumentCallbacks<MapLocationChangeEventData>();

final int _channelSuffix = _suffixesRegistry.getSuffix();
late MethodChannel _channel;
Expand Down Expand Up @@ -103,6 +105,10 @@ class _MapboxMapsPlatform {
onResourceRequestPlatform(
ResourceEventData.fromJson(jsonDecode(call.arguments)));
break;
case _MapEvent.locationChange:
onLocationChangePlatform(
MapLocationChangeEventData.fromJson(jsonDecode(call.arguments)));
break;
default:
throw MissingPluginException();
}
Expand Down
1 change: 1 addition & 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.