-
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
Tangram 0.8.0-RC2 #428
Tangram 0.8.0-RC2 #428
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
import com.mapzen.android.core.MapzenManager; | ||
import com.mapzen.android.graphics.model.BubbleWrapStyle; | ||
import com.mapzen.android.graphics.model.MapStyle; | ||
import com.mapzen.android.graphics.model.MarkerManager; | ||
import com.mapzen.tangram.MapController; | ||
import com.mapzen.tangram.SceneError; | ||
import com.mapzen.tangram.SceneUpdate; | ||
|
||
import android.content.Context; | ||
|
@@ -31,6 +31,8 @@ public class MapInitializer { | |
|
||
private Locale locale = Locale.getDefault(); | ||
|
||
MapReadyInitializer mapReadyInitializer; | ||
|
||
/** | ||
* Creates a new instance. | ||
*/ | ||
|
@@ -42,6 +44,7 @@ public class MapInitializer { | |
this.mapDataManager = mapDataManager; | ||
this.mapStateManager = mapStateManager; | ||
this.sceneUpdateManager = sceneUpdateManager; | ||
mapReadyInitializer = new MapReadyInitializer(); | ||
} | ||
|
||
/** | ||
|
@@ -71,10 +74,6 @@ public void init(final MapView mapView, MapStyle mapStyle, Locale locale, | |
loadMap(mapView, mapStyle, true, callback); | ||
} | ||
|
||
private TangramMapView getTangramView(final MapView mapView) { | ||
return mapView.getTangramMapView(); | ||
} | ||
|
||
private void loadMap(final MapView mapView, MapStyle mapStyle, boolean styleExplicitlySet, | ||
final OnMapReadyCallback callback) { | ||
if (mapStateManager.getPersistMapState() && !styleExplicitlySet) { | ||
|
@@ -90,15 +89,13 @@ private void loadMap(final MapView mapView, String sceneFile, final OnMapReadyCa | |
final List<SceneUpdate> sceneUpdates = sceneUpdateManager.getUpdatesFor(apiKey, locale, | ||
mapStateManager.isTransitOverlayEnabled(), mapStateManager.isBikeOverlayEnabled(), | ||
mapStateManager.isPathOverlayEnabled()); | ||
getTangramView(mapView).getMapAsync(new com.mapzen.tangram.MapView.OnMapReadyCallback() { | ||
@Override public void onMapReady(MapController mapController) { | ||
mapController.setHttpHandler(mapzenMapHttpHandler.httpHandler()); | ||
MapzenManager mapzenManager = MapzenManager.instance(mapView.getContext()); | ||
callback.onMapReady( | ||
new MapzenMap(mapView, mapController, new OverlayManager(mapView, mapController, | ||
mapDataManager, mapStateManager), mapStateManager, new LabelPickHandler(mapView), | ||
new MarkerManager(mapController), sceneUpdateManager, locale, mapzenManager)); | ||
MapController controller = mapView.getTangramMapView().getMap( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify this But this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I set the
Does this reasoning make sense, are there things I'm not considering properly? On a related note, I was planning on setting a |
||
new MapController.SceneLoadListener() { | ||
@Override public void onSceneReady(int sceneId, SceneError sceneError) { | ||
mapReadyInitializer.onMapReady(mapView, mapzenMapHttpHandler, callback, mapDataManager, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably make sense to use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of the way our APIs are setup I don't think this is needed. The flow the user goes through is either:
We wrap all calls to |
||
mapStateManager, sceneUpdateManager, locale); | ||
} | ||
}, sceneFile, sceneUpdates); | ||
}); | ||
controller.loadSceneFileAsync(sceneFile, sceneUpdates); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.mapzen.android.graphics; | ||
|
||
import com.mapzen.android.core.MapzenManager; | ||
import com.mapzen.android.graphics.model.MarkerManager; | ||
import com.mapzen.tangram.MapController; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Class to handle creating a {@link MapzenMap} and invoking {@link OnMapReadyCallback}. | ||
*/ | ||
class MapReadyInitializer { | ||
|
||
/** | ||
* Creates a {@link MapzenMap} configured using the provided parameters and invokes the | ||
* {@link OnMapReadyCallback} with this new map. | ||
* @param mapView | ||
* @param mapzenMapHttpHandler | ||
* @param callback | ||
* @param mapDataManager | ||
* @param mapStateManager | ||
* @param sceneUpdateManager | ||
* @param locale | ||
*/ | ||
void onMapReady(MapView mapView, MapzenMapHttpHandler mapzenMapHttpHandler, | ||
OnMapReadyCallback callback, MapDataManager mapDataManager, MapStateManager mapStateManager, | ||
SceneUpdateManager sceneUpdateManager, Locale locale) { | ||
MapController mapController = mapView.getTangramMapView().getMap(null); | ||
mapController.setSceneLoadListener(null); | ||
mapController.setHttpHandler(mapzenMapHttpHandler.httpHandler()); | ||
MapzenManager mapzenManager = MapzenManager.instance(mapView.getContext()); | ||
callback.onMapReady( | ||
new MapzenMap(mapView, mapController, new OverlayManager(mapView, mapController, | ||
mapDataManager, mapStateManager), mapStateManager, new LabelPickHandler(mapView), | ||
new MarkerManager(mapController), sceneUpdateManager, locale, mapzenManager)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.mapzen.android.graphics; | ||
|
||
import com.mapzen.tangram.HttpHandler; | ||
import com.mapzen.tangram.MapController; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import android.content.Context; | ||
|
||
import java.util.Locale; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PowerMockIgnore("javax.net.ssl.*") | ||
@SuppressStaticInitializationFor("com.mapzen.tangram.MapController") | ||
public class MapReadyInitializerTest { | ||
|
||
MapReadyInitializer initializer = new MapReadyInitializer(); | ||
|
||
@Test public void onMapReady_shouldSetMapControllerSceneLoadListenerNull() throws Exception { | ||
MapView mapView = mock(MapView.class); | ||
Context context = mock(Context.class); | ||
when(mapView.getContext()).thenReturn(context); | ||
when(context.getApplicationContext()).thenReturn(mock(Context.class)); | ||
TangramMapView tangramMapView = mock(TangramMapView.class); | ||
MapController mapController = mock(MapController.class); | ||
when(mapView.getTangramMapView()).thenReturn(tangramMapView); | ||
when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( | ||
mapController); | ||
initializer.onMapReady(mapView, mock(MapzenMapHttpHandler.class), | ||
mock(OnMapReadyCallback.class), mock(MapDataManager.class), mock(MapStateManager.class), | ||
mock(SceneUpdateManager.class), new Locale("en_us")); | ||
verify(mapController).setSceneLoadListener(null); | ||
} | ||
|
||
@Test public void onMapReady_shouldSetMapControllerHttpHandler() throws Exception { | ||
MapView mapView = mock(MapView.class); | ||
Context context = mock(Context.class); | ||
when(mapView.getContext()).thenReturn(context); | ||
when(context.getApplicationContext()).thenReturn(mock(Context.class)); | ||
TangramMapView tangramMapView = mock(TangramMapView.class); | ||
MapController mapController = mock(MapController.class); | ||
when(mapView.getTangramMapView()).thenReturn(tangramMapView); | ||
when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( | ||
mapController); | ||
MapzenMapHttpHandler mapzenHttpHandler = mock(MapzenMapHttpHandler.class); | ||
HttpHandler httpHandler = mock(HttpHandler.class); | ||
when(mapzenHttpHandler.httpHandler()).thenReturn(httpHandler); | ||
initializer.onMapReady(mapView, mapzenHttpHandler, | ||
mock(OnMapReadyCallback.class), mock(MapDataManager.class), mock(MapStateManager.class), | ||
mock(SceneUpdateManager.class), new Locale("en_us")); | ||
verify(mapController).setHttpHandler(httpHandler); | ||
} | ||
|
||
@Test public void onMapReady_shouldCallOnMapReady() throws Exception { | ||
MapView mapView = mock(MapView.class); | ||
Context context = mock(Context.class); | ||
when(mapView.getContext()).thenReturn(context); | ||
when(context.getApplicationContext()).thenReturn(mock(Context.class)); | ||
TangramMapView tangramMapView = mock(TangramMapView.class); | ||
MapController mapController = mock(MapController.class); | ||
when(mapView.getTangramMapView()).thenReturn(tangramMapView); | ||
when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( | ||
mapController); | ||
OnMapReadyCallback callback = mock(OnMapReadyCallback.class); | ||
initializer.onMapReady(mapView, mock(MapzenMapHttpHandler.class), | ||
callback, mock(MapDataManager.class), mock(MapStateManager.class), | ||
mock(SceneUpdateManager.class), new Locale("en_us")); | ||
verify(callback).onMapReady(any(MapzenMap.class)); | ||
} | ||
} |
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.
Not part of this PR, but does it make sense to provide a
isBuildingExtrude
option tomapStateManager
. Our house style offers options to control this.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'm glad you brought this up and think it would be nice to provide more global options like this. Created tickets in the iOS and Android SDKs for future work to complete this
#431
mapzen/ios#355