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 null if the map is not ready or an error occurs.

Constructors

NeshanMapController()
Creates a new map controller.

Properties

hashCode int
The hash code for this object.
no setterinherited
ready Future<void>
Future that completes when the controller is ready to receive commands.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addCircle(NeshanCircle circle) → void
Adds a single circle to the map.
addMarker(NeshanMarker marker) → void
Adds a single marker to the map.
addPolygon(NeshanPolygon polygon) → void
Adds a single polygon to the map.
addPolyline(NeshanPolyline polyline) → void
Adds a single polyline to the map.
clearCircles() → void
Clears all circles from the map.
clearMarkers() → void
Clears all markers from the map.
clearPolygons() → void
Clears all polygons from the map.
clearPolylines() → void
Clears all polylines 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
removeCircle(String circleId) → void
Removes a circle from the map by its ID.
removeMarker(String markerId) → void
Removes a marker from the map by its ID.
removePolygon(String polygonId) → void
Removes a polygon from the map by its ID.
removePolyline(String polylineId) → void
Removes a polyline 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
updateCircles(List<NeshanCircle> circles) → void
Updates all circles on the map.
updateMarkers(List<NeshanMarker> markers) → void
Updates all markers on the map.
updatePolygons(List<NeshanPolygon> polygons) → void
Updates all polygons on the map.
updatePolylines(List<NeshanPolyline> polylines) → void
Updates all polylines on the map.

Operators

operator ==(Object other) bool
The equality operator.
inherited