diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps')
2 files changed, 78 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 7cc1d003df..9c36343051 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -76,10 +76,13 @@ public final class MapboxMap { @Nullable private MapboxMap.OnFpsChangedListener onFpsChangedListener; + private com.mapbox.mapboxsdk.maps.Style style; + MapboxMap(NativeMapView map, Transform transform, UiSettings ui, Projection projection, OnGesturesManagerInteractionListener listener, AnnotationManager annotations, CameraChangeDispatcher cameraChangeDispatcher, MapChangeReceiver mapChangeReceiver) { this.nativeMapView = map; + this.style = new com.mapbox.mapboxsdk.maps.Style(nativeMapView); this.uiSettings = ui; this.projection = projection; this.annotationManager = annotations.bind(this); @@ -101,6 +104,10 @@ public final class MapboxMap { setPrefetchesTiles(options); } + public com.mapbox.mapboxsdk.maps.Style getStyle(){ + return style; + } + /** * Called when the hosting Activity/Fragment onStart() method is called. */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java new file mode 100644 index 0000000000..50192d8f8d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java @@ -0,0 +1,71 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.style.layers.Layer; +import com.mapbox.mapboxsdk.style.sources.Source; + +import java.util.HashMap; + +public class Style { + + private NativeMapView nativeMapView; + private final HashMap<String, Source> sources = new HashMap<>(); + private final HashMap<String, Layer> layers = new HashMap<>(); + + public Style(NativeMapView nativeMapView) { + this.nativeMapView = nativeMapView; + } + + public void loadStyle(@com.mapbox.mapboxsdk.constants.Style.StyleUrl String styleUrl) { + for (Source source : sources.values()) { + if (source != null) { + source.setDetached(); + nativeMapView.removeSource(source); + } + } + + for (Layer layer : layers.values()) { + if (layer != null) { + layer.setDetached(); + nativeMapView.removeLayer(layer); + } + } + + nativeMapView.setStyleUrl(styleUrl); + } + + // + // Source + // + + public void addSource(Source source) { + sources.put(source.getId(), source); + nativeMapView.addSource(source); + } + + public Source getSource(String id) { + Source source = sources.get(id); + if (source == null) { + source = nativeMapView.getSource(id); + } + return source; + } + + // + // Layer + // + + public void addLayer(Layer layer) { + layers.put(layer.getId(), layer); + nativeMapView.addLayer(layer); + } + + public Layer getLayer(String id) { + Layer layer = layers.get(id); + if (layer == null) { + layer = nativeMapView.getLayer(id); + } + return layer; + } + + +} |