I am using cluster group. But how to limit cluster expand level. Suppose default cluster group loads with continent level then click. It expand to deeper level and when third time click on cluster group again it expand to country level. I want to fix three expand level of cluster group not below country level.
I tried freezeAtZoom() but it stops the cluster group from expand even from first level..
Your issue is still a little bit unclear.
Note first that when clicking on a cluster, it zooms to the extent of its child markers. This could represent a few zoom levels, depending on the actual child markers. It could even be directly the map's maximum zoom level, if all markers are really close one to each other. So there is no predefined target zoom level that the map will go to when you click, it all depends on the markers in that cluster.
Now if these markers do not change, and you can record the exact map's zoom level at which you want your clusters to no longer split apart on clicking, you have several ways to achieve that:
Define the map's maxZoom option to that zoom level, so that your users cannot go any deeper.
Add a map's "zoomend" event listener, so that if user goes deeper that your known zoom level, you freeze the cluster group to that recorded zoom. Remember that .freezeAtZoom(frozenZoom) can take an argument to specify at which zoom level the clusters should be frozen at, no matter the current zoom level.
Replace your individual markers by their equivalent cluster at your recorded zoom level ("country level"), maybe use Leaflet.markercluster singleMarkerMode option for styling, and iconCreateFunction option to override the counts and make them appear as if the clusters had many markers.
Related
Given a bound box like the below picture, how do you get all the features contained within, regardless of if they are visible or not.
I have tried to get all roads using
let features = map.querySourceFeatures('composite', {sourceLayer: 'road'})
But it only gives me roads that are visible if I am zoomed in.
I have also tried
let features = map.queryRenderedFeatures([tile_info.swPt, tile_info.nePt])
But again, it only gets features visible on the map based on zoom level.
I need all the features within the bounding box regardless of what you can see or zoom level
It is in the nature of vector tiles that you can not do what you want to do here. You can only query data which has been loaded into the browser, and the point of the vector tile architecture is to prevent that happening at lower zooms.
You could consider a server based approach like Tilequery.
I am generating a layer UK scale, it is composed for several polygons, the idea for the layer is to display it fully and then the user can zoom to most specific area. The main problem is because the number of polygons when I create the .mbtile it split some of the polygon at determined zooms.
I have tried with different options of tippecanoe like --not duplication extend zooms if still dropping ... but I couldn't nail whit the correct commands to make it work.
tippecanoe -zg --read-parallel -l $LAYER -o "$OUT_MBTILES" "$OUT_JSON" --coalesce-densest-as-needed --extend-zooms-if-still-dropping --no-duplication
I suspect this is somehow related to --no-duplication. Per the documentation:
--no-duplication: As with --no-clipping, each feature is included intact instead of cut to tile boundaries. In addition, it is included only in a single tile per zoom level rather than potentially in multiple copies. Clients of the tileset must check adjacent tiles (possibly some distance away) to ensure they have all features.
I'm not sure why you're using that option, but disable it if possible.
It's hard to be more specific without seeing your data and having a lot more information about what you're trying to achieve, zoom levels, attributes, data size etc.
When you zoom in and out, the markerclusters automatically "re-cluster", as in it calculates clustering again.
Is there an option for to disable the auto re-cluster when the zoom is changed?
Depending on exactly what you are trying to achieve, you might be interested in Leaflet.MarkerCluster.Freezable subplugin:
When frozen / disabled, clusters will no longer split / merge on map zoom, but retain their status as if they were on the specified zoom level.
For example if you want the clusters to reflect the zoom 15 configuration:
var map = L.map("map"),
mcg = L.markerClusterGroup(options);
mcg.addLayers(arrayOfMarkers);
mcg.addTo(map);
mcg.freezeAtZoom(15);
Disclaimer: I am the author of that subplugin.
Is there an option for to disable the auto re-cluster when the zoom is changed?
No.
In Leaflet.MarkerCluster, the cluster depends on the value of the maxClusterRadius option, which is measured in screen pixels at the current zoom level.
I encourage you to have a look at the other Leaflet plugins for clustering, as some of them have clustering algorithms which do not depend on the zoom level.
I have drawn a graph using arborjs with about 15-20 nodes. Is there a way to ensure that two particular nodes never overlap. In fact, it would be better if they have a quite large distance between them or are simply situated at the extremes of the canvas.
Im using Annotations in IOS to display London Tube stations, but im looking at numbers and there are 280 or so.
Whats the easiest way to do this?
Individually or is there another option?
Cheers for all the advice
David
The performance is good with 280 annotations, the appearance is not. You have to group them into clusters when the user zooms out.
One way to do it is:
Decide how many cluster annotations you want to show.
Split the screen in x*y tiles so roughly x*y =~ numClusters and x/y=480/320=1.5
Add a cluster annotation per tile (it's a normal cluster with an array containing 0 or more annotations).
Run the k-means algorithm:
Iterate all annotations and add each one to the closest cluster.
Calculate a new center for each cluster, which will be an average of the centers of all its members.
Empty each cluster.
Repeat until no cluster moves any longer.
Remove empty clusters, if any.
You end up with numClusters clusters positioned according to the annotation density.
You can also leave a number of normal annotations on their own if they are away from the clusters. Depends on how you want it to look.