Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Factory.createMarker parameters #9

Open
marcelpinto opened this issue Sep 19, 2017 · 0 comments
Open

Reduce Factory.createMarker parameters #9

marcelpinto opened this issue Sep 19, 2017 · 0 comments

Comments

@marcelpinto
Copy link

Hi,

In general, the library is pretty simple to use but there are few parts that might be confusing.

onCreateAnnotation should use the factory to create the marker and then onBindAnnotation should actually set up the marker attributes, the way is implemented feels you have to do it onCreatAnnotation since the factory requires position, bitmap and title but also during onBindAnnotation so feels like duplicating the job.

My suggestion would be that the factory only requires a position, so the MapAnnotation constructor. Then on the create Annotation you only make sure to create the marker on the position and during onBindAnnotation you set the attrs.

interface AnnotationFactory<in Map> {
    fun createMarker(latLng: LatLng): MarkerAnnotation
    ...
}

abstract class MarkerAnnotation(latLng: LatLng) : MapAnnotation() {
...
}

// MyAdapter...
override fun onBindAnnotation(annotation: MapAnnotation, position: Int, payload: Any?) {
    // Set the attributes to the annotation
}

override fun onCreateAnnotation(factory: AnnotationFactory, position: Int, annotationType: Int): MapAnnotation {
    val item = this.markers[position]
    return factory.createMarker(LatLng(item.latitude, item.longitude)
}
marcelpinto pushed a commit to marcelpinto/MapMe that referenced this issue Sep 19, 2017
Only accept the position of the marker so the onCreateAnnotation is
clearer and does not duplicate the work that should be done in
onBindAnnotation. That simplifies the adapter and avoid possible
duplication of work and resources.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant