summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotation.java.ejs
blob: 60bdd1ffa15b849ac7d9fb0932ca6ffc563751d0 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<%
  const type = locals.type;
  const properties = locals.properties;
  const doc = locals.doc;
-%>
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`.

package com.mapbox.mapboxsdk.annotations.<%- type %>;

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 <%- camelize(type) %> {

  public static final String ID_KEY = "id-<%- type %>";
<% if (type === "symbol") { -%>
  public static final String Z_INDEX = "z-index";
<% } -%>
  private final <%- camelize(type) %>Manager <%- type %>Manager;
  private final JsonObject jsonObject = new JsonObject();
  private Geometry geometry;

  /**
   * Create a <%- type %>.
   *
   * @param manager the <%- type %> manager created and managing the <%- type %>
   * @param id            the id of the <%- type %>
   */
  <%- camelize(type) %>(<%- camelize(type) %>Manager manager, long id) {
    this.<%- type %>Manager = manager;
    this.jsonObject.addProperty(ID_KEY, id);
<% if (type === "symbol") { -%>
    this.jsonObject.addProperty(Z_INDEX, 0);
<% } -%>
  }

  /**
   * Get the <%- type %> geometry.
   *
   * @return the <%- type %> geometry
   */
  Geometry getGeometry() {
    if (geometry == null) {
      throw new IllegalStateException();
    }
    return geometry;
  }

  /**
   * Get the <%- type %> feature properties.
   *
   * @return the <%- type %> feature properties
   */
  JsonObject getFeature() {
    return jsonObject;
  }

  /**
   * Get the <%- type %> id.
   *
   * @return the <%- type %> id
   */
  public long getId() {
    return jsonObject.get(ID_KEY).getAsLong();
  }
<% if (type === "circle" || type === "symbol") { -%>

  /**
   * Set the LatLng of the <%- type %>, which represents the location of the <%- type %> on the map
   *
   * @param latLng the location of the <%- type %> in a longitude and latitude pair
   */
  public void setLatLng(LatLng latLng) {
    geometry = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude());
    <%- type %>Manager.updateSource();
  }
<% } else if (type === "line") { -%>

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

  /**
   * 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();
  }
<% } -%>
<% if (type === "symbol") { -%>

  /**
   * Set the z-index of a symbol.
   * <p>
   * If a symbol z-index is higher as another symbol it will be rendered above it.
   * </p>
   * <p>
   * Default value is 0.
   * </p>
   *
   * @param index the z-index value
   */
  public void setZIndex(int index) {
    jsonObject.addProperty(Z_INDEX, index);
    symbolManager.updateSource();
  }

  /**
   * Get the z-index of a symbol.
   *
   * @return the z-index value, 0 if not set
   */
  public int getZIndex() {
    return jsonObject.get(Z_INDEX).getAsInt();
  }
<% } -%>

  // Property accessors
<% for (const property of properties) { -%>
<% if (supportsPropertyFunction(property)) { -%>
<% if (propertyType(property).endsWith("[]")) { -%>
  /**
   * Get the <%- camelize(property.name) %> property
   *
   * @return property wrapper value around <%- propertyType(property) %>
   */
  <%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), "") %>
  public <%- propertyType(property) %> get<%- camelize(property.name) %>() {
    JsonArray jsonArray = jsonObject.getAsJsonArray("<%-property.name %>");
    <%- propertyType(property) %> value = new <%- propertyType(property).substring(0, propertyType(property).length-1) %>jsonArray.size()];
    for (int i = 0; i < jsonArray.size(); i++) {
      value[i] = jsonArray.get(i).getAs<%- propertyType(property).substring(0, propertyType(property).length-2) %>();
    }
    return value;
  }

  /**
   * Set the <%- camelize(property.name) %> property
   *
   * @return property wrapper value around <%- propertyType(property) %>
   */
  public void set<%- camelize(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), "") %><%- propertyType(property) %> value) {
    JsonArray jsonArray = new JsonArray();
    for (<%- propertyType(property).substring(0, propertyType(property).length-2) %> element : value) {
      jsonArray.add(element);
    }
    jsonObject.add("<%-property.name %>", jsonArray);
    <%- type %>Manager.updateSource();
  }

<% } else { -%>
  /**
   * Get the <%- camelize(property.name) %> property
   *
   * @return property wrapper value around <%- propertyType(property) %>
   */
  <%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), "") %>
  public <%- propertyType(property) %> get<%- camelize(property.name) %>() {
    return jsonObject.get("<%- property.name %>").getAs<%- propertyType(property) %>();
  }

  /**
   * Set the <%- camelize(property.name) %> property
   *
   * @param value constant property value for <%- propertyType(property) %>
   */
  public void set<%- camelize(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), "") %> <%- propertyType(property) %> value) {
    jsonObject.addProperty("<%- property.name %>", value);
    <%- type %>Manager.updateSource();
  }

<% } -%>
<% } -%>
<% } -%>
}