MapShapeLayerController class

Provides option for adding, removing, deleting and updating marker collection.

You can also get the current markers count, selected shape's index and convert pixel points to latitude and longitude using this.

You need to set the instance of this to MapShapeLayer.controller as shown in the below code snippet.

List<Model> _data;
MapShapeLayerController controller;
MapShapeSource _mapSource;
Random random = Random();

@override
void initState() {
    _data = <Model>[
      Model(-14.235004, -51.92528),
      Model(51.16569, 10.451526),
      Model(-25.274398, 133.775136),
      Model(20.593684, 78.96288),
      Model(61.52401, 105.318756)
    ];
   _mapSource = MapShapeSource.asset(
     "assets/world_map.json",
     shapeDataField: "name",
  );

   controller = MapShapeLayerController();
   super.initState();
}

@override
Widget build(BuildContext context) {
   return Scaffold(
     body: Center(
         child: Container(
           height: 350,
           child: Padding(
             padding: EdgeInsets.only(left: 15, right: 15),
             child: Column(
               children: [
                 SfMaps(
                   layers: <MapLayer>[
                     MapShapeLayer(
                      source: _mapSource,
                       initialMarkersCount: 5,
                       markerBuilder: (BuildContext context, int index){
                         return MapMarker(
                           latitude: _data[index].latitude,
                           longitude: _data[index].longitude,
                           child: Icon(Icons.add_location),
                         );
                       },
                       controller: controller,
                     ),
                   ],
                 ),
                 RaisedButton(
                   child: Text('Add marker'),
                   onPressed: () {
                     data.add(Model(
                         -180 + random.nextInt(360).toDouble(),
                         -55 + random.nextInt(139).toDouble()));
                     controller.insertMarker(5);
                   },
                 ),
               ],
             ),
           ),
        )
     ),
  );
}

class Model {
 Model(this.latitude, this.longitude);

 final double latitude;
 final double longitude;
}
Inheritance

Constructors

MapShapeLayerController()

Properties

hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
markersCount int
Returns the current markers count.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(Object listener) → void
Register a closure to be called when the object changes.
inherited
clearMarkers() → void
Clears all the markers.
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
inherited
insertMarker(int index) → void
Adds marker dynamically in the provided index.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
pixelToLatLng(Offset position) MapLatLng
Converts pixel point to MapLatLng.
removeListener(Object listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
removeMarkerAt(int index) → void
Removes the marker in the provided index.
inherited
toString() String
A string representation of this object.
inherited
updateMarkers(List<int> indices) → void
Updates the markers in the given indices dynamically. See also:
inherited

Operators

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