Open fufylev opened 8 months ago
I have this same exact problem has anyone figured this out yet? It seems like it should be so simple here is my code why is it so hard to change the circle and make it tappable? There has to be a way?
void _addGeoJsonSourceWithClustering() async {
final mapClusterProvider = Provider.of<MapClusterProvider>(context, listen: false);
final geoJson = mapClusterProvider.createGeoJson();
String sourceId = "data";
Map<String, dynamic> sourceData = {
"type": "geojson",
"data": json.decode(geoJson),
"cluster": true,
"clusterRadius": 50,
"clusterMaxZoom": 14,
};
String encodedSourceData = jsonEncode(sourceData);
if (!(await mapboxMap?.style.styleSourceExists(sourceId) ?? true)) {
await mapboxMap?.style.addStyleSource(sourceId, encodedSourceData);
print('"data" source added to the map style');
_addClusteringLayers(sourceId);
}
}
void _addClusteringLayers(String sourceId) async {
// Add clusters layer
var layer = '''
{
"id": "clusters",
"type": "circle",
"source": "$sourceId",
"filter": ["has", "point_count"],
"paint": {
"circle-color": [
"step",
["get", "point_count"],
"#51bbd6",
100,
"#f1f075",
750,
"#f28cb1"
],
"circle-radius": [
"step",
["get", "point_count"],
20,
100,
30,
750,
40
]
}
}
''';
await mapboxMap?.style.addStyleLayer(layer, null);
print('"clusters" layer added to the map style');
// Add cluster count layer
var clusterCountLayer = '''
{
"id": "cluster-count",
"type": "symbol",
"source": "$sourceId",
"filter": ["has", "point_count"],
"layout": {
"text-field": "{point_count_abbreviated}",
"text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
"text-size": 12
}
}
''';
await mapboxMap?.style.addStyleLayer(clusterCountLayer, null);
print('"cluster-count" layer added to the map style');
// Add unclustered point layer
var unclusteredLayer = '''
{
"id": "unclustered-point",
"type": "circle",
"source": "$sourceId",
"filter": ["!", ["has", "point_count"]],
"paint": {
"circle-color": "#f62323",
"circle-radius": 40,
"circle-stroke-width": 1,
"circle-stroke-color": "#fff"
}
}
''';
await mapboxMap?.style.addStyleLayer(unclusteredLayer, null);
print('"unclustered-point" layer added to the map style');
}
@fufylev did you find any work around for this? the api of this package is really becoming a pain in the *ss
@fufylev did you find any work around for this? the api of this package is really becoming a pain in the *ss
Nope, spent a lot of time, still at the same trubble point.
Version mapbox_maps_flutter: ^0.5.1 is being used. Flutter version 3.16.2
Is there any way to combine Markers and Clusters in the way that they know that each other exists on the map?
I render Markers by means of
pointAnnotationManager
and render Clusters as per your example file. Both Markers and Clusters are displayed on the screen, but when some points are inside Cluster their markers are still visible. In example YOU use unclusteredLayer instead of Markers. As for the Cluster I found the way how to style it, however as forunClusteredLayer
I didn't find any way or example on how to set it as an Image but not a simple circle. Nevertheless, even if I find the way how to setunClusteredLayer
as an Image I didn't find any way to listen to tap on cluster or onunClusteredLayer
.Please, provide a complete example, that includes both clusters and "custom" markers as an Image where these "custom" markers are not visible inside cluster and the way to listen tap on cluster or
unClusteredLayer
.Here is the my code that is responsible for both Clusters and Markers.
File "create_image_from_widget.dart":
Just for info here is my flutter doctor result:
In order to make muself clear I also included the video and screenshots of my problem where rounded boxes with Image inside are my custom Markers converted from
Widget
toUint8List
:Without my custom dynamic Markers:
With my custom dynamic Markers:
Here you can see that Markers are outside clusters:
https://github.com/mapbox/mapbox-maps-flutter/assets/35691656/98207a35-eaae-43b6-8021-2f225f8c8857