SCEE
SCEE copied to clipboard
Add clustering
This is still very basic, it only increases quest dot radius with point_count.
Since we want to get rid of quest dots, this is obviously only some sort of demo / playground.
Currently
- I don't understand what
withClusterPropertyis doing - I don't have an idea how the clusters should look like
- I don't know what should happen when selecting a cluster (Zoom in? Open the highest priority quest? Show all contained quests? Nothing?
Help for continuing: https://maplibre.org/maplibre-gl-js/docs/examples/cluster/ https://github.com/maplibre/maplibre-native/blob/main/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/style/GeoJsonClusteringActivity.kt
I don't know what should happen when selecting a cluster (Zoom in? Open the highest priority quest? Show all contained quests? Nothing?
Zoom in sounds reasonable. However, note that there can be several quests on the same element, i.e. on the exact same position. The most practical solution would probably be to not show any clusters starting a certain zoom level anymore but only show quests.
I don't have an idea how the clusters should look like
I'd expect circles with a number in the middle. Maybe optionally colored by the magnitude of that number on a gradient, but since this would necessitate coming up with a good (best color-blind-friendly) palette, could do that some time later and just start with white.
Now it's working in a very basic way. I'd like the zoom-in to contain all clustered pins, will have a look on how to do that later.
I think the basics are working now. The number is inside a white circle, and the circle size slightly increases with number of quests. I did this because otherwise for more than 100 quests the number is too close to circle edge, or the circle for small numbers looks empty.
When clicking, the map is centered on the click position, and zoomed to the "cluster expansion zoom", i.e. the zoom at which the cluster splits into pins or smaller clusters. This could possibly be adjusted to zoom to the bbox that contains all children of the cluster.
what if anything is returned when clicking
What should be returned by the component? A camera update?
What should be returned by the component? A camera update?
I didn't completely think this through, but I was thinking along the lines of that the OverlayComponent would return the ElementKey, the QuestPinComponent the... hmm, I guess the properties. And in case of clicking on a cluster, do the zoom-in itself.
(Maybe it's a bit dirty that the PinsComponent is used by two different data sources and then switched forth-and-back. It could also be solved by it being a class with a name parameter or an abstract superclass and result in having two completely separate components)
I was thinking along the lines of that the OverlayComponent would return the ElementKey, the QuestPinComponent the... hmm, I guess the properties. And in case of clicking on a cluster, do the zoom-in itself.
So this is more general than the scope of this PR then? I guess it would be better to do it after the PR is done.
Then for this I'd play a little with trying to get a better zoom / target bbox out of getClusterChilden or getClusterLeaves, and maybe try playing with background color depending on number of elements with quests.
[edit: FeatureCollection has a bbox, which would be really convenient here, but it seems to always return null]
So this is more general than the scope of this PR then?
Yes
[edit: FeatureCollection has a bbox, which would be really convenient here, but it seems to always return null]
There should be a function in SphericalEarthMath somewhere that calculates the bbox of a set of latlons.
There should be a function in
SphericalEarthMathsomewhere that calculates the bbox of a set of latlons.
I have it already working, but it's a bit annoying to deal with. Will commit the current state and continue working.
So the idea of returning a CameraUpdate from the cluster Feature will not work, because we need MapLibreMap.getCameraForLatLngBounds.
the sorting could also be put into the Manager
Not sure whether it's worth the work, doesn't look like a straightforward change to me.
Really? It looked to me like a straightforward change. No matter. I just got an idea that may or may not look nice:
I offset the quest dots a bit up so that they are hidden behind the pins. The same technique could be used to move the cluster circle up so that it's circular area is where the pin circle has it's center. This may look quite nice when zooming in, because the circle may look kind of like it turns into a pin.
I just tried offsets, and it looks really awkward when zooming, because the circles move relative to the surrounding map geometry. Also the cluster circles are typically located somewhere between pins, so they will not turn into a pin anyway.
Btw it looks like the circleTranslate moves the circles on the map, and not on the screen. Try rotating the map by 180° and you will see the circles appearing from behind the pins.
Though maybe the circleTranslate issue can be fixed using circleTranslateAnchor
Oh right, probably circleTranslateAnchor=viewport
Did that now on maplibre branch.
I tried playing with colors, essentially copying from the example in first post, just using point_count and different stop values and colors.
There was nothing I really liked so far, and possibly simple white just fits best into SC.
Is there anything else you would like to change or try? Otherwise I think the PR would be ready.
No, looks fine!
If colors don't look nice, another angle could be to play with bold font vs normal font / text size.
I've finally taken a look and tuned a small thing. Merging!