Skip to content

Commit c781e9e

Browse files
authored
Refill Themes (#447)
* rm refill-more-labels submodule * add refill-style submodule * 8.0.0 refill release * add ThemeColor and migrate RefillStyle to ThemedMapStyle * yaml generator for themes import * Inject ImportYamlGenerator into MapzenMap * checkstyle fixes and add javadocs for ThemeMapStyle * move private methods to bottom * Add theme methods to MapzenMap * rm rebase code * fix test * Rm unnecc methods * s/detailLevel/lod * defaults consistent w cartography docs
1 parent 93b8385 commit c781e9e

20 files changed

+888
-58
lines changed

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[submodule "core/src/main/assets/styles/bubble-wrap"]
22
path = core/src/main/assets/styles/bubble-wrap
33
url = https://github.com/tangrams/bubble-wrap.git
4-
[submodule "core/src/main/assets/styles/refill-more-labels"]
5-
path = core/src/main/assets/styles/refill-more-labels
6-
url = https://github.com/tangrams/refill-style-more-labels.git
74
[submodule "core/src/main/assets/styles/cinnabar-more-labels"]
85
path = core/src/main/assets/styles/cinnabar-more-labels
96
url = https://github.com/tangrams/cinnabar-style-more-labels.git
@@ -16,3 +13,6 @@
1613
[submodule "samples/mapzen-android-sdk-sample/src/main/assets/styles/tron-style"]
1714
path = samples/mapzen-android-sdk-sample/src/main/assets/styles/tron-style
1815
url = https://github.com/tangrams/tron-style.git
16+
[submodule "core/src/main/assets/styles/refill-style"]
17+
path = core/src/main/assets/styles/refill-style
18+
url = https://github.com/tangrams/refill-style
This file was deleted.
Submodule refill-style added at a85ba8c

core/src/main/java/com/mapzen/android/graphics/GraphicsModule.java

+9
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,13 @@
6363
BitmapMarkerFactory bitmapMarkerFactory, StyleStringGenerator styleStringGenerator) {
6464
return new BitmapMarkerManager(bitmapMarkerFactory, styleStringGenerator);
6565
}
66+
67+
/**
68+
* Returns the object used to generate import yaml for use loading
69+
* {@link com.mapzen.android.graphics.model.ThemedMapStyle}s.
70+
* @return
71+
*/
72+
@Provides @Singleton public ImportYamlGenerator providesImportYamlGenerator() {
73+
return new ImportYamlGenerator();
74+
}
6675
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.mapzen.android.graphics;
2+
3+
import com.mapzen.android.graphics.model.ThemeColor;
4+
import com.mapzen.android.graphics.model.ThemedMapStyle;
5+
6+
/**
7+
* Handles creating fully qualified import yaml for a given {@link ThemedMapStyle} so that
8+
* it can be applied by {@link MapzenMap}.
9+
*/
10+
class ImportYamlGenerator {
11+
12+
/**
13+
* Creates import yaml string for a given theme, label level, detail level, and color.
14+
* @param themedMapStyle
15+
* @param labelLevel
16+
* @return
17+
*/
18+
String getImportYaml(ThemedMapStyle themedMapStyle, int labelLevel, int detailLevel,
19+
ThemeColor color) {
20+
String labelFileName = new StringBuilder()
21+
.append("label-")
22+
.append(labelLevel)
23+
.append(".yaml")
24+
.toString();
25+
String detailFileName = new StringBuilder()
26+
.append("detail-")
27+
.append(detailLevel)
28+
.append(".yaml")
29+
.toString();
30+
String colorFileName = new StringBuilder()
31+
.append("color-")
32+
.append(color.toString())
33+
.append(".yaml")
34+
.toString();
35+
return "{ import: [ "
36+
+ themedMapStyle.getBaseStyleFilename() + ", "
37+
+ themedMapStyle.getThemesPath() + labelFileName + ", "
38+
+ themedMapStyle.getThemesPath() + detailFileName + ", "
39+
+ themedMapStyle.getThemesPath() + colorFileName
40+
+ " ] }";
41+
}
42+
}

core/src/main/java/com/mapzen/android/graphics/MapInitializer.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.mapzen.android.graphics.model.BubbleWrapStyle;
55
import com.mapzen.android.graphics.model.MapStyle;
66
import com.mapzen.android.graphics.model.BitmapMarkerManager;
7+
import com.mapzen.android.graphics.model.ThemedMapStyle;
78
import com.mapzen.tangram.MapController;
89
import com.mapzen.tangram.SceneError;
910
import com.mapzen.tangram.SceneUpdate;
@@ -36,19 +37,23 @@ public class MapInitializer {
3637

3738
private BitmapMarkerManager bitmapMarkerManager;
3839

40+
private ImportYamlGenerator yamlGenerator;
41+
3942
/**
4043
* Creates a new instance.
4144
*/
4245
@Inject MapInitializer(Context context, MapzenMapHttpHandler mapzenMapHttpHandler,
4346
MapDataManager mapDataManager, MapStateManager mapStateManager,
44-
SceneUpdateManager sceneUpdateManager, BitmapMarkerManager bitmapMarkerManager) {
47+
SceneUpdateManager sceneUpdateManager, BitmapMarkerManager bitmapMarkerManager,
48+
ImportYamlGenerator yamlGenerator) {
4549
this.context = context;
4650
this.mapzenMapHttpHandler = mapzenMapHttpHandler;
4751
this.mapDataManager = mapDataManager;
4852
this.mapStateManager = mapStateManager;
4953
this.sceneUpdateManager = sceneUpdateManager;
5054
mapReadyInitializer = new MapReadyInitializer();
5155
this.bitmapMarkerManager = bitmapMarkerManager;
56+
this.yamlGenerator = yamlGenerator;
5257
}
5358

5459
/**
@@ -85,10 +90,11 @@ private void loadMap(final MapView mapView, MapStyle mapStyle, boolean styleExpl
8590
mapStyle = restoredMapStyle;
8691
}
8792
mapStateManager.setMapStyle(mapStyle);
88-
loadMap(mapView, mapStyle.getSceneFile(), callback);
93+
loadMap(mapView, mapStyle, callback);
8994
}
9095

91-
private void loadMap(final MapView mapView, String sceneFile, final OnMapReadyCallback callback) {
96+
private void loadMap(final MapView mapView, MapStyle mapStyle,
97+
final OnMapReadyCallback callback) {
9298
final String apiKey = MapzenManager.instance(context).getApiKey();
9399
final List<SceneUpdate> sceneUpdates = sceneUpdateManager.getUpdatesFor(apiKey, locale,
94100
mapStateManager.isTransitOverlayEnabled(), mapStateManager.isBikeOverlayEnabled(),
@@ -97,9 +103,16 @@ private void loadMap(final MapView mapView, String sceneFile, final OnMapReadyCa
97103
new MapController.SceneLoadListener() {
98104
@Override public void onSceneReady(int sceneId, SceneError sceneError) {
99105
mapReadyInitializer.onMapReady(mapView, mapzenMapHttpHandler, callback, mapDataManager,
100-
mapStateManager, sceneUpdateManager, locale, bitmapMarkerManager);
106+
mapStateManager, sceneUpdateManager, locale, bitmapMarkerManager, yamlGenerator);
101107
}
102108
});
103-
controller.loadSceneFileAsync(sceneFile, sceneUpdates);
109+
if (mapStyle instanceof ThemedMapStyle) {
110+
ThemedMapStyle themedMapStyle = (ThemedMapStyle) mapStyle;
111+
String yaml = yamlGenerator.getImportYaml(themedMapStyle, mapStateManager.getLabelLevel(),
112+
mapStateManager.getLod(), mapStateManager.getThemeColor());
113+
controller.loadSceneYamlAsync(yaml, themedMapStyle.getStyleRootPath(), sceneUpdates);
114+
} else {
115+
controller.loadSceneFileAsync(mapStyle.getSceneFile(), sceneUpdates);
116+
}
104117
}
105118
}

core/src/main/java/com/mapzen/android/graphics/MapReadyInitializer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MapReadyInitializer {
2525
void onMapReady(MapView mapView, MapzenMapHttpHandler mapzenMapHttpHandler,
2626
OnMapReadyCallback callback, MapDataManager mapDataManager, MapStateManager mapStateManager,
2727
SceneUpdateManager sceneUpdateManager, Locale locale,
28-
BitmapMarkerManager bitmapMarkerManager) {
28+
BitmapMarkerManager bitmapMarkerManager, ImportYamlGenerator yamlGenerator) {
2929
MapController mapController = mapView.getTangramMapView().getMap(null);
3030
mapController.setSceneLoadListener(null);
3131
mapController.setHttpHandler(mapzenMapHttpHandler.httpHandler());
@@ -34,6 +34,6 @@ void onMapReady(MapView mapView, MapzenMapHttpHandler mapzenMapHttpHandler,
3434
callback.onMapReady(
3535
new MapzenMap(mapView, mapController, new OverlayManager(mapView, mapController,
3636
mapDataManager, mapStateManager), mapStateManager, new LabelPickHandler(mapView),
37-
bitmapMarkerManager, sceneUpdateManager, locale, mapzenManager));
37+
bitmapMarkerManager, sceneUpdateManager, locale, mapzenManager, yamlGenerator));
3838
}
3939
}

core/src/main/java/com/mapzen/android/graphics/MapStateManager.java

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mapzen.android.graphics.model.BubbleWrapStyle;
44
import com.mapzen.android.graphics.model.CameraType;
55
import com.mapzen.android.graphics.model.MapStyle;
6+
import com.mapzen.android.graphics.model.ThemeColor;
67
import com.mapzen.tangram.LngLat;
78

89
/**
@@ -14,6 +15,9 @@ class MapStateManager {
1415
private boolean persistMapState = true;
1516
private LngLat position = new LngLat(0, 0);
1617
private MapStyle mapStyle = new BubbleWrapStyle();
18+
private int labelLevel = 0;
19+
private int lod = 0;
20+
private ThemeColor themeColor = null;
1721
private float zoom = 0;
1822
private float rotation = 0;
1923
private float tilt = 0;
@@ -46,6 +50,30 @@ public MapStyle getMapStyle() {
4650
return this.mapStyle;
4751
}
4852

53+
public void setLabelLevel(int labelLevel) {
54+
this.labelLevel = labelLevel;
55+
}
56+
57+
public int getLabelLevel() {
58+
return this.labelLevel;
59+
}
60+
61+
public void setLod(int lod) {
62+
this.lod = lod;
63+
}
64+
65+
public int getLod() {
66+
return this.lod;
67+
}
68+
69+
public void setThemeColor(ThemeColor color) {
70+
this.themeColor = color;
71+
}
72+
73+
public ThemeColor getThemeColor() {
74+
return this.themeColor;
75+
}
76+
4977
public void setZoom(float zoom) {
5078
this.zoom = zoom;
5179
}

0 commit comments

Comments
 (0)