summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/Fill.java
blob: 5c6329d2ad47b98bb1937acbea908e6bf7ce8960 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`.

package com.mapbox.mapboxsdk.annotations.fill;

import android.support.annotation.UiThread;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.mapbox.geojson.*;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.style.layers.Property;

import java.util.ArrayList;
import java.util.List;

@UiThread
public class Fill {

  public static final String ID_KEY = "id-fill";
  private final FillManager fillManager;
  private final JsonObject jsonObject = new JsonObject();
  private Geometry geometry;

  /**
   * Create a fill.
   *
   * @param manager the fill manager created and managing the fill
   * @param id            the id of the fill
   */
  Fill(FillManager manager, long id) {
    this.fillManager = manager;
    this.jsonObject.addProperty(ID_KEY, id);
  }

  /**
   * Get the fill geometry.
   *
   * @return the fill geometry
   */
  Geometry getGeometry() {
    if (geometry == null) {
      throw new IllegalStateException();
    }
    return geometry;
  }

  /**
   * Get the fill feature properties.
   *
   * @return the fill feature properties
   */
  JsonObject getFeature() {
    return jsonObject;
  }

  /**
   * Get the fill id.
   *
   * @return the fill id
   */
  public long getId() {
    return jsonObject.get(ID_KEY).getAsLong();
  }

  /**
   * Set a list of lists of LatLng for the fill, which represents the locations of the fill on the map
   *
   * @param latLngs a list of a lists of the locations of the line in a longitude and latitude pairs
   */
  public void setLatLngs(List<List<LatLng>> latLngs) {
    List<List<Point>> points = new ArrayList<>();
    for (List<LatLng> innerLatLngs : latLngs) {
      List<Point>innerList = new ArrayList<>();
      for (LatLng latLng : innerLatLngs) {
        innerList.add(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
      }
      points.add(innerList);
    }
    geometry = Polygon.fromLngLats(points);
    fillManager.updateSource();
  }

  // Property accessors
  /**
   * Get the FillOpacity property
   *
   * @return property wrapper value around Float
   */
  public Float getFillOpacity() {
    return jsonObject.get("fill-opacity").getAsFloat();
  }

  /**
   * Set the FillOpacity property
   *
   * @param value constant property value for Float
   */
  public void setFillOpacity(Float value) {
    jsonObject.addProperty("fill-opacity", value);
    fillManager.updateSource();
  }

  /**
   * Get the FillColor property
   *
   * @return property wrapper value around String
   */
  public String getFillColor() {
    return jsonObject.get("fill-color").getAsString();
  }

  /**
   * Set the FillColor property
   *
   * @param value constant property value for String
   */
  public void setFillColor(String value) {
    jsonObject.addProperty("fill-color", value);
    fillManager.updateSource();
  }

  /**
   * Get the FillOutlineColor property
   *
   * @return property wrapper value around String
   */
  public String getFillOutlineColor() {
    return jsonObject.get("fill-outline-color").getAsString();
  }

  /**
   * Set the FillOutlineColor property
   *
   * @param value constant property value for String
   */
  public void setFillOutlineColor(String value) {
    jsonObject.addProperty("fill-outline-color", value);
    fillManager.updateSource();
  }

  /**
   * Get the FillPattern property
   *
   * @return property wrapper value around String
   */
  public String getFillPattern() {
    return jsonObject.get("fill-pattern").getAsString();
  }

  /**
   * Set the FillPattern property
   *
   * @param value constant property value for String
   */
  public void setFillPattern(String value) {
    jsonObject.addProperty("fill-pattern", value);
    fillManager.updateSource();
  }

}