Topic: A way to implement clustering?

Hello,

Is there a built in way to handle clustering of markers or some example to do that?



example:
http://www.imapbuilder.net/images/guide … ve-map.jpg

Re: A way to implement clustering?

Hello.

http://infinity-code.com/atlas/online-m … ample.html

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

Thanks!

Re: A way to implement clustering?

Hey,

Can you please comment out how the script work in a little more detail if possible? I would really appreciate that (I did modify it a bit to work with 3d markers).

Re: A way to implement clustering?

Hello.

This script calculates the distance between the markers in the tile coordinates, and if the distance is less than the specified value, limit zoom range of the markers, and creates a new grouping marker.

Actually, in a nearby thread, I have already made it for 3D markers:
http://forum.infinity-code.com/viewtopic.php?id=394

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

Thanks for the script, but I did get it clustering to work perfectly, as you discussed in that thread that just clustering will not improve performance (I will have 50k or so marker which will go up)
I am trying to implement what you did in million marker script, and add clustering as well. so basically it will only create the markers which lie within the boundary of the map add them to a list and the run the clustering function. Instead of a for loop for all zoom levels, I am just assigning the current zoom.
This whole things runs again as I have assigned it to onlineMap.OnchangePosition Delegate. Also I am deleting all the markers at the start in the marker list each time player moves the map, so that way I don't any inactive marker in the scene.
Although my concern is it will be too much calculations and will lag the map a bit, I haven't tested it yet, so if you have any suggestions please feel free to tell me.

7 (edited by Mridul 2017-02-07 01:18:14)

Re: A way to implement clustering?

After trying it out for a bit I couldn't really get it to work the way I would want to. I have both clustering and creating markers(like in your oneMillionMarker script) working separately, I couldn't get them to work in junction with each other. 

this is how I am handelling the creation of markers

    public void BeginCreatingPlayers()
    {   
        Lat = DBS.latitude;        // I am getting these values from the sever and I update this list every 2 mins
        Lng = DBS.longitude;
        PlayerName = DBS.playerNames;
        OM.OnChangePosition += CreatePlayers;
        OM.OnChangeZoom += CreatePlayers;


    }


    private void CreatePlayers ()
    {

        
  

        if (OM.zoom > 4) {

 
            double tlx, tly, brx, bry;   // top left longitude = tlx ; x - longitude , y - latitude
            OM.GetTopLeftPosition (out tlx, out tly);
            OM.GetBottomRightPosition (out brx, out bry);
            var lng = new List<float> ();
            var lat = new List<float> ();
            var playerName = new List<string> ();
            OnlineMapsMarker3D player;

            for (int i = 0; i < Lat.Count; i++) { 

                if (Lng [i] >= tlx && Lng [i] <= brx && Lat [i] >= bry && Lat [i] <= tly) {
                    Vector2 markerPosition = new Vector2 (Lng [i], Lat [i]);


                    // Assign PlayerIcon
//            
                                player = control.AddMarker3D (markerPosition, playerIcon);
                    
                        player.scale = playerIconScale;
                    //  player.range = new OnlineMapsRange (5, 20);
                        var pData = player.instance.GetComponent<playerData> ();
                        pData.playerName = PlayerName [i];
                        pData.gender = genderValue;
                        


                        lng.Add (Lng [i]);
                        lat.Add (Lat [i]);
                        playerName.Add (PlayerName [i]);
                       

                }
            }

                        foreach (float f in lng) {
                            Lng.Remove (f);
                        }
                        foreach (float f in lat) {
                            Lat.Remove (f);
                        }
                        foreach (string s in playerName) {
                            PlayerName.Remove (s);
                        }

       

        }
    }

Re: A way to implement clustering?

Use these two scripts together is a bad idea.

I have an idea how to implement it using trees.
But it takes time to develop and test (I think 1-2 days).
I'll send you the script, when it will be ready.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

Thanks a lot, really appreciate it.

Re: A way to implement clustering?

Hello.

Saying 1-2 days, I was too optimistic.
It was much harder than I thought.

The script is attached. I hope it will work well.

Post's attachments

Attachment icon Clustering3DMarkers.cs 10.21 kb, 58 downloads since 2017-02-13 

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

Thanks a lot man! I will give it a go, again really appreciate it!

Re: A way to implement clustering?

It works perfectly. In my project I was using a bit older version on online maps as I want to use the cartoDB > dark matter map, and in the newer updates that map does not work. But you script required for me to update the plugin, could you please tell me why that particular one and a few other maps stop working for me when I update the plugin?

Also, as for the script, I am going to be fetching the position of the players every few minutes or so from the server, so how should I update all these generated markers?I am guessing remove on change position delegate, remove all the markers, update the list, and rerun the start function?

Thanks for all your help.

Re: A way to implement clustering?

I improved this script and adds the ability to remove markers and change the position of the markers.
But it takes some time for testing and fixing bugs.
I'll send you the script and an example of using when it will be ready.

Thank you for writing about CartoDB. Fixed. In the next version it will work correctly.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

Thanks!

Re: A way to implement clustering?

Currently too early to thanks, because I have not yet finished it.
The script has a bug that just blows my mind.
I can not find this a few days, and frankly starting to lose patience.
I hope that I can find and fix the bug, because I already spent on this script too much time.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

I see, I do really appreciate you putting all that effort into into, in the end if you think its not possible feel free to drop it, I will do away without clustering and just load the markers like you you did the 1 million marker one. I currently am fetching the coordinate list from the server and updating the markers, but so far I was just testing it will only 1k markers on server since I was waiting for your response before dumping all the 30k or so markers on the server. I will go ahead and do it now and see its performance on my mobile and I might circle back to you if there are any major performance hits.
Again thanks for all the help.

Re: A way to implement clustering?

Hello.

I haven't forgotten about your thread.
Scripts is attached.
I hope it will work well.

P.S. In search of this bug, I almost lost faith in mathematics, and it was a good challenge for my knowledge and patience.

Post's attachments

Attachment icon Clustering3DMarkers.cs 19.68 kb, 52 downloads since 2017-03-01 

Attachment icon TestClustering.cs 1.65 kb, 62 downloads since 2017-03-01 

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

Thanks a lot, I thought you gave up on it thats why didnt check on it, I will try it out and get back to you!

Re: A way to implement clustering?

Hello,

Right now its only clustering the markers I add through :

 Clustering3DMarkers.Add(markerDot); 

And all the other Icons are just not showing up, is there a way to fix that? I need to cluster only a few kinds of icons which I am adding to the cluster script rest I want visible as is, is there any work around this?

Also is it at all possible to limit the clustering till a certain zoom level, eg : it will only cluster till zoom 16

Thanks.

Re: A way to implement clustering?

Hello.

I added the ability to create unclustered markers.
Use Clustering3DMarkers.AddUnclustered.
Updated script is attached.

Post's attachments

Attachment icon Clustering3DMarkers.cs 20.17 kb, 51 downloads since 2017-06-16 

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

Thanks a lot man! I will try it out right away, just one more thing about limiting the clustering to a zoom level lets cluster upto 15 zoom level? or maybe change the value for threshold of clustering for eg only cluster the marker within a certain distance?

Our game displays different 'players' playing the game around you as markers which you can tap on and perform certain actions, right now its basically clustering a little too much, since you have to zoom real close to a player to see the actual marker not the clustered one.

Really appreciate all the help.

Cheers,
Mridul

Re: A way to implement clustering?

OK. I added a field "clusterToZoom", which allows you to limit clustering.

Post's attachments

Attachment icon Clustering3DMarkers.cs 20.29 kb, 60 downloads since 2017-06-16 

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: A way to implement clustering?

Thanks!

24 (edited by Mridul 2017-06-16 02:59:37)

Re: A way to implement clustering?

Hey,

It works perfectly and super fast, thank you so much.

just have to ask one thing if it can be possible without too much trouble, the clusters appear as grid and do not look good, basically one of them is in a middle of an oceans where there are no players.

Cluster Grid


Link of screen cap video, if that helps : https://www.dropbox.com/s/onykmwe9a1uwp … t.mp4?dl=0


Cheers,
Mridul

Re: A way to implement clustering?

Updated script is attached.

After generating the markers you need to invoke:
Clustering3DMarkers.UpdatePositions();

Post's attachments

Attachment icon Clustering3DMarkers.cs 20.7 kb, 60 downloads since 2017-06-18 

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!