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

Restore Markers #433

Merged
merged 12 commits into from
Aug 28, 2017
Merged

Restore Markers #433

merged 12 commits into from
Aug 28, 2017

Conversation

sarahsnow1
Copy link
Member

@sarahsnow1 sarahsnow1 commented Aug 22, 2017

Overview

This PR uses SceneLoadListener to restore markers on scene updates, including scene updates which occur because of orientation changes. This code doesn't check sceneId in the listener callback because we always want to restore markers when the scene is ready after any update. It also doesn't check sceneError 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

  • Adds SceneLoadListener to MapzenMap
  • Adds restoration handling to MarkerManager
  • Updates MarkerOptions to include all BitmapMarker properties
  • Updates BitmapMarker to provide property getters
  • Migrates StyleStringGenerator and MarkerManager to be singletons
  • Updates and adds test coverage
  • Updates custom marker example in sample app to show marker restoration on scene load changes

Closes #348

Copy link
Member

@tallytalwar tallytalwar left a 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;


Copy link
Member

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.

Copy link
Member Author

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(),
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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);
Copy link
Member

@tallytalwar tallytalwar Aug 24, 2017

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.

Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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 {
Copy link
Member

@tallytalwar tallytalwar Aug 24, 2017

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

Copy link
Member Author

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(
Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member

@tallytalwar tallytalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tallytalwar tallytalwar merged commit e8948c9 into master Aug 28, 2017
@tallytalwar tallytalwar deleted the 348-restore-markers branch August 28, 2017 20:39
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

Successfully merging this pull request may close these issues.

None yet

2 participants