map_controller 0.5.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 89

Map controller #

pub package

Stateful map controller for Flutter Map. Manage markers, lines and polygons.

Api #

Api for the StatefulMapController class

Map controls #

Zoom #

zoom: get the current zoom value

zoomIn(): increase the zoom level by 1

zoomOut(): decrease the zoom level by 1

zoomTo(Double value): zoom to the provided value

Center #

center: get the current center LatLng value

centerOnPoint(LatLng point): center on the LatLng value

Map assets #

Markers #

addMarker(String name, Marker marker): add a named marker on the map

addMarkers(Map<String, Marker> markers): add several named markers on the map

removeMarker(String name, Marker marker): remove a named marker from the map

removeMarkers(Map<String, Marker> markers): remove several named markers from the map

markers: get the markers that are on the map

namedMarkers: get the markers with their names that are on the map

Lines #

addLine(String name, List<LatLng> points, double width = 1.0, Color color = Colors.green, bool isDotted = false): add a line on the map

lines: get the lines that are on the map

Polygons #

addPolygon(String name, List<LatLng> points, double width = 1.0, Color color = const Color(0xFF00FF00), double borderWidth = 0.0, Color borderColor = const Color(0xFFFFFF00)): add a polygon on the map

polygons: get the polygons that are on the map

On ready callback #

Execute some code right after the map is ready:

   @override
   void initState() {
      statefulMapController.onReady.then((_) {
         setState((_) =>_ready = true);
      });
      super.initState();
   }

Changefeed #

A changefeed is available: it's a stream with all state changes from the map controller. Use it to update the map when a change occurs:

   statefulMapController.onReady.then((_) {
       statefulMapController.changeFeed.listen((change) => setState(() {}));
      });
   }

Geojson data #

The map controller can draw on the map from geojson data:

void loadData() async {
  print("Loading geojson data");
  final data = await rootBundle.loadString('assets/airports.geojson');
  await statefulMapController.fromGeoJson(data,
    markerIcon: Icon(Icons.local_airport), verbose: true);
}

@override
void initState() {
  mapController = MapController();
  statefulMapController = StatefulMapController(mapController: mapController);
  statefulMapController.onReady.then((_) => loadData());
  sub = statefulMapController.changeFeed.listen((change) => setState(() {}));
  super.initState();
}

Tile layer management #

Some predefined tile layers are available.

   FlutterMap(
      mapController: mapController,
      options: MapOptions(
         center: LatLng(48.853831, 2.348722), zoom: 11.0),
      layers: [
         // Use the map controller's tile layer
         statefulMapController.tileLayer,
         MarkerLayerOptions(markers: statefulMapController.markers),
         // ...
      ],
   )

To switch tile layers at runtime use:

   statefulMapController.switchTileLayer(TileLayerType.monochrome);

Available layers:

   TileLayerType.normal
   TileLayerType.topography
   TileLayerType.monochrome
   TileLayerType.hike

A tile layers bar is available:

   Stack(children: <Widget>[
      FlutterMap(
         mapController: mapController,
         options: MapOptions(center: LatLng(48.853831, 2.348722), zoom: 11.0),
         layers: [
         statefulMapController.tileLayer,
         MarkerLayerOptions(markers: statefulMapController.markers),
         ],
      ),
      Positioned(
         top: 15.0,
         right: 15.0,
         child: TileLayersBar(controller: statefulMapController))
   ])

Changelog #

0.5.1 #

Add tile layer management

0.5.0 #

  • Upgrade dependencies
  • Use more strict analysis options
  • Add fitLine and addLineFromGeoPoints methods
  • Add fitMarker and fitMarkers methods

0.4.2 #

  • Add the fitLine method
  • Add the addLineFromGeoPoint method

0.4.1 #

  • Add support for geojson
  • Add the rotate method
  • Update dependencies

0.4.0 #

  • Add map controller change type
  • Add the fromGeoJson method

0.3.0 #

Add methods to add and remove polygons and lines

0.2.0 #

Update dependencies

0.1.0 #

Initial release

example/README.md

example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  map_controller: ^0.5.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:map_controller/map_controller.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
78
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on Dec 12, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
cupertino_icons ^0.1.2 0.1.3
extra_pedantic ^1.1.1+3 1.1.1+3
flutter 0.0.0
flutter_map ^0.7.3 0.7.3
geojson ^0.7.2 0.7.3
latlong ^0.6.1 0.6.1
pedantic ^1.7.0 1.9.0
rxdart ^0.22.6 0.22.6 0.23.0-dev.3
Transitive dependencies
ansicolor 1.0.2
async 2.4.0
cached_network_image 1.1.3 2.0.0-rc.1
charcode 1.1.2
collection 1.14.11 1.14.12
console_log_handler 1.1.6
convert 2.1.1
crypto 2.1.4
flutter_cache_manager 1.1.3
flutter_image 2.0.0 3.0.0
geodesy 0.3.2
geopoint 0.7.0
http 0.12.0+2
http_parser 3.1.3
intl 0.16.0
iso 0.2.3 0.3.0
logging 0.11.3+2
matcher 0.12.6
meta 1.1.8
path 1.6.4
path_provider 1.5.1
platform 2.2.1
positioned_tap_detector 1.0.3
quiver 2.1.2+1
sky_engine 0.0.99
slugify2 0.2.1
source_span 1.5.5
sqflite 1.1.8
stack_trace 1.9.3
string_scanner 1.0.5
synchronized 2.1.1
term_glyph 1.1.0
transparent_image 1.0.0
tuple 1.0.3
typed_data 1.1.6
uuid 2.0.4
validate 1.7.0
vector_math 2.0.8
Dev dependencies
flutter_test