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

Refill Themes #447

Merged
merged 14 commits into from
Sep 13, 2017
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "core/src/main/assets/styles/bubble-wrap"]
path = core/src/main/assets/styles/bubble-wrap
url = https://github.com/tangrams/bubble-wrap.git
[submodule "core/src/main/assets/styles/refill-more-labels"]
path = core/src/main/assets/styles/refill-more-labels
url = https://github.com/tangrams/refill-style-more-labels.git
[submodule "core/src/main/assets/styles/cinnabar-more-labels"]
path = core/src/main/assets/styles/cinnabar-more-labels
url = https://github.com/tangrams/cinnabar-style-more-labels.git
Expand All @@ -16,3 +13,6 @@
[submodule "samples/mapzen-android-sdk-sample/src/main/assets/styles/tron-style"]
path = samples/mapzen-android-sdk-sample/src/main/assets/styles/tron-style
url = https://github.com/tangrams/tron-style.git
[submodule "core/src/main/assets/styles/refill-style"]
path = core/src/main/assets/styles/refill-style
url = https://github.com/tangrams/refill-style
1 change: 0 additions & 1 deletion core/src/main/assets/styles/refill-more-labels
Submodule refill-more-labels deleted from 2325ec
1 change: 1 addition & 0 deletions core/src/main/assets/styles/refill-style
Submodule refill-style added at a85ba8
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@
BitmapMarkerFactory bitmapMarkerFactory, StyleStringGenerator styleStringGenerator) {
return new BitmapMarkerManager(bitmapMarkerFactory, styleStringGenerator);
}

/**
* Returns the object used to generate import yaml for use loading
* {@link com.mapzen.android.graphics.model.ThemedMapStyle}s.
* @return
*/
@Provides @Singleton public ImportYamlGenerator providesImportYamlGenerator() {
return new ImportYamlGenerator();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mapzen.android.graphics;

import com.mapzen.android.graphics.model.ThemeColor;
import com.mapzen.android.graphics.model.ThemedMapStyle;

/**
* Handles creating fully qualified import yaml for a given {@link ThemedMapStyle} so that
* it can be applied by {@link MapzenMap}.
*/
class ImportYamlGenerator {

/**
* Creates import yaml string for a given theme, label level, detail level, and color.
* @param themedMapStyle
* @param labelLevel
* @return
*/
String getImportYaml(ThemedMapStyle themedMapStyle, int labelLevel, int detailLevel,
ThemeColor color) {
String labelFileName = new StringBuilder()
.append("label-")
.append(labelLevel)
.append(".yaml")
.toString();
String detailFileName = new StringBuilder()
.append("detail-")
.append(detailLevel)
.append(".yaml")
.toString();
String colorFileName = new StringBuilder()
.append("color-")
.append(color.toString())
.append(".yaml")
.toString();
return "{ import: [ "
+ themedMapStyle.getBaseStyleFilename() + ", "
+ themedMapStyle.getThemesPath() + labelFileName + ", "
+ themedMapStyle.getThemesPath() + detailFileName + ", "
+ themedMapStyle.getThemesPath() + colorFileName
+ " ] }";
}
}
23 changes: 18 additions & 5 deletions core/src/main/java/com/mapzen/android/graphics/MapInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mapzen.android.graphics.model.BubbleWrapStyle;
import com.mapzen.android.graphics.model.MapStyle;
import com.mapzen.android.graphics.model.BitmapMarkerManager;
import com.mapzen.android.graphics.model.ThemedMapStyle;
import com.mapzen.tangram.MapController;
import com.mapzen.tangram.SceneError;
import com.mapzen.tangram.SceneUpdate;
Expand Down Expand Up @@ -36,19 +37,23 @@ public class MapInitializer {

private BitmapMarkerManager bitmapMarkerManager;

private ImportYamlGenerator yamlGenerator;

/**
* Creates a new instance.
*/
@Inject MapInitializer(Context context, MapzenMapHttpHandler mapzenMapHttpHandler,
MapDataManager mapDataManager, MapStateManager mapStateManager,
SceneUpdateManager sceneUpdateManager, BitmapMarkerManager bitmapMarkerManager) {
SceneUpdateManager sceneUpdateManager, BitmapMarkerManager bitmapMarkerManager,
ImportYamlGenerator yamlGenerator) {
this.context = context;
this.mapzenMapHttpHandler = mapzenMapHttpHandler;
this.mapDataManager = mapDataManager;
this.mapStateManager = mapStateManager;
this.sceneUpdateManager = sceneUpdateManager;
mapReadyInitializer = new MapReadyInitializer();
this.bitmapMarkerManager = bitmapMarkerManager;
this.yamlGenerator = yamlGenerator;
}

/**
Expand Down Expand Up @@ -85,10 +90,11 @@ private void loadMap(final MapView mapView, MapStyle mapStyle, boolean styleExpl
mapStyle = restoredMapStyle;
}
mapStateManager.setMapStyle(mapStyle);
loadMap(mapView, mapStyle.getSceneFile(), callback);
loadMap(mapView, mapStyle, callback);
}

private void loadMap(final MapView mapView, String sceneFile, final OnMapReadyCallback callback) {
private void loadMap(final MapView mapView, MapStyle mapStyle,
final OnMapReadyCallback callback) {
final String apiKey = MapzenManager.instance(context).getApiKey();
final List<SceneUpdate> sceneUpdates = sceneUpdateManager.getUpdatesFor(apiKey, locale,
mapStateManager.isTransitOverlayEnabled(), mapStateManager.isBikeOverlayEnabled(),
Expand All @@ -97,9 +103,16 @@ private void loadMap(final MapView mapView, String sceneFile, final OnMapReadyCa
new MapController.SceneLoadListener() {
@Override public void onSceneReady(int sceneId, SceneError sceneError) {
mapReadyInitializer.onMapReady(mapView, mapzenMapHttpHandler, callback, mapDataManager,
mapStateManager, sceneUpdateManager, locale, bitmapMarkerManager);
mapStateManager, sceneUpdateManager, locale, bitmapMarkerManager, yamlGenerator);
}
});
controller.loadSceneFileAsync(sceneFile, sceneUpdates);
if (mapStyle instanceof ThemedMapStyle) {
ThemedMapStyle themedMapStyle = (ThemedMapStyle) mapStyle;
String yaml = yamlGenerator.getImportYaml(themedMapStyle, mapStateManager.getLabelLevel(),
mapStateManager.getLod(), mapStateManager.getThemeColor());
controller.loadSceneYamlAsync(yaml, themedMapStyle.getStyleRootPath(), sceneUpdates);
} else {
controller.loadSceneFileAsync(mapStyle.getSceneFile(), sceneUpdates);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MapReadyInitializer {
void onMapReady(MapView mapView, MapzenMapHttpHandler mapzenMapHttpHandler,
OnMapReadyCallback callback, MapDataManager mapDataManager, MapStateManager mapStateManager,
SceneUpdateManager sceneUpdateManager, Locale locale,
BitmapMarkerManager bitmapMarkerManager) {
BitmapMarkerManager bitmapMarkerManager, ImportYamlGenerator yamlGenerator) {
MapController mapController = mapView.getTangramMapView().getMap(null);
mapController.setSceneLoadListener(null);
mapController.setHttpHandler(mapzenMapHttpHandler.httpHandler());
Expand All @@ -34,6 +34,6 @@ void onMapReady(MapView mapView, MapzenMapHttpHandler mapzenMapHttpHandler,
callback.onMapReady(
new MapzenMap(mapView, mapController, new OverlayManager(mapView, mapController,
mapDataManager, mapStateManager), mapStateManager, new LabelPickHandler(mapView),
bitmapMarkerManager, sceneUpdateManager, locale, mapzenManager));
bitmapMarkerManager, sceneUpdateManager, locale, mapzenManager, yamlGenerator));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mapzen.android.graphics.model.BubbleWrapStyle;
import com.mapzen.android.graphics.model.CameraType;
import com.mapzen.android.graphics.model.MapStyle;
import com.mapzen.android.graphics.model.ThemeColor;
import com.mapzen.tangram.LngLat;

/**
Expand All @@ -14,6 +15,9 @@ class MapStateManager {
private boolean persistMapState = true;
private LngLat position = new LngLat(0, 0);
private MapStyle mapStyle = new BubbleWrapStyle();
private int labelLevel = 0;
private int lod = 0;
private ThemeColor themeColor = null;
private float zoom = 0;
private float rotation = 0;
private float tilt = 0;
Expand Down Expand Up @@ -46,6 +50,30 @@ public MapStyle getMapStyle() {
return this.mapStyle;
}

public void setLabelLevel(int labelLevel) {
this.labelLevel = labelLevel;
}

public int getLabelLevel() {
return this.labelLevel;
}

public void setLod(int lod) {
this.lod = lod;
}

public int getLod() {
return this.lod;
}

public void setThemeColor(ThemeColor color) {
this.themeColor = color;
}

public ThemeColor getThemeColor() {
return this.themeColor;
}

public void setZoom(float zoom) {
this.zoom = zoom;
}
Expand Down