controller property

MapTileLayerController? controller
final

Provides options for adding, removing, deleting, updating markers collection and converting pixel points to latitude and longitude.

late List<Model> data;
late MapTileLayerController controller;
late MapZoomPanBehavior _zoomPanBehavior;

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)
];

controller = MapTileLayerController();
_zoomPanBehavior = MapZoomPanBehavior();

super.initState();
}

@override
Widget build(BuildContext context) {
return FutureBuilder(
    future: getBingUrlTemplate(
        'http://dev.virtualearth.net/REST/V1/Imagery/Metadata/RoadOn
        Demand?output=json&include=ImageryProviders&key=YOUR_KEY'),
    builder: (context, snapshot) {
      if (snapshot.hasData) {
        return Column(
          children: [
            SfMaps(
              layers: [
                MapTileLayer(
                  initialFocalLatLng: MapLatLng(20.5937, 78.9629),
                  zoomPanBehavior: _zoomPanBehavior,
                  initialZoomLevel: 3,
                  urlTemplate: snapshot.data,
                  initialMarkersCount: 5,
                  markerBuilder: (BuildContext context, int index) {
                   return MapMarker(
                      latitude: data[index].latitude,
                      longitude: data[index].longitude,
                      child: Icon(Icons.add_location),
                    );
                  },
                ),
              ],
            ),
            RaisedButton(
              child: Text('Add marker'),
              onPressed: () {
                data.add(Model(-180 + random.nextInt(360).toDouble(),
                    -55 + random.nextInt(139).toDouble()));
                controller.insertMarker(5);
              },
            ),
          ],
        );
      }
      return CircularProgressIndicator();
    },
);
}

Implementation

final MapTileLayerController? controller;