-
Notifications
You must be signed in to change notification settings - Fork 66
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
Restore Markers #433
Restore Markers #433
Conversation
… restoration after orientation change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good.
@sarahlensing can you clarify few naming and some design decisions, I pointed in the comments below.
Thanks
@@ -5,6 +5,7 @@ | |||
|
|||
import android.graphics.drawable.Drawable; | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this class only used for BitmapMarkers
or also for Markers
(backed by MapData
)? If so, we should clarify the naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to BitmapMarkerOptions
and deprecated MarkerOptions
!
return new BitmapMarker(this, marker, styleStringGenerator); | ||
BitmapMarker bitmapMarker = bitmapMarkerFactory.createMarker(this, marker, | ||
styleStringGenerator); | ||
configureMarker(bitmapMarker, markerOptions.getPosition(), markerOptions.getIconDrawable(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing every property, can we not pass the markerOptions explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use this method in two places- here when adding markers given MarkerOptions
and then when restoring markers when I don't have options but instead only the BitmapMarker
which is why I don't have it taking the MarkerOptions
explicitly. I'll create a couple convenience methods on top of this one to handle configuring a marker given just the MarkerOptions
and have it call through to this one. How does that sound? I could keep a mapping of MarkerOptions
-> BitmapMarker
and then have just one method to configure a marker but I'd prefer not to store this info if I can get away with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that sounds fine to me.
markerOptions.getHeight(), markerOptions.isInteractive(), markerOptions.getColorHex(), | ||
markerOptions.getColorInt(), markerOptions.isVisible(), markerOptions.getDrawOrder(), | ||
markerOptions.getUserData()); | ||
restorableMarkers.add(bitmapMarker); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be missing something here, but this should be synchronized right? As in when a new scene is loaded its listener should have have a synchronized set of markers to be restored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Updated to use Collections.synchronizedList(restorableMarkers)
/** | ||
* Creates {@link BitmapMarker} objects. | ||
*/ | ||
public class BitmapMarkerFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might not be following the usage of the Factory here, but could this functionality not make sense in MarkerManager
itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It definitely could be within MarkerManager
but the reason I pulled it out was to make testing easier. If I have a separate object in charge of creating the markers that I inject into BitmapMarkerFactory
, I can easily have this factory object generate mocks and make assertions on them when testing:
https://github.com/mapzen/android/pull/433/files#diff-f00bf2e8f7b3f14b7d6bc8fbf88ddabfR40
https://github.com/mapzen/android/pull/433/files#diff-f00bf2e8f7b3f14b7d6bc8fbf88ddabfR57
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh yes definitely makes sense. 👍
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Manages {@link BitmapMarker} instances on the map. | ||
*/ | ||
public class MarkerManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always get confused with this Marker
name usage. I know its because of
multiple reasons including compatibility with how Marker
->MapData
usage was and how BitmapMarker
->Tangram::Marker
usage is. But can we try to keep the naming such that it distinguishes between sdk markers (tangram mapdata) and sdk bitmapmarkers (tangram markers)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, the naming is not ideal. I'll update to BitmapMarkerManager
for clarity
* Returns the object used to manager markers. | ||
* {@link com.mapzen.tangram.Marker}. | ||
*/ | ||
@Provides @Singleton public MarkerManager providesMarkerManager( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does android sdk support multiple map instances (tangram android does!), if so does it make sense to not make MarkerManager
singleton? Or will every map instance gets its own MarkerManager
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SDK doesn't support map instances, this is something I've had floating around in my head as a TODO. I created a ticket for it and will add support in a future PR #436
markerOptions.getHeight(), markerOptions.isInteractive(), markerOptions.getColorHex(), | ||
markerOptions.getColorInt(), markerOptions.isVisible(), markerOptions.getDrawOrder(), | ||
markerOptions.getUserData()); | ||
configureMarker(bitmapMarker, markerOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah overloading this makes it more cleaner to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Overview
This PR uses
SceneLoadListener
to restore markers on scene updates, including scene updates which occur because of orientation changes. This code doesn't checksceneId
in the listener callback because we always want to restore markers when the scene is ready after any update. It also doesn't checksceneError
because the sdk doesn't have first class support for loading custom scenes and ensures that all house styles work with the apis we provide.Proposed Changes
SceneLoadListener
toMapzenMap
MarkerManager
MarkerOptions
to include allBitmapMarker
propertiesBitmapMarker
to provide property gettersStyleStringGenerator
andMarkerManager
to be singletonsCloses #348