Giter Site home page Giter Site logo

Comments (10)

ericpanorel avatar ericpanorel commented on May 17, 2024 7

To track any data associated with the marker, it is best to create a hashmap of marker ID vs. you data model, the best place to implement this is also in the renderer class by implementing the method:

@Override
protected void onClusterItemRendered(Person person, Marker marker) {
    super.onClusterItemRendered(person, marker);
    markerPersonMap.put(marker.getId(), person);
}

When implementing the method, onBeforeClusterItemRendered, you have MarkerOptions object passed in as the second parameter. You can then modify it from there.

markerOptions.title("Blah")
                      .snippet("some property from the first parameter object...")
                     .flat(true);

and finally, on your onInfoWindowClick method, you can access your object (ClusterItem) by doing

    @Override
    public void onInfoWindowClick(Marker marker) {
         final Person thePersonOnThisMarker = markerPersonMap.get(marker.getId());
         // do something with this person/ClusterItem associated with this marker / markerInfoWindow
    }

from android-maps-utils.

AntonioGonzalez avatar AntonioGonzalez commented on May 17, 2024 2

First thanks, but I need to resolve some questions:

1.- Why is better to create a hashmap if inside library there are two structures which have those data, why don't reuse them to get info? The way you commented resolves just one question: given a marker -> get their data, but what will happen when you need a marker from data? I know I can create another hashmap inverse, but I don't know if it is a good idea repeat the same structure than library has.

2.- Yes, I can manage some information about marker in onBeforeClusterItemRendered like snippet, title, etc but I need to call showInfoWindow method from a marker in a determinate time, so I need to get a marker from cluster data.

By the way, crash report was because of sometimes I called showInfoWindow from marker when zoom could had changed and marker didn't exist. I resolved that and now all is working but I would like to know why is bad idea (may be not) giving two method to DefaultClusterRenderer class:

protected Marker getMarker(T item) {
return mMarkerCache.get(item);
}

protected T getCluster(Marker marker) {
return mMarkerCache.get(marker);
}

from android-maps-utils.

at-anhtt avatar at-anhtt commented on May 17, 2024 2

libary ClusterItem where ?
http://www.chuanroi.net/

from android-maps-utils.

ericpanorel avatar ericpanorel commented on May 17, 2024

I agree with you. Inside the static class MarkerCache, there is already a mCacheReverse that stores this 'map'. I'm assuming this is what you're trying to expose with your methods above. I am not yet clear on the entire architecture of this library though, so I cannot comment whether this is OK or not. It seems like they used the variable mMarkerCache to manage markers that are added/removed when needed (i.e. zoom, after animation, etc...) . The removeMarker method, is even marked private .... So maybe as long as you check if the marker is still there or not ....

from android-maps-utils.

broady avatar broady commented on May 17, 2024

This is a good point - I think initial design concerns were misguided - the clusterer has no concept of markers intentionally. I can see that has hampered usability.

The idea to add those protected methods sounds good to me.

Would you like to send a pull request to expose those?

from android-maps-utils.

AntonioGonzalez avatar AntonioGonzalez commented on May 17, 2024

Pull request sent

from android-maps-utils.

JithinSunny avatar JithinSunny commented on May 17, 2024

onClusterItemRendered method gets called only when we zoom map .

from android-maps-utils.

broady avatar broady commented on May 17, 2024

Thanks for the pull requests, all. This is in 0.3.2.

from android-maps-utils.

jeffdgr8 avatar jeffdgr8 commented on May 17, 2024

Oh yes, making these maps publicly accessible to get ClusterItem for Marker is a must! This helped me find that mapping in the DefaultClusterRenderer though.

How else would you be able to update a ClusterItem's position when dragged for example? You only have the Marker in the OnMarkerDragListener. The problem with rolling your own map, besides duplicating an already present and managed cache, is that Markers are never removed from your map when they're removed from the cluster renderer! So this would surely leak memory.

from android-maps-utils.

bosung90 avatar bosung90 commented on May 17, 2024

@ericpanorel Thank you so much!!!!!

from android-maps-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.