moveRaw method
Internal endpoint to move the MapCamera and change zoom level.
Implementation
bool moveRaw(
LatLng newCenter,
double newZoom, {
Offset offset = Offset.zero,
required bool hasGesture,
required MapEventSource source,
String? id,
}) {
// Algorithm thanks to https://github.com/tlserver/flutter_map_location_marker
LatLng center = newCenter;
if (offset != Offset.zero) {
final newPoint = camera.projectAtZoom(newCenter, newZoom);
center = camera.unprojectAtZoom(
camera.rotatePoint(
newPoint,
newPoint - offset,
),
newZoom,
);
}
MapCamera? newCamera = camera.withPosition(
center: center,
zoom: camera.clampZoom(newZoom),
);
newCamera = options.cameraConstraint.constrain(newCamera);
if (newCamera == null ||
(newCamera.center == camera.center && newCamera.zoom == camera.zoom)) {
return false;
}
final oldCamera = camera;
value = value.withMapCamera(newCamera);
final movementEvent = MapEventWithMove.fromSource(
oldCamera: oldCamera,
camera: camera,
hasGesture: hasGesture,
source: source,
id: id,
);
//! PREVENTS TILE LOADING IF SOURCE NOT CONFIGURED IN CONSTRUCTOR
if (movementEvent != null) _emitMapEvent(movementEvent);
options.onPositionChanged?.call(newCamera, hasGesture);
return true;
}