summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapSettings.java
blob: 8a64937bf4ffde9dcf2156e799bb5fa460305d34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.mapbox.mapboxsdk.maps;

import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;

/**
 * Internal class used to manage map settings.
 */
public final class MapSettings extends ViewModel {
  private CameraPosition lastCameraPosition = CameraPosition.DEFAULT;
  private MutableLiveData<Double> maxZoom = new MutableLiveData<>();
  private MutableLiveData<Double> minZoom = new MutableLiveData<>();
  private MutableLiveData<Boolean> isDebugMode = new MutableLiveData<>();
  private MutableLiveData<Boolean> prefetchesTiles = new MutableLiveData<>();
  private MutableLiveData<String> styleUrl = new MutableLiveData<>();
  private MutableLiveData<String> apiBaseUrl = new MutableLiveData<>();

  void initialiseOptions(@NonNull MapboxMapOptions options) {
    setLastCameraPosition(options.getCamera());
    setMinZoom(options.getMinZoomPreference());
    setMaxZoom(options.getMaxZoomPreference());
    setDebugMode(options.getDebugActive());
    setPrefetchesTiles(options.getPrefetchesTiles());

    String apiBaseUrl = options.getApiBaseUrl();
    if (!TextUtils.isEmpty(apiBaseUrl)) {
      setApiBaseUrl(apiBaseUrl);
    }

    String style = options.getStyle();
    if (!TextUtils.isEmpty(style)) {
      setStyleUrl(style);
    } else {
      setStyleUrl(Style.MAPBOX_STREETS);
    }
  }

  @Nullable
  public CameraPosition getLastCameraPosition() {
    return lastCameraPosition;
  }

  public void setLastCameraPosition(@Nullable CameraPosition lastCameraPosition) {
    this.lastCameraPosition = lastCameraPosition;
  }

  public double getMinZoom() {
    return minZoom.getValue();
  }

  public MutableLiveData<Double> getMinZoomObservable() {
    return minZoom;
  }

  public void setMinZoom(double minZoom) {
    this.minZoom.setValue(minZoom);
  }

  public double getMaxZoom() {
    return maxZoom.getValue();
  }

  public MutableLiveData<Double> getMaxZoomObservable() {
    return maxZoom;
  }

  public void setMaxZoom(double maxZoom) {
    this.maxZoom.setValue(maxZoom);
  }

  public MutableLiveData<Boolean> isDebugModeObservable() {
    return isDebugMode;
  }

  public boolean isDebugMode() {
    return isDebugMode.getValue();
  }

  public void setDebugMode(boolean isDebugMode) {
    this.isDebugMode.setValue(isDebugMode);
  }

  public MutableLiveData<Boolean> getPrefetchesTilesObservable() {
    return prefetchesTiles;
  }

  public boolean getPrefetchesTiles() {
    return prefetchesTiles.getValue();
  }

  public void setPrefetchesTiles(boolean prefetchesTiles) {
    this.prefetchesTiles.setValue(prefetchesTiles);
  }

  public MutableLiveData<String> getStyleUrlObservable() {
    return styleUrl;
  }

  public String getStyleUrl() {
    return styleUrl.getValue();
  }

  public void setStyleUrl(String styleUrl) {
    if (!TextUtils.isEmpty(styleUrl)) {
      this.styleUrl.setValue(styleUrl);
    }
  }

  public MutableLiveData<String> getApiBaseUrlObservable() {
    return apiBaseUrl;
  }

  public void setApiBaseUrl(String apiBaseUrl) {
    this.apiBaseUrl.setValue(apiBaseUrl);
  }
}