NeshanMapController class
Controller for programmatically controlling the Neshan map.
This controller provides methods to interact with the map from Dart code, such as moving to locations, changing zoom, getting current state, and fitting bounds.
Usage
import 'package:neshan_maps_flutter/map.dart';
final controller = NeshanMapController();
NeshanMap(
mapKey: 'your-api-key',
controller: controller,
// ... other params
)
// Wait for the controller to be ready before using it
await controller.ready;
// Move the map to a specific location
controller.moveToLocation(35.6892, 51.3890, zoom: 15);
// Get current location
final location = await controller.getCurrentLocation();
print('Current center: ${location?.latitude}, ${location?.longitude}');
// Get current zoom
final zoom = await controller.getCurrentZoom();
print('Current zoom: $zoom');
// Fit map to bounds
controller.fitBounds(36.0, 35.0, 52.0, 51.0);
Important Notes
- Always await ready before calling controller methods to ensure the map is fully loaded and ready to receive commands.
- The ready future will timeout after 10 seconds if the map doesn't become ready.
- Methods that return values (like getCurrentLocation and getCurrentZoom)
may return
nullif the map is not ready or an error occurs.
Constructors
- NeshanMapController()
- Creates a new map controller.
Properties
Methods
-
addMarker(
NeshanMarker marker) → void - Adds a single marker to the map.
-
clearMarkers(
) → void - Clears all markers from the map.
-
dispose(
) → void - Disposes of the controller and cleans up resources.
-
fitBounds(
double north, double south, double east, double west) → void - Fits the map view to the specified bounds.
-
getCurrentLocation(
) → Future< LatLng?> - Gets the current center location of the map.
-
getCurrentZoom(
) → Future< double?> - Gets the current zoom level of the map.
-
moveToLocation(
double lat, double lng, {double? zoom}) → void - Moves the map to the specified location with optional zoom level.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeMarker(
String markerId) → void - Removes a marker from the map by its ID.
-
setIframe(
dynamic iframe) → void - Internal method to set the iframe element (web only).
-
setLogger(
NeshanMapLogger logger) → void - Internal method to set the logger.
-
setWebViewController(
dynamic controller) → void - Internal method to set the WebViewController (mobile only).
-
setZoom(
double zoom) → void - Sets the zoom level of the map.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateMarkers(
List< NeshanMarker> markers) → void - Updates all markers on the map.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited