rorystephenson / flutter_map_supercluster Goto Github PK
View Code? Open in Web Editor NEWVery fast Marker clustering for flutter_map. Supports efficient adding/removing of Markers.
License: BSD 3-Clause "New" or "Revised" License
Very fast Marker clustering for flutter_map. Supports efficient adding/removing of Markers.
License: BSD 3-Clause "New" or "Revised" License
The next version of flutter_map is coming soon, with breaking changes for all users and plugins!
Expected CHANGELOG: https://github.com/fleaflet/flutter_map/blob/release-prep/CHANGELOG.md
Likely to be merged PR with significant impacts: fleaflet/flutter_map#1615
Release prep PR: fleaflet/flutter_map#1632
New documentation (path liable to change): https://docs.fleaflet.dev/v/v6-1
Expected migration instructions, suitable for most users: https://docs.fleaflet.dev/v/v6-1/getting-started/migrating-to-v6
List of commits since v5 (more to come): fleaflet/flutter_map@v5.0.0...master
How do i make a customized cluster widgets that show a summary of their contained Markers as shown in your medium article?
Hello,
I'm getting following error:
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Illegal argument in isolate message: (object extends NativeWrapper - Library:'dart:ui' Class: EngineLayer)
#0 Isolate._spawnFunction (dart:isolate-patch/isolate_patch.dart:399:25)
#1 Isolate.spawn (dart:isolate-patch/isolate_patch.dart:379:7)
#2 Isolate.run (dart:isolate:238:15)
#3 compute (package:flutter/src/foundation/_isolates_io.dart:18:18)
#4 compute (package:flutter/src/foundation/isolates.dart:76:19)
#5 _SuperclusterLayerState._initializeClusterManager.<anonymous closure> (package:flutter_map_supercluster/src/layer/supercluster_layer.dart:339:15)
<asynchronous suspension>
What should I do?
Deps:
cupertino_icons: ^1.0.2
sliding_up_panel: ^2.0.0+1
vector_map_tiles: ^3.1.4
flutter_map: ^3.1.0
latlong2: ^0.8.1
geolocator: ^9.0.1
flutter_map_location_marker: ^5.1.0+1
flutter_svg: ^1.1.2
http: ^0.13.5
maps_launcher: ^2.0.1
url_launcher: ^6.1.5
flutter_map_dragmarker: ^4.1.2
cross_fade: ^0.3.1
connectivity_plus: ^3.0.2
flutter_launcher_icons: ^0.11.0
flutter_map_supercluster: ^2.2.0
Flutter version:
environment:
sdk: '>=2.18.0-257.0.dev <3.0.0'
Hi,
thanks a lot for your work here - your project is really amazing and helpful.
During the customization inside of my project I realized that the PopUp-style of a Marker is removed as soon as the splayed clusters will be collapsed (by zooming out or manually collapsing them). In my case it would be great if the style could be maintained so that the user can find the selected Marker again. Is there a chance to avoid collapsing when a Marker is in PopUp-mode or maintain it´s style even if it is collapsed? I have investigated your code but didn´t found an easy way to manipulate it. Maybe I am overseeing something?
BTW, I am using the mutable SuperClusterLayer.
Cheers
If I have several markers very close to each other, I can't zoom deeper to open cluster because map has some max zoom parameter.
I'm migrating from version 2.3.0 to the latest version, 5.0.0-dev1 and I'm facing issues from changes made in version 3.
I've previously implemented my own UI for lots of markers placed exactly onto each other. I'd like to keep that, but the ClusterSplayDelegate seems required by SuperclusterLayer and I couldn't find a way to disable it or force it to display just the underlying markers without interfering with the marker tap function.
Am I missing something?
When I try to assign markers to a list and giving it to initialMarkers (doesn't matter if as a layer or a list of Marker), it throws:
../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_map_supercluster-3.0.0+1/lib/src/layer/expanded_cluster_manager.dart:99:71: Error: The argument type 'int' can't be assigned to the parameter type 'LayerCluster<Marker>'.
- 'LayerCluster' is from 'package:supercluster/src/layer_element.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/supercluster-2.3.0/lib/src/layer_element.dart').
- 'Marker' is from 'package:flutter_map/src/layer/marker_layer.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_map-4.0.0/lib/src/layer/marker_layer.dart').
.childrenOf((layerCluster as ImmutableLayerCluster<Marker>).id)
This is how I set FlutterMap:
FlutterMap(
nonRotatedChildren: <Widget>[
SuperclusterLayer.immutable(
controller: _superclusterController,
calculateAggregatedClusterData: true,
clusterWidgetSize: const Size(40, 40),
anchor: AnchorPos.align(AnchorAlign.center),
initialMarkers: layer,
builder: (BuildContext context, LatLng position, int markerCount,
ClusterDataBase? extraClusterData) {
return Container(child: Text("culo"));
},
)
],
mapController: _mapController,
options: MapOptions(
onMapReady: () {
_mapController.mapEventStream.listen((evt) {});
// And any other `MapController` dependent non-movement methods
},
center: LatLng(41.902, 12.5),
zoom: 7,
),
children: [
//MarkerLayer(markers: markers,),
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.app',
),
],
),
And this how I add Markers to list:
loadJson() async {
final String response =
await rootBundle.loadString('TREMESTIERI_ETNEO.json');
final data = await json.decode(response);
for (var civ in data) {
print(civ);
markers.add(
Marker(
point: LatLng(
double.parse(civ['latitude']), double.parse(civ['longitude'])),
width: 50,
height: 50,
builder: (context) => IconButton(
onPressed: () {
print("culo");
},
icon: Icon(
Icons.circle,
))),
);
}
layer = MarkerLayer(
markers: markers,
);
}
Even copying the example in example/ gives the same error
tried setting maxClusterRadius between 1 and 80 and have not observed any difference
This originally added as a temporary solution for clusters that couldn't be opened because their un-clustering zoom was higher than the map's maximum zoom. Once cluster splaying was implemented I removed this option but it turns out some users want it for other valid reasons.
#12 Will resolve this, just waiting for flutter_map v6 to be released.
How to rotate cluster marker and it's child initialMarkers?
There are https://pub.dev/packages/flutter_map/versions/3.0.0-beta.3 new version of flutter_map.
Is plugin support planned for this version of map ?
There are following lines in SuperclusterLayer
:
/// Implement this function to extract extra data from Markers which can be
/// used in the [builder] and [computeSize].
final ClusterDataBase Function(Marker marker)? clusterDataExtractor;
But I can't find this computeSize
thing anywhere.
As I understand it should allow computing clusterWidgetSize
for each cluster instead of having constant one.
So could you please explain what computeSize
is and how to use it?
It is hoped that the onClusterTap
function will be added, so that the cluster's markers can be listed.
For example:
added onClusterTap function
I can add and remove markers. But I cannot modify them. Modifications cannot be seen on the map.
I use a custom marker called HashedMarker
with additional properties and overrides to handle equality. Even if I override equality of HashedMarker
when I modify a marker only position matters. Status changes don't trigger a rebuild.
class HashedMarker extends Marker {
final VoidCallback onTap;
final CustomMarker child;
final MarkerStatus status;
HashedMarker({
required super.point,
required this.onTap,
required this.child,
required this.status,
super.width = 80.0,
super.height = 80.0,
AnchorPos? anchorPos,
}) : super(
anchorPos: anchorPos ?? AnchorPos.align(AnchorAlign.top),
builder: (context) => GestureDetector(
onTap: onTap,
child: child,
),
);
HashedMarker copyWith({
VoidCallback? onTap,
CustomMarker? child,
MarkerStatus? status,
LatLng? point,
double? width,
double? height,
AnchorPos? anchorPos,
}) {
return HashedMarker(
point: point ?? super.point,
onTap: onTap ?? this.onTap,
child: child ?? this.child,
width: width ?? super.width,
height: height ?? super.height,
anchorPos: anchorPos ?? super.anchorPos,
status: status ?? this.status,
);
}
@override
bool operator ==(Object other) {
if (other is! HashedMarker) return false;
return super.point == other.point && this.status == other.status;
}
@override
int get hashCode =>Object.hash(super.point, status);
}
I have a custom marker controller that uses SuperclusterMutableController
's methods internally. And currently our focus on modifyMarker()
. Which I use like below:
class ClusterMarkerController {
final SuperclusterMutableController _superclusterController;
ClusterMarkerController()
: _superclusterController = SuperclusterMutableController();
static final List<HashedMarker> _hashedMarkersList = [];
SuperclusterMutableController get controller => _superclusterController;
void modifyMarker(HashedMarker newMarker) {
final index = _hashedMarkersList
.indexWhere((element) => element.point == newMarker.point);
final oldMarker = _hashedMarkersList[index];
_hashedMarkersList[index] = newMarker;
_superclusterController.modifyMarker(oldMarker, newMarker);
}
}
I give controller
to SuperclusterLayer.mutable
like below.
SuperclusterLayer.mutable(
controller: widget.clusterController.controller,
indexBuilder: IndexBuilders.computeWithCopiedMarkers,
...
)
In the readme.md you suggest to check out flutter_map_marker_plugin for beautiful clustering animations, where can I find it?
thank you
Hi,
I am using SuperclusterLayer.mutable
this is the complete widget code:
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.7,
child: FlutterMap(
options: MapOptions(
center: position,
zoom: 6,
maxZoom: 15,
rotationThreshold: 0,
rotation: 0,
pinchMoveWinGestures: MultiFingerGesture.pinchMove,
pinchZoomWinGestures: MultiFingerGesture.pinchZoom,
rotationWinGestures: MultiFingerGesture.none,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
keepBuffer: 5,
),
SuperclusterLayer.mutable(
initialMarkers: markers,
indexBuilder: IndexBuilders.rootIsolate,
builder: (context, position, markerCount, extraClusterData) => Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.blue,
),
child: Center(
child: Text(
markerCount.toString(),
style: const TextStyle(color: Colors.white),
),
),
),
),
],
),
But I can't turn off rotation when using the map from phone
How should I do it?
Best Regards
This was originally raised in another issue:
Hello @rorystephenson great work on this package, we love it!
With regards to markers that are too close to uncluster, we have a map where many markers may share the same coordinates, too many for splaying to make sense, and instead we were hoping to be able to override the splaying, and have a method that gives us the items of the cluster, which we may then use to open a listview in a modal. This would be more scalable and safe for an unknown and large amount of markers, contrary to the splaying which we believe could become troublesome for the user with too many markers. Is such a feature anything your package could support?
Hey mate, thanks for this package and your popup package! Im trying to upgrade to flutter map 4.0.0 along with your popup package 4.1.0 but im getting an issue with this package now:
Running "flutter pub get" in fsd_desktop...
Resolving dependencies...
Because flutter_map_supercluster >=2.2.1 depends on flutter_map ^3.1.0 and fsd_desktop depends on flutter_map ^4.0.0, flutter_map_supercluster >=2.2.1 is forbidden.
So, because fsd_desktop depends on flutter_map_supercluster ^2.3.0, version solving failed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.