Comments (10)
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.
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.
libary ClusterItem where ?
http://www.chuanroi.net/
from android-maps-utils.
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.
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.
Pull request sent
from android-maps-utils.
onClusterItemRendered method gets called only when we zoom map .
from android-maps-utils.
Thanks for the pull requests, all. This is in 0.3.2
.
from android-maps-utils.
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.
@ericpanorel Thank you so much!!!!!
from android-maps-utils.
Related Issues (20)
- Add support for Advanced Markers HOT 1
- Ability to specify `anchor` marker option for `ClusterItem`
- Refdocs stuck at v3.4.0 HOT 3
- Change documentation link to GitHub page HOT 1
- Set documentation title as "android-maps-utils" HOT 1
- A lot of unnecessary warnings HOT 1
- Add StreetViewSource parameter to fetchStreetViewData HOT 2
- Remove outdated CHANGELOG.md file HOT 2
- Add kml layer in compose HOT 1
- Creating Kotlin demos for android-maps-utils
- Add Header Check to android-maps-utils
- Improve javadoc descriptions to marker clustering algorithms
- java.lang.IllegalArgumentException : Unmanaged descriptor HOT 3
- Android Map development encountered Google Map deadlock issue: HOT 3
- Incorrect operation of the marker information window HOT 3
- Multiple google api keys (MAPS_API_KEY) per Application HOT 1
- Odd cluster behavior during clustering HOT 1
- Add AdvancedMarkerManager Collection HOT 2
- setOnMarkerDragListener does not report marker drag event HOT 2
- Google Maps is not loading on Android 8 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-maps-utils.