Skip to content

Reduce Factory.createMarker parameters  #9

Description

@marcelpinto

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)
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions