diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2018-11-08 14:36:28 +0100 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-12-10 16:59:50 +0100 |
commit | dedb7404f23b407bd8e0583b0648025a3dc256b6 (patch) | |
tree | 9cfa50d4c2a37f7d749dcc9694a8e37514cbfa42 /platform | |
parent | 94451b41ef5ede1f3f1534f0f6c94356663ae23b (diff) | |
download | qtlocation-mapboxgl-dedb7404f23b407bd8e0583b0648025a3dc256b6.tar.gz |
[android] - move all style methods to Style.java
Diffstat (limited to 'platform')
2 files changed, 56 insertions, 99 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 2211d4bd1d..0c4cbe92d1 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 @@ -679,63 +679,8 @@ public final class MapboxMap { // Styling // - public void setStyle(Style.Builder builder) { - - } - - - /** - * <p> - * Loads a new map style asynchronous from the specified URL. - * </p> - * {@code url} can take the following forms: - * <ul> - * <li>{@code Style.*}: load one of the bundled styles in {@link Style}.</li> - * <li>{@code mapbox://styles/<user>/<style>}: - * loads the style from a <a href="https://www.mapbox.com/account/">Mapbox account.</a> - * {@code user} is your username. {@code style} is the ID of your custom - * style created in <a href="https://www.mapbox.com/studio">Mapbox Studio</a>.</li> - * <li>{@code http://...} or {@code https://...}: - * loads the style over the Internet from any web server.</li> - * <li>{@code asset://...}: - * loads the style from the APK {@code assets/} directory. - * This is used to load a style bundled with your app.</li> - * <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li> - * </ul> - * <p> - * This method is asynchronous and will return before the style finishes loading. - * If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener} - * callback. - * </p> - * If the style fails to load or an invalid style URL is set, the map view will become blank. - * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback - * will be triggered. - * - * @param url The URL of the map style - * @see Style - */ - public void setStyleUrl(@NonNull String url) { - nativeMapView.setStyleUrl(url); - } - - /** - * <p> - * Loads a new map style from the specified bundled style. - * </p> - * <p> - * This method is asynchronous and will return before the style finishes loading. - * If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener} - * callback. - * </p> - * If the style fails to load or an invalid style URL is set, the map view will become blank. - * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback - * will be triggered. - * - * @param style The bundled style. - * @see Style - */ - public void setStyle(@NonNull @Style.StyleUrl String style) { - setStyleUrl(style); + public Style setStyle(Style.Builder builder) { + return style = builder.build(nativeMapView); } /** @@ -746,54 +691,17 @@ public final class MapboxMap { private void setStyleUrl(@NonNull MapboxMapOptions options) { String style = options.getStyleUrl(); if (!TextUtils.isEmpty(style)) { - setStyleUrl(style); + setStyle(new Style.Builder().withStyleUrl(style)); } } - /** - * Returns the map style url currently displayed in the map view. - * - * @return The URL of the map style - */ - @Nullable - public String getStyleUrl() { - return nativeMapView.getStyleUrl(); - } - - /** - * Loads a new map style from a json string. - * <p> - * If the style fails to load or an invalid style URL is set, the map view will become blank. - * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback - * will be triggered. - * </p> - */ - public void setStyleJson(@NonNull String styleJson) { - nativeMapView.setStyleJson(styleJson); - } - - /** - * Loads a new map style json from MapboxMapOptions if available. - * - * @param options the object containing the style json - */ private void setStyleJson(@NonNull MapboxMapOptions options) { String styleJson = options.getStyleJson(); if (!TextUtils.isEmpty(styleJson)) { - setStyleJson(styleJson); + setStyle(new Style.Builder().withStyleJson(styleJson)); } } - /** - * Returns the map style json currently displayed in the map view. - * - * @return The json of the map style - */ - @NonNull - public String getStyleJson() { - return nativeMapView.getStyleJson(); - } - // // Annotations // 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 index 9cc14d67db..edbb2764cd 100644 --- 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 @@ -18,7 +18,7 @@ import java.util.List; public class Style { - private NativeMapView nativeMapView; + private final NativeMapView nativeMapView; private final HashMap<String, Source> sources = new HashMap<>(); private final HashMap<String, Layer> layers = new HashMap<>(); @@ -44,6 +44,16 @@ public class Style { nativeMapView.setStyleUrl(styleUrl); } + @Nullable + public String getUrl(){ + return nativeMapView.getStyleUrl(); + } + + @Nullable + public String getJson(){ + return nativeMapView.getStyleJson(); + } + // // Source // @@ -339,11 +349,50 @@ public class Style { private List<Layer> layers = new ArrayList<>(); private TransitionOptions transitionOptions; - public Builder withStyleUrl(@StyleUrl String styleUrl) { + + /** + * <p> + * Loads a new map style asynchronous from the specified URL. + * </p> + * {@code url} can take the following forms: + * <ul> + * <li>{@code Style.*}: load one of the bundled styles in {@link Style}.</li> + * <li>{@code mapbox://styles/<user>/<style>}: + * loads the style from a <a href="https://www.mapbox.com/account/">Mapbox account.</a> + * {@code user} is your username. {@code style} is the ID of your custom + * style created in <a href="https://www.mapbox.com/studio">Mapbox Studio</a>.</li> + * <li>{@code http://...} or {@code https://...}: + * loads the style over the Internet from any web server.</li> + * <li>{@code asset://...}: + * loads the style from the APK {@code assets/} directory. + * This is used to load a style bundled with your app.</li> + * <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li> + * </ul> + * <p> + * This method is asynchronous and will return before the style finishes loading. + * If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener} + * callback. + * </p> + * If the style fails to load or an invalid style URL is set, the map view will become blank. + * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback + * will be triggered. + * + * @param url The URL of the map style + * @see Style + */ + public Builder withStyleUrl(@StyleUrl String url) { this.styleUrl = styleUrl; return this; } + /** + * Loads a new map style from a json string. + * <p> + * If the style fails to load or an invalid style URL is set, the map view will become blank. + * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback + * will be triggered. + * </p> + */ public Builder withStyleJson(String styleJson) { this.styleJson = styleJson; return this; @@ -363,7 +412,7 @@ public class Style { this.transitionOptions = transition; return this; } - + Style build(NativeMapView nativeMapView) { Style style = new Style(nativeMapView); for (Source source : sources) { |