flutter_map_marker_cluster 0.2.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 95

Flutter Map Marker Cluster #

pub package travis

A Dart implementation of Leaflet.markercluster for Flutter apps. This is a plugin for flutter_map package

Usage #

Add flutter_map and flutter_map_marker_cluster to your pubspec:

dependencies:
  flutter_map: any
  flutter_map_marker_cluster: any # or the latest version on Pub

Add it in you FlutterMap and configure it using MarkerClusterGroupLayerOptions.

  Widget build(BuildContext context) {
    return FlutterMap(
      options: new MapOptions(
        plugins: [
          MarkerClusterPlugin(),
        ],
      ),
      layers: [
        TileLayerOptions(
          urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
          subdomains: ['a', 'b', 'c'],
        ),
        MarkerClusterLayerOptions(
          maxClusterRadius: 120,
          size: Size(40, 40),
          fitBoundsOptions: FitBoundsOptions(
            padding: EdgeInsets.all(50),
          ),
          markers: markers,
          polygonOptions: PolygonOptions(
              borderColor: Colors.blueAccent,
              color: Colors.black12,
              borderStrokeWidth: 3),
          builder: (context, markers) {
            return FloatingActionButton(
              child: Text(markers.length.toString()),
              onPressed: null,
            );
          },
        ),
      ],
    );
  }

Run the example #

See the example/ folder for a working example app.

[0.2.7] - 08/02/2019 #

  • Update support for latest flutter_map and add support for AndroidX #27

[0.2.6] - 08/02/2019 #

  • updated flutter_map

[0.2.5] - 18/11/2019 #

  • added animationsoptions
  • #24 Add optional onTap callback for Markers

[0.2.4] - 18/11/2019 #

  • added analysis_options.yaml
  • fix warnings

[0.2.0] - 26/06/2019 #

  • fix positions
  • spiderfyCircleDistanceMultiplier to spiderfyCircleRadius

[0.1.6] - 26/06/2019 #

  • fix circle spiferfy
  • splitted spiderfyDistanceMultiplier to spiderfyCircleDistanceMultiplier and spiderfySpiralDistanceMultiplier
  • added to gesturedetector behavior opaque
  • spiderfy marker animation starts to cluster point
  • added anchorpos to cluster in example

[0.1.5] - 20/06/2019 #

  • setState issue fixed ( #4 setState not supported )
  • added example with marker that change position

[0.1.4] - 17/06/2019 #

  • MarkerClusterGroupPlugin to MarkerClusterPlugin
  • MarkerClusterGroupLayerOptions to MarkerClusterLayerOptions
  • maxZoom and minZoom not required ( #2 MapOptions.minZoom required )
  • refresh when change markers ( #4 setState not supported )
  • fix when spiderfy

[0.1.3] - 07/06/2019 #

  • flutter_map version 0.5.5+2
  • options added anchorPos
  • removed removeOutsideVisibleBound

[0.1.2] - 07/06/2019 #

  • added option showPolygon
  • polygon line are all cluster's markers and not cluster's child

[0.1.1] - 06/06/2019 #

  • polygon under clusters and markers

[0.1.0] - 06/06/2019 #

  • added some tests and configurated travis ci

[0.0.1] - 06/06/2019 #

  • inital release

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart';
import 'package:latlong/latlong.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List<Marker> markers;
  int pointIndex;
  List points = [
    LatLng(51.5, -0.09),
    LatLng(49.8566, 3.3522),
  ];

  @override
  void initState() {
    pointIndex = 0;
    markers = [
      Marker(
        anchorPos: AnchorPos.align(AnchorAlign.center),
        height: 30,
        width: 30,
        point: points[pointIndex],
        builder: (ctx) => Icon(Icons.pin_drop),
      ),
      Marker(
        anchorPos: AnchorPos.align(AnchorAlign.center),
        height: 30,
        width: 30,
        point: LatLng(53.3498, -6.2603),
        builder: (ctx) => Icon(Icons.pin_drop),
      ),
      Marker(
        anchorPos: AnchorPos.align(AnchorAlign.center),
        height: 30,
        width: 30,
        point: LatLng(53.3488, -6.2613),
        builder: (ctx) => Icon(Icons.pin_drop),
      ),
      Marker(
        anchorPos: AnchorPos.align(AnchorAlign.center),
        height: 30,
        width: 30,
        point: LatLng(53.3488, -6.2613),
        builder: (ctx) => Icon(Icons.pin_drop),
      ),
      Marker(
        anchorPos: AnchorPos.align(AnchorAlign.center),
        height: 30,
        width: 30,
        point: LatLng(48.8566, 2.3522),
        builder: (ctx) => Icon(Icons.pin_drop),
      ),
      Marker(
        anchorPos: AnchorPos.align(AnchorAlign.center),
        height: 30,
        width: 30,
        point: LatLng(49.8566, 3.3522),
        builder: (ctx) => Icon(Icons.pin_drop),
      ),
    ];

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.refresh),
        onPressed: () {
          pointIndex++;
          if (pointIndex >= points.length) {
            pointIndex = 0;
          }
          setState(() {
            markers[0] = Marker(
              point: points[pointIndex],
              anchorPos: AnchorPos.align(AnchorAlign.center),
              height: 30,
              width: 30,
              builder: (ctx) => Icon(Icons.pin_drop),
            );

            // one of this
            markers = List.from(markers);
            // markers = [...markers];
            // markers = []..addAll(markers);
          });
        },
      ),
      body: FlutterMap(
        options: MapOptions(
          center: points[0],
          zoom: 5,
          plugins: [
            MarkerClusterPlugin(),
          ],
        ),
        layers: [
          TileLayerOptions(
            urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
            subdomains: ['a', 'b', 'c'],
          ),
          MarkerClusterLayerOptions(
            maxClusterRadius: 120,
            size: Size(40, 40),
            anchor: AnchorPos.align(AnchorAlign.center),
            fitBoundsOptions: FitBoundsOptions(
              padding: EdgeInsets.all(50),
            ),
            markers: markers,
            polygonOptions: PolygonOptions(
                borderColor: Colors.blueAccent,
                color: Colors.black12,
                borderStrokeWidth: 3),
            builder: (context, markers) {
              return FloatingActionButton(
                child: Text(markers.length.toString()),
                onPressed: null,
              );
            },
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_map_marker_cluster: ^0.2.7

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:flutter_map_marker_cluster/flutter_map_marker_cluster.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
91
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]
95
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_map ^0.8.2 0.8.2
latlong ^0.6.1 0.6.1
Transitive dependencies
ansicolor 1.0.2
async 2.4.1
cached_network_image 2.0.0
charcode 1.1.3
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 3.0.0
http 0.12.0+4
http_parser 3.1.4
intl 0.16.1
logging 0.11.4
matcher 0.12.6
meta 1.1.8
path 1.6.4
path_provider 1.6.5
path_provider_macos 0.0.4
path_provider_platform_interface 1.0.1
pedantic 1.9.0
platform 2.2.1
plugin_platform_interface 1.0.2
positioned_tap_detector 1.0.3
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
sqflite 1.3.0
sqflite_common 1.0.0+1
stack_trace 1.9.3
string_scanner 1.0.5
synchronized 2.2.0
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