git-printa / osmbonuspack

Automatically exported from code.google.com/p/osmbonuspack
0 stars 0 forks source link

Get visible items of a cluster #110

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have a problem to show markers on map. When two or more marker are overlapped 
then the cluster won't open. I solved it with deleting the cluster from 
overlays and adding all Markers again separately. But I want get a list of 
visible items in a cluster by clicking on it.
Assume we have 20 markers in a cluster and in a zoom level only 4 items are 
available (Showing a circle with number 4). now I want to get these for makers 
with click on cluster marker.

Thanks.

Original issue reported on code.google.com by hr.saleh...@gmail.com on 4 Feb 2015 at 11:37

GoogleCodeExporter commented 8 years ago
Interesting point. Let's go a little bit deeper in the specification of this 
request. 

Effectively, when using the default marker clusterer, clicking on a cluster 
marker is not opening any InfoWindow. 

You would like to have an InfoWindow opening. Key question is: what do you want 
to display in this InfoWindow? I easily guess the answer: the title + 
description of all markers contained in the cluster. 

Now the issues:
1) What should we do if the cluster has - let say - 200 markers? 
2) What should we do if markers InfoWindows have been customized, and contain: 
an image; a sub-description; a "more info" button; a "delete" button, etc ... 

What I can suggest: you can customize the RadiusMarkerClusterer by sub-classing 
it, so that it opens an InfoWindow matching your need. You can for instance 
override buildClusterMarker to call marker.setInfoWindow

If you think your customization is generic, then you can propose it here 
(attaching the source file to the issue). 

Alternate solution to this issue could be to implement an "Explode" mechanism, 
as described here: https://groups.google.com/forum/#!topic/osmdroid/tvpFEuzE3yY

Original comment by mathieu....@gmail.com on 4 Feb 2015 at 12:46

GoogleCodeExporter commented 8 years ago
I don't think showing an info windows is a problem. The first problem is 
getting a list of clustered visible Markers objects.
Something like : ArrayList<Marker> visibleItems ...

By the way I'm using GridMarkerClusterer for clustering markers.What is the 
difference with RadiusMarkerClusterer? I can't find it's class

Original comment by hr.saleh...@gmail.com on 4 Feb 2015 at 12:55

GoogleCodeExporter commented 8 years ago
"The first problem is getting a list of clustered visible Markers objects"
=> sorry, I don't understand at all. If they are clustered, then they should 
not be visible, this is the basic idea of clustering. What do you want 
PRECISELY when clicking on a cluster marker? 

RadiusMarkerClusterer has been added in v5.1. Similar to GridMarkerClusterer, 
but much better clustering algorithm. 

Original comment by mathieu....@gmail.com on 4 Feb 2015 at 5:09

GoogleCodeExporter commented 8 years ago
I explain again.
Assume you added about 30 marker into a cluster (RadiusMarkerClusterer) and 
then you added that cluster to your map overlays. 
When the map loaded in minimum zoom you can see a number 30 on a single marker 
that formed a cluster. By zooming in the cluster breaks into more than one 
marker and you can see some markers with different numbers on them (sum of all 
is 30). 
Something like you have 4 marker with 9,11,4,6 marker in each of them. 
Now I want get list of markers in every visible node bu clicking on them.
For example if I clicked on marker with 4 single markers in it I should get an 
ArrayList of those nodes. And it's obvious that all markers are clustered 
together in a RadiusMarkerClusterer.

I think I explained better this time.

Original comment by hr.saleh...@gmail.com on 6 Feb 2015 at 9:02

GoogleCodeExporter commented 8 years ago
It's still unclear for me what you will do with this ArrayList of nodes, but 
anyway:

Sub-class RadiusMarkerClusterer, and override buildClusterMarker:

@Override public Marker buildClusterMarker(StaticCluster cluster, MapView 
mapView){
  Marker m = super.buildClusterMarker(cluster, mapView);
  m.setRelatedObject(cluster);
  return m;
}

Now your cluster marker has a handle to the StaticCluster. 
And your "ArrayList<Marker>" of nodes is inside this "StaticCluster cluster" 
parameter: it is the mItems attribute. 

Hope it helps. 

Original comment by mathieu....@gmail.com on 6 Feb 2015 at 4:17

GoogleCodeExporter commented 8 years ago
Thank you very much. I'll try that and let you know

Original comment by hr.saleh...@gmail.com on 7 Feb 2015 at 7:36

GoogleCodeExporter commented 8 years ago
I looked into your suggested solution but I had some problems :
1- The StaticCluster doesn't have any method or way to get "Items". Onlya 
getItem(int index) method to get a specific item.
2. the clsuter have a getSize() method that return the size of it and in every 
zoom level or visible area with any number of visible markers returns the same 
number every time (2 in my example).

        @Override
    public boolean onSingleTapUp(MotionEvent e, MapView mapView) {

        if (mapView.getZoomLevel() >= 15 && cluster != null) {
            Toast.makeText(context, "size : " + cluster.getSize(),       Toast.LENGTH_SHORT).show();            
        }
        return super.onSingleTapUp(e, mapView);
    }

    @Override
    public Marker buildClusterMarker(StaticCluster cluster, MapView mapView) {
        marker = super.buildClusterMarker(cluster, mapView);
        marker.setRelatedObject(cluster);
        this.cluster = cluster;
        return marker;
    }
=============
In your first response you get the point correctly. I have some places that 
overlap on each other. I set the maximum level of my cluster equal to my 
maximum zoom level to break the cluster into separate nodes in the last zoom 
level. But steel only one marker can be touched by the user. 
I want to have maintain my cluster to show the the number of items in last zoom 
level (for example 3 overlapped items) and by clicking on that a list of 
overlapped markers appear on screen or an activity with a list of those items 
be launched.

Original comment by hr.saleh...@gmail.com on 7 Feb 2015 at 11:46

GoogleCodeExporter commented 8 years ago
StaticCluster has getSize method to get the number of items in this 
StaticCluster, and getItem method to get an item. 

In your code: 

public boolean onSingleTapUp(MotionEvent e, MapView mapView) {
        if (mapView.getZoomLevel() >= 15 && cluster != null) {
            Toast.makeText(context, "size : " + cluster.getSize(),       Toast.LENGTH_SHORT).show();            
        }
        return super.onSingleTapUp(e, mapView);
    }

=> Where this "cluster" variable is defined?

Original comment by mathieu....@gmail.com on 13 Feb 2015 at 1:09

GoogleCodeExporter commented 8 years ago
the "cluster" variable is defined as a class variable or globally. as you see 
in the "builClusterMaker" method the static cluster get it's value and in 
"onSingleTapUp" method I used the value of the variable.

Original comment by hr.saleh...@gmail.com on 13 Feb 2015 at 4:10

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
"the "cluster" variable is defined as a class variable or globally"
=> as the RadiusMarkerClusterer contains more than 1 cluster, this is the root 
cause of your bug. 

Original comment by mathieu....@gmail.com on 13 Feb 2015 at 5:30

GoogleCodeExporter commented 8 years ago
Thank I will test It.
But the main problem still exist. There is not any method to get all items in a 
static cluster. The "getItem" method returns only one object that equals with 
the input and at that moment (in "onSingleTapUp" method) I don't have access to 
those objects. 
Do you suggest any solution for this?

Original comment by hr.saleh...@gmail.com on 14 Feb 2015 at 7:05

GoogleCodeExporter commented 8 years ago
Overriding RadiusMarkerClusterer.onSingleTapUp is not an appropriate solution. 
Again, RadiusMarkerClusterer contains more than 1 StaticCluster, you don't know 
at this level which StaticCluster has been taped-up. 
And you don't care, as the selection of the appropriate StaticCluster is 
already implemented. 

What you have to do is implement a customized InfoWindow class matching your 
need. For instance opening a bubble listing the names of clustered markers. 
Then you will pass this InfoWindow to your cluster Markers: 

@Override public Marker buildClusterMarker(StaticCluster cluster, MapView 
mapView){
  Marker m = super.buildClusterMarker(cluster, mapView);
  m.setRelatedObject(cluster);
  m.setInfoWindow(new ClusterInfoWindow(mapView);
  return m;
}

For that, first of all, follow Tutorial: "7. Customizing the bubble behaviour"
here: https://code.google.com/p/osmbonuspack/wiki/Tutorial_2

Original comment by mathieu....@gmail.com on 14 Feb 2015 at 1:39

GoogleCodeExporter commented 8 years ago
Thanks I will look into It

Original comment by hr.saleh...@gmail.com on 14 Feb 2015 at 4:10