MapLibreMapController constructor
MapLibreMapController({
- required MapLibrePlatform maplibrePlatform,
- required CameraPosition initialCameraPosition,
- required Iterable<
AnnotationType> annotationOrder, - required Iterable<
AnnotationType> annotationConsumeTapEvents, - OnStyleLoadedCallback? onStyleLoadedCallback,
- OnMapClickCallback? onMapClick,
- OnMapLongClickCallback? onMapLongClick,
- OnCameraTrackingDismissedCallback? onCameraTrackingDismissed,
- OnCameraTrackingChangedCallback? onCameraTrackingChanged,
- OnMapIdleCallback? onMapIdle,
- OnUserLocationUpdated? onUserLocationUpdated,
- OnCameraIdleCallback? onCameraIdle,
- OnCameraMoveCallback? onCameraMove,
Implementation
MapLibreMapController({
required MapLibrePlatform maplibrePlatform,
required CameraPosition initialCameraPosition,
required Iterable<AnnotationType> annotationOrder,
required Iterable<AnnotationType> annotationConsumeTapEvents,
this.onStyleLoadedCallback,
this.onMapClick,
this.onMapLongClick,
this.onCameraTrackingDismissed,
this.onCameraTrackingChanged,
this.onMapIdle,
this.onUserLocationUpdated,
this.onCameraIdle,
this.onCameraMove,
}) : _maplibrePlatform = maplibrePlatform {
_cameraPosition = initialCameraPosition;
_maplibrePlatform.onFeatureTappedPlatform.add((payload) {
final id = payload["id"].toString();
final layerId = payload["layerId"];
final point = payload["point"];
final latLng = payload["latLng"];
final annotation = getAnnotationById(id);
// Call all generic feature tapped callbacks
for (final fun in List.of(onFeatureTapped)) {
// New signature supplies id and (possibly null) annotation
fun(point, latLng, id, layerId, annotation);
}
// If we have a managed annotation, call specific annotation callbacks (onSymbolTapped, onLineTapped...)
if (annotation != null) {
ArgumentCallbacks? annotationTappedCallbacks;
if (annotation is Line) {
annotationTappedCallbacks = onLineTapped;
} else if (annotation is Symbol) {
annotationTappedCallbacks = onSymbolTapped;
} else if (annotation is Fill) {
annotationTappedCallbacks = onFillTapped;
} else if (annotation is Circle) {
annotationTappedCallbacks = onCircleTapped;
}
annotationTappedCallbacks?.call(annotation);
}
});
_maplibrePlatform.onFeatureDraggedPlatform.add((payload) {
final id = payload["id"];
final annotation = getAnnotationById(id);
final enmDragEventType = DragEventType.values
.firstWhere((element) => element.name == payload["eventType"]);
for (final fun in List.of(onFeatureDrag)) {
fun(
payload["point"],
payload["origin"],
payload["current"],
payload["delta"],
id,
annotation,
enmDragEventType,
);
}
});
_maplibrePlatform.onFeatureHoverPlatform.add((payload) {
final id = payload["id"];
final annotation = getAnnotationById(id);
final hoverEventType = HoverEventType.values
.firstWhere((e) => e.name == payload["eventType"]);
for (final fun in List.of(onFeatureHover)) {
fun(
payload["point"],
payload["latLng"],
id,
annotation,
hoverEventType,
);
}
});
_maplibrePlatform.onCameraMoveStartedPlatform.add((_) {
_isCameraMoving = true;
if (!isDisposed) notifyListeners();
});
_maplibrePlatform.onCameraMovePlatform.add((cameraPosition) {
_cameraPosition = cameraPosition;
onCameraMove?.call(cameraPosition);
if (!isDisposed) notifyListeners();
});
_maplibrePlatform.onCameraIdlePlatform.add((cameraPosition) {
_isCameraMoving = false;
if (cameraPosition != null) {
_cameraPosition = cameraPosition;
}
onCameraIdle?.call();
if (!isDisposed) notifyListeners();
});
_maplibrePlatform.onMapStyleLoadedPlatform.add((_) async {
final interactionEnabled = annotationConsumeTapEvents.toSet();
for (final type in annotationOrder.toSet()) {
final enableInteraction = interactionEnabled.contains(type);
switch (type) {
case AnnotationType.fill:
fillManager = FillManager(
this,
enableInteraction: enableInteraction,
);
await fillManager!.initialize();
case AnnotationType.line:
lineManager = LineManager(
this,
enableInteraction: enableInteraction,
);
await lineManager!.initialize();
case AnnotationType.circle:
circleManager = CircleManager(
this,
enableInteraction: enableInteraction,
);
await circleManager!.initialize();
case AnnotationType.symbol:
symbolManager = SymbolManager(
this,
enableInteraction: enableInteraction,
);
await symbolManager!.initialize();
}
}
onStyleLoadedCallback?.call();
});
_maplibrePlatform.onMapClickPlatform.add((dict) {
onMapClick?.call(dict['point'], dict['latLng']);
});
_maplibrePlatform.onMapLongClickPlatform.add((dict) {
onMapLongClick?.call(dict['point'], dict['latLng']);
});
_maplibrePlatform.onCameraTrackingChangedPlatform.add((mode) {
onCameraTrackingChanged?.call(mode);
});
_maplibrePlatform.onCameraTrackingDismissedPlatform.add((_) {
onCameraTrackingDismissed?.call();
});
_maplibrePlatform.onMapIdlePlatform.add((_) {
onMapIdle?.call();
});
_maplibrePlatform.onUserLocationUpdatedPlatform.add((location) {
onUserLocationUpdated?.call(location);
});
}