setCursorScreenPosition method
Updates the cursor's screen position for map selection.
Sets the cursor to the specified screen coordinates, enabling selection of map elements (landmarks, routes, markers, overlayitems, paths, streets, traffic events) at that location. After setting the cursor position, use selection methods like cursorSelectionLandmarks, cursorSelectionRoutes, cursorSelectionMarkers, cursorSelectionOverlayItems, cursorSelectionPath, cursorSelectionStreets, or cursorSelectionTrafficEvents to retrieve selected elements.
This asynchronous method must be awaited before querying selections to ensure the cursor update completes. Failing to await may result in empty selection lists or selections from the previous cursor position.
The cursor position also influences centering operations when no explicit screen position is provided to methods like centerOnCoordinates.
Parameters
screenPosition: The target cursor position in physical pixels, relative to the map view's top-left corner
See also:
- cursorScreenPosition - Get current cursor position
- cursorSelectionLandmarks - Get landmarks at cursor position
- cursorSelectionRoutes - Get routes at cursor position
- resetMapSelection - Reset cursor to viewport center
Implementation
Future<void> setCursorScreenPosition(final Point<int> screenPosition) async {
// This method needs to be async
await GemKitPlatform.instance
.getChannel(mapId: mapId)
.invokeMethod<String>(
'callObjectMethod',
jsonEncode(<String, dynamic>{
'id': _pointerId,
'class': 'MapView',
'method': 'setCursorScreenPosition',
'args': XyType<int>(x: screenPosition.x, y: screenPosition.y),
}),
);
}