Mapbox-gl-native: point clustering

Created on 11 Jun 2014  Â·  62Comments  Â·  Source: mapbox/mapbox-gl-native

Once we have #170 GeoJSON with arbitrary points complete, then we need to be able to cluster overlay points for parity with existing mobile APIs.

Android feature iOS

Most helpful comment

@shfishburn we work on it actively now, with the intention of releasing it next month as a GL Native feature (available on both iOS and Android).

All 62 comments

Any status on Marker clustering in iOS?

I'm interested in annotation clustering on iOS as well :+1: .

Any idea when something like this will be released?

Nothing on the radar right now for clustering, but stay tuned for annotations improvements in the medium-term. In short, we are thinking more about potential aspects of annotations that are unique to Mapbox GL and not necessarily derivative of what's been done with maps frameworks before.

Clustering it's very important feature as for me. I hope it will be added soon.

Dear Developers, i need you advice :)
Clustering it's critical task in my current project, so what should i do, use old SDK because it has clustering or wait for clustering in prerelease versions? Main problem is that i can't wait more than two-three weeks. Thank you.

Clustering is not on a current timeline for 2015. Stuff needs to happen under the hood in what we’re calling the runtime style API first (see #837). /cc @jfirebaugh

@incanus Okay, can i use old SDK version and buy standard or premium plan?

@Sh1mor1nka - happy to figure out which plan is correct for you while you're waiting for clustering via the GL SDKs. Want to shoot a note to [email protected] with this ticket number included for reference?

@pdgoodman i don't have much time, may be two weeks, maybe thee, but not more, and as your developer says: "Clustering is not on a current timeline for 2015". All i can is to use old SDK, but i don't know if i can do tbis, maybe it's not supported by current API version, so i'm waiting for developer answer.

Clustering is done client-side and is indeed still active in the iOS SDK 1.x (which is not based on Mapbox GL or OpenGL). So you should be fine to go there. You’ll want to look at the clustering-related properties on RMMapView.

@incanus Sorry, but can you share reference where i can download latest SDK 1.x version?

UPD: Okay, i find it https://github.com/mapbox/mapbox-ios-sdk-legacy
But what pricing plans i can use with this SDK?

:point_right: https://github.com/mapbox/mapbox-ios-sdk-legacy

It's also available in CocoaPods as Mapbox-iOS-SDK up to version 1.6.1.

Hi guys. Is there an expected solution to the whole no-clustering issue on iOS?

I would also love to see clustering on ios/android sdk

Now that JS SDK has gotten clustering support #1931 what needs to happen to get similar on this?

I'd expect this to come in a few weeks. I'm working on porting https://github.com/mapbox/supercluster, which is relatively small, to C++11. Integration into gl-native then should be pretty easy.

Sounds great @mourner!

I've gone ahead an tried implementing clustering using quad tree using FBAnnotationClustering converting it to support mapbox instead.

But I get stuck on how to get zoom scale and width of visible view from mapbox similar to this

double scale = self.mapView.bounds.size.width / self.mapView.visibleMapRect.size.width;

and converting this to support mapbox constants

NSInteger FBZoomScaleToZoomLevel(MKZoomScale scale)
{
    double totalTilesAtMaxZoom = MKMapSizeWorld.width / 256.0;
    NSInteger zoomLevelAtMaxZoom = log2(totalTilesAtMaxZoom);
    NSInteger zoomLevel = MAX(0, zoomLevelAtMaxZoom + floor(log2f(scale) + 0.5));

    return zoomLevel;
}

But implementing clustering using r tree is the way to go, have you any ideas where I can find a r tree library for objective-c? Can then look into converting supercluster to objective-c.

Maybe start porting your wonderful rbush is a good start.

@maqen I don't know since I focus on JS development, but the coming implementation in gl-native will most likely use boost:rtree. We're still eager to try porting rbush someday and seeing how it compares.

In addition, I'm doing some experiments on a different index instead of an R-tree, optimized for clustering and based on lexicographic array sorting in a grid + binary search. But it may take a while before I get results, although I'm certain it will be faster than R-Tree.

We manage about 22m POIs in the US with very, very high density urban areas. The clustering feature is supported in the 1.x SDK but not yet in 3.x. Options seem to be:

A. Use a deprecated SDK.
B. Use a web view in iOS with Leaflet (for example)
C. Live without it.
D. Port or write a bunch of custom code.
E. Revert to using Google Maps

None of these are good options. Am I missing something?

@shfishburn as I said earlier, we are going to port https://github.com/mapbox/supercluster to C++11 and then use it in mapbox-gl-native to support efficient point clustering. It's not a big effort, but we have a lot of other things on our plate right now, so I can't give more precise estimates of when this will be done other than "soon".

We process 22 million POIs, 370 million consumers in 524 user profiles, and movement data of those consumers using anonymized data from the four major US carriers. We work with pivot data (entry and exit from geofences). Our evaluation of Mapbox comes down to TWO issues. This one in iOS and working with your platform with respect to building level geofences.

I’m totally sensitive to developer priorities. If there is no better answer than "soon, I understand. We will move back to ArcGIS.

Note: we have this working with a slightly different implementation given this library as a starting point (https://github.com/DDRBoxman/google-maps-ios-utils/blob/master/Clustering/GCluster.h) and about 600 more lines of Objective C. The result looks like the attached image (dots & markers). As the user zooms in and out of the map, the dots convert to markers and vice versa. At this point, though, I'd be happy with circles and numbers that split and join given zoom in/out.

map

Hi incanus, I love your work.
Can you get your company to throw some $$$ at this problem?

The suggestion to use v1 has limitations around unlimited map views
Plus using swift with latest sdk has to be the recommended moving forward?
You just need to put forward a case that supporting v1 is a headache / tech debt and we need to support clustering.

I have experience with this - and fixed the google maps ios sdk here ->
https://github.com/DDRBoxman/google-maps-ios-utils/pull/16
I would think it shouldn't take a week or two to nail this?

What would you want to include that's beyond other derivative clustering frameworks?

JP

I've started merging the google clustering code into this swift example
https://github.com/johndpope/Blitz.app - DRAFTED

4693 tracks any changes needed for this feature in the Android SDK.

how to get zoom scale and width of visible view from mapbox

@maqen, if I’m not mistaken, MapKit’s MKZoomScale is more or less equivalent to the Mapbox iOS SDK’s zoomLevel property. (It might be off by one or something like that, but the conversion doesn’t depend on the view’s width.)

Is there an update on clustering for iOS?

@shfishburn we work on it actively now, with the intention of releasing it next month as a GL Native feature (available on both iOS and Android).

In 4 days (next month is 4 days away)? :)

@mourner Any update on when this month to expect the release?

@frankiecheung

via https://github.com/mapbox/mapbox-gl-native/issues/4693:

In absolute terms we are working on the Core GL work for this feature now, and you'll see the capability expose in the Next +1 Release: iOS 3.4/Android 4.2. We are targeting Q3 for this feature, so somewhere in the July/August timeframe.

A broader note on timing and release dates: we do not post a Release Date until we can be fairly confident of hitting it; this usually means that the release is fully scoped and the necessary research is completed. We've all been on the receiving end of delayed releases, so we're trying to avoid being overly optimistic. I appreciate that the other end of the spectrum is opacity, which is equally unhelpful, so I'll work more to give what guidance we can as soon as we can give it.

@twbell I'm puzzled by the delta between your dates and the comment from @mourner : "we work on it actively now, with the intention of releasing it next month as a GL Native feature (available on both iOS and Android)."

@shfishburn, https://github.com/mapbox/mapbox-gl-native/issues/320#issuecomment-219539291 is the plan of record as things stand. @mourner and others are working to port the Supercluster library to C++ as supercluster.hpp. From there, more work will be needed to integrate that library into mbgl core, then plumb that logic into the platform-specific SDKs. Indeed, the intention is to eventually make this functionality available on both iOS and Android, but it is not planned as part of the upcoming iOS SDK v3.3.0 and Android SDK v4.1.0 releases (hence the lack of a milestone on this issue).

@1ec5, when @mourner commented as he did, we modified our internal planning related. I reckon we should not have done that. :(

The clustering algorithm itself is already implemented (see https://github.com/mapbox/supercluster.hpp library). However I underestimated the time it would take to integrate it, add bindings for different platforms and make it a part of an official release in addition to many other priorities.

Great work, and great communication on this issue! I am building with the deprecated mapbox overlay renderer right now, on top of MapKit and an open-source grid clustering implementation. Not happy about overlay loading performance, but it's getting me by for now. It sounds like the Q3 timeline will be soon enough for me to swap this out for MapBox GL -- it's very helpful to know that now so I don't get tempted to mess around with other idea.

I _was_ thinking about decoupling the clustering from the map implementation -- basically computing an array of annotations that were already pre-clustered for the map zoom level. Then passing them in as annotations to MapBoxGL and letting it ask me for the images for each, which I would then render either as clusters or not. Not sure if this would have been that simple; I'm still tempted to try it as a stopgap.

Stay.com needs annotation clustering badly!

any updates on the implementation of clustering ?

@mourner Hows it going my friend? any news for us hopefuls?

The work is still going. Related prerequisite issues to track are:

Hey, please let us know even if it reaches the testing phase, I would like to test and help improve it as early as possible. So badly in need of clustering.
Thank you :)

Is this feature release close?

Noting here that discussions of clustering will have to separately consider annotation view structure as well on each platform, if we are also going to allow clustering there.

https://github.com/mapbox/mapbox-gl-native/pull/5724 was just merged to master. Which means you will now be able to add clustered GeoJSON sources and style them like on the GL JS example here.

To expand on @mourner’s much welcome update:

  • #5724 implements clustering for points in GeoJSON layers. If you’re unfamiliar with that terminology, that’s because historically GeoJSON layers have been immutable elements baked into the style and not accessible via the SDKs. In #5642 and #5642, we implemented a runtime styling API on Qt and Android, respectively, allowing you to manipulate and style GeoJSON layers (along with any layer of the map) on the fly. The same feature is coming to the iOS and macOS SDKs: #5626 #5727.
  • Most of the requests we’ve received for marker clustering have understandably been in relation to point annotations (known on Android as markers) rather than GeoJSON points. #5814 tracks adding APIs to cluster point annotations just as you can now cluster GeoJSON points.
  • The final step will be to extend point annotation clustering to view-backed point annotations (known on Android as marker views): #5815.

What about mapboxgl-js HTML markers and clustering?

Am 28.07.2016 um 06:43 schrieb Minh Nguyá»…n [email protected]:

To expand on @mourner https://github.com/mourner’s much welcome update:

5724 https://github.com/mapbox/mapbox-gl-native/pull/5724 implements clustering for points in GeoJSON layers. If you’re unfamiliar with that terminology, that’s because historically GeoJSON layers have been immutable elements baked into the style and not accessible via the SDKs. In #5642 https://github.com/mapbox/mapbox-gl-native/pull/5642 and #5642 https://github.com/mapbox/mapbox-gl-native/pull/5642, we implemented a runtime styling API on Qt and Android, respectively, allowing you to manipulate and style GeoJSON layers on the fly. The same feature is coming to the iOS and macOS SDKs: #5626 https://github.com/mapbox/mapbox-gl-native/issues/5626 #5727 https://github.com/mapbox/mapbox-gl-native/pull/5727.

Most of the requests we’ve received for marker clustering have understandably been in relation to point annotations (known on Android as markers) rather than GeoJSON points. #5814 https://github.com/mapbox/mapbox-gl-native/issues/5814 tracks adding APIs to cluster point annotations just as you can now cluster GeoJSON points.
The final step will be to extend point annotation clustering to view-backed annotations: #5815 https://github.com/mapbox/mapbox-gl-native/issues/5815.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-gl-native/issues/320#issuecomment-235799557, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQVtWg-BsHdteaSrPXN-hQugmkzUGVTks5qaDN3gaJpZM4CDZzA.

That's a good question. However, since this is the Mapbox GL Native repository, please request that feature in the GL JS repository. Thanks!

Just to give my 2 cents as I just switched my tile provider to Mapbox. But I'm still using osmdroid/osmbonuspack, mainly for markers clustering which is well implemented in it.

For me, key features are:

  • support of customized marker icon and customized cluster icon.
  • defining the minimum number of markers to cluster because clustering is not hidding markers; Without this, we will need to zoom in up to the highest level to explode just 2 close markers. default value of 5 is a good choice as GoogleMap API do.
  • overriding clusterization method because sometimes it's very cool to cluster all markers but one or two very important markers we don't want to cluster.

Any updates on clustering markers (annotations) using the SDKs?

Any updates on clustering markers (annotations) using the SDKs?

@o15a3d4l11s2, please subscribe to #5814. That issue will be updated as soon as there’s progress to report.

In the meantime, consider reimplementing your markers as a GeoJSON source styled with a symbol layer. GeoJSON sources can already be clustered, although you’ll have to implement interactivity manually. You may also want to keep track of #6181 and its dependent issues, which would hopefully eliminate that caveat.

support of customized marker icon and customized cluster icon

@2ndGAB, this should already be possible with the runtime styling API; see https://github.com/mapbox/mapbox-gl-native/issues/320#issuecomment-254066450. We don’t have a live native example online yet, but refer to this GL JS example for now. Now how the cluster-count layer can apply any symbol layer property.

defining the minimum number of markers to cluster because clustering is not hidding markers; Without this, we will need to zoom in up to the highest level to explode just 2 close markers. default value of 5 is a good choice as GoogleMap API do.

If this isn’t already supported for GeoJSON sources, please file a separate issue. The implementation may require some changes upstream in Supercluster.hpp and/or Supercluster.

overriding clusterization method because sometimes it's very cool to cluster all markers but one or two very important markers we don't want to cluster.

Similarly, this would be a great enhancement to request in a separate issue. Additional comments on this closed issue are less likely to be read by the project’s developers, and therefore less likely to be prioritized.

Any status on this?

Is this a low priority feature? Seems to me that everyone putting more than 20 markers on a map needs this.

To us it's a must have, and I'm surprised that anyone would consider this low priority. I guess there's other maplibs out there, but mapbox is usually soo good!

This missing is the only reason why I still keep using Google Maps for my app

@AAverin same here

I subscribed to this thread 2 years ago when I was considering to use Mapbox in my projects... After so much time I'm happy that I didn't waste my time with this SDK and I decided to use Google Maps. It's pathetic how something so important like this is still not implemented.

We decided to go with another map solution instead. Sad.

To clarify, recent comments are asking about view-backed annotation clustering? Because per https://github.com/mapbox/mapbox-gl-native/issues/320#issuecomment-235799557 we have had GL-backed clustering for some time now (API). I'll look into adding an example of the latter to our gallery.

Re: addressing the core need of marker-backed clustering, the main holdup is https://github.com/mapbox/mapbox-gl-native/issues/6181 and all of its associated dependency work. This would move the MapKit-like annotation model to be a thin implementation layer on top of Mapbox's unique GL-based runtime styling functionality (which you can't get in other toolkits). Per @1ec5 in that ticket:

Developers should be able to think of the annotation API as nothing more than a shortcut for runtime styling functionality, rather than an entirely separate code path.

We originally implemented annotations for parity with Apple and Google tools and because it's what people would expect, but where we've taken runtime styling and our open styling spec brings capabilities far beyond these. Developers no longer have to think about maps as just your own data on top of an opaque map, but rather can mix your data _into_ the map in a much more immersive way.

As a result of this a) early annotation parity for familiarity and b) the substantial backlog of things we need to do to bring the two APIs together, this has been taking a while.

Our examples repo will be updated soon with a comprehensive runtime styling example that shows how to cluster and visualize GeoJSON data (GL-backed clustering). In the meantime, here is a gist that ports the GL JS heatmap example that uses clustering to iOS.

To reiterate, anyone interested in clustering annotations (as opposed to GeoJSON sources aka shape sources) should subscribe to #5814 and #5815.

Was this page helpful?
0 / 5 - 0 ratings