move method
bool
move(
- LatLng newCenter,
- double newZoom, {
- bool hasGesture = false,
- required MapEventSource source,
- String? id,
Implementation
bool move(
LatLng newCenter,
double newZoom, {
bool hasGesture = false,
required MapEventSource source,
String? id,
}) {
newZoom = fitZoomToBounds(newZoom);
if (newCenter == _center && newZoom == _zoom) return false;
if (isOutOfBounds(newCenter)) {
if (!options.slideOnBoundaries) {
return false;
}
newCenter = containPoint(newCenter, _center);
}
// Try and fit the corners of the map inside the visible area.
// If it's still outside (so response is null), don't perform a move.
if (options.maxBounds != null) {
final adjustedCenter = adjustCenterIfOutsideMaxBounds(
newCenter, newZoom, options.maxBounds!);
if (adjustedCenter == null) {
return false;
} else {
newCenter = adjustedCenter;
}
}
final LatLng oldCenter = _center;
final double oldZoom = _zoom;
//Apply state then emit events and callbacks
setState(() {
_zoom = newZoom;
_center = newCenter;
});
_pixelBounds = getPixelBounds(_zoom);
_bounds = _calculateBounds();
_pixelOrigin = getNewPixelOrigin(newCenter);
final movementEvent = MapEventWithMove.fromSource(
targetCenter: newCenter,
targetZoom: newZoom,
oldCenter: oldCenter,
oldZoom: oldZoom,
hasGesture: hasGesture,
source: source,
);
if (movementEvent != null) emitMapEvent(movementEvent);
options.onPositionChanged?.call(
MapPosition(
center: newCenter,
bounds: _bounds,
zoom: newZoom,
hasGesture: hasGesture,
),
hasGesture,
);
return true;
}