Skip to content

Commit 014aa04

Browse files
committed
[annotation] - remove self update mechanism
1 parent ef2b486 commit 014aa04

18 files changed

Lines changed: 86 additions & 290 deletions

File tree

app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/SymbolActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
109109
} else {
110110
return super.onOptionsItemSelected(item);
111111
}
112+
symbolManager.update(symbol);
112113
return true;
113114
}
114115

plugin-annotation/scripts/annotation.java.ejs

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,19 @@ public class <%- camelize(type) %> extends Annotation {
2323
<% if (type === "symbol") { -%>
2424
//public static final String Z_INDEX = "z-index";
2525
<% } -%>
26-
private final <%- camelize(type) %>Manager <%- type %>Manager;
27-
28-
/**
29-
* Create a <%- type %>.
30-
*
31-
* @param manager the <%- type %> manager created and managing the <%- type %>
32-
* @param id the id of the <%- type %>
33-
*/
34-
<%- camelize(type) %>(<%- camelize(type) %>Manager manager, long id) {
35-
super(id);
36-
this.<%- type %>Manager = manager;
37-
<% if (type === "symbol") { -%>
38-
//this.jsonObject.addProperty(Z_INDEX, 0);
39-
<% } -%>
40-
}
41-
4226
/**
4327
* Create a <%- type %>.
4428
*
45-
* @param manager the <%- type %> manager created and managing the <%- type %>
4629
* @param id the id of the <%- type %>
4730
* @param jsonObject the features of the annotation
4831
* @param geometry the geometry of the annotation
4932
*/
50-
<%- camelize(type) %>(<%- camelize(type) %>Manager manager, long id, JsonObject jsonObject, Geometry geometry) {
33+
<%- camelize(type) %>(long id, JsonObject jsonObject, Geometry geometry) {
5134
super(id, jsonObject, geometry);
52-
this.<%- type %>Manager = manager;
5335
<% if (type === "symbol") { -%>
5436
//this.jsonObject.addProperty(Z_INDEX, 0);
5537
<% } -%>
5638
}
57-
58-
/**
59-
* Called to update the underlying data source.
60-
*/
61-
@Override
62-
public void update() {
63-
<%- type %>Manager.updateSource();
64-
}
6539
<% if (type === "circle" || type === "symbol") { -%>
6640
6741
/**
@@ -70,20 +44,7 @@ public class <%- camelize(type) %> extends Annotation {
7044
* @param latLng the location of the <%- type %> in a longitude and latitude pair
7145
*/
7246
public void setLatLng(LatLng latLng) {
73-
setLatLng(latLng, true);
74-
}
75-
76-
/**
77-
* Set the LatLng of the <%- type %>, which represents the location of the <%- type %> on the map
78-
*
79-
* @param latLng the location of the <%- type %> in a longitude and latitude pair
80-
* @param updateSource flag to indicate the source instantly
81-
*/
82-
public void setLatLng(LatLng latLng, boolean updateSource) {
8347
geometry = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude());
84-
if (updateSource) {
85-
<%- type %>Manager.updateSource();
86-
}
8748
}
8849
<% } else if (type === "line") { -%>
8950
@@ -93,24 +54,11 @@ public class <%- camelize(type) %> extends Annotation {
9354
* @param latLngs a list of the locations of the line in a longitude and latitude pairs
9455
*/
9556
public void setLatLngs(List<LatLng> latLngs) {
96-
setLatLngs(latLngs, true);
97-
}
98-
99-
/**
100-
* Set a list of LatLng for the line, which represents the locations of the line on the map
101-
*
102-
* @param latLngs a list of the locations of the line in a longitude and latitude pairs
103-
* @param updateSource flag to indicate the source instantly
104-
*/
105-
public void setLatLngs(List<LatLng> latLngs, boolean updateSource) {
10657
List<Point>points = new ArrayList<>();
10758
for (LatLng latLng : latLngs) {
10859
points.add(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
10960
}
11061
geometry = LineString.fromLngLats(points);
111-
if (updateSource) {
112-
lineManager.updateSource();
113-
}
11462
}
11563
<% } else { -%>
11664
@@ -120,16 +68,6 @@ public class <%- camelize(type) %> extends Annotation {
12068
* @param latLngs a list of a lists of the locations of the line in a longitude and latitude pairs
12169
*/
12270
public void setLatLngs(List<List<LatLng>> latLngs) {
123-
setLatLngs(latLngs, true);
124-
}
125-
126-
/**
127-
* Set a list of lists of LatLng for the fill, which represents the locations of the fill on the map
128-
*
129-
* @param latLngs a list of a lists of the locations of the line in a longitude and latitude pairs
130-
* @param updateSource flag to indicate the source instantly
131-
*/
132-
public void setLatLngs(List<List<LatLng>> latLngs, boolean updateSource) {
13371
List<List<Point>> points = new ArrayList<>();
13472
for (List<LatLng> innerLatLngs : latLngs) {
13573
List<Point>innerList = new ArrayList<>();
@@ -139,9 +77,6 @@ public class <%- camelize(type) %> extends Annotation {
13977
points.add(innerList);
14078
}
14179
geometry = Polygon.fromLngLats(points);
142-
if (updateSource) {
143-
fillManager.updateSource();
144-
}
14580
}
14681
<% } -%>
14782
<% if (type === "symbol") { -%>
@@ -201,7 +136,6 @@ public class <%- camelize(type) %> extends Annotation {
201136
jsonArray.add(element);
202137
}
203138
jsonObject.add("<%-property.name %>", jsonArray);
204-
<%- type %>Manager.updateSource();
205139
}
206140
207141
<% } else { -%>
@@ -221,7 +155,6 @@ public class <%- camelize(type) %> extends Annotation {
221155
*/
222156
public void set<%- camelize(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), " ") %><%- propertyType(property) %> value) {
223157
jsonObject.addProperty("<%- property.name %>", value);
224-
<%- type %>Manager.updateSource();
225158
}
226159
227160
<% } -%>

plugin-annotation/scripts/annotation_manager.java.ejs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize
124124
*/
125125
@UiThread
126126
public <%- camelize(type) %> create<%- camelize(type) %>(@NonNull <%- camelize(type) %>Options options) {
127-
<%- camelize(type) %> <%- type %> = options.build(this, currentId);
127+
<%- camelize(type) %> <%- type %> = options.build(currentId);
128128
add(<%- type %>);
129+
updateSource();
129130
return <%- type %>;
130131
}
131132

@@ -140,7 +141,7 @@ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize
140141
List<<%- camelize(type) %>> <%- type %>s = new ArrayList<>();
141142
<%- camelize(type) %> <%- type %>;
142143
for (<%- camelize(type) %>Options option : options) {
143-
<%- type %> = option.build(this, currentId);
144+
<%- type %> = option.build(currentId);
144145
<%- type %>s.add(<%- type %>);
145146
add(<%- type %>);
146147
}

plugin-annotation/scripts/annotation_options.java.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public class <%- camelize(type) %>Options {
106106
}
107107
<% } -%>
108108

109-
<%- camelize(type) %> build(<%- camelize(type) %>Manager <%- type %>Manager, long id) {
109+
<%- camelize(type) %> build(long id) {
110110
if (geometry == null) {
111111
throw new RuntimeException("geometry field is required");
112112
}
@@ -120,6 +120,6 @@ public class <%- camelize(type) %>Options {
120120
<% } -%>
121121
<% } -%>
122122
<% } -%>
123-
return new <%- camelize(type) %>(<%- type %>Manager, id, jsonObject, geometry);
123+
return new <%- camelize(type) %>(id, jsonObject, geometry);
124124
}
125125
}

plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/Annotation.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,4 @@ public long getId() {
3737
JsonObject getFeature() {
3838
return jsonObject;
3939
}
40-
41-
abstract void update();
4240
}

plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
import java.util.ArrayList;
1515
import java.util.List;
1616

17+
/**
18+
* Generic AnnotationManager, can be used to create annotation specific managers.
19+
*
20+
* @param <T> type of annotation
21+
* @param <U> type of annotation click listener, depends on generic T
22+
* @param <V> type of annotation long click listener, depends on generic T
23+
*/
1724
public abstract class AnnotationManager<
1825
T extends Annotation,
1926
U extends OnAnnotationClickListener<T>,
@@ -49,20 +56,61 @@ public LongSparseArray<T> getAnnotations() {
4956
return annotations;
5057
}
5158

59+
/**
60+
* Adds an annotatiokn to the map.
61+
*
62+
* @param annotation annotation to be added
63+
*/
5264
@UiThread
53-
void add(@NonNull T t) {
54-
annotations.put(currentId, t);
65+
void add(@NonNull T annotation) {
66+
annotations.put(annotation.getId(), annotation);
5567
currentId++;
5668
}
5769

70+
/**
71+
* Adds annotations to the map.
72+
*
73+
* @param annotationList list of annotation to be added
74+
*/
75+
@UiThread
76+
void add(@NonNull List<T> annotationList) {
77+
for (T annotation : annotationList) {
78+
annotations.put(annotation.getId(), annotation);
79+
}
80+
}
81+
5882
/**
5983
* Delete an annotation from the map.
6084
*
61-
* @param t annotation to be deleted
85+
* @param annotation annotation to be deleted
6286
*/
6387
@UiThread
64-
public void delete(T t){
65-
annotations.remove(t.getId());
88+
public void delete(T annotation) {
89+
annotations.remove(annotation.getId());
90+
updateSource();
91+
}
92+
93+
/**
94+
* Update an annotation on the map.
95+
*
96+
* @param annotation annotation to be updated
97+
*/
98+
@UiThread
99+
public void update(T annotation) {
100+
annotations.put(annotation.getId(), annotation);
101+
updateSource();
102+
}
103+
104+
/**
105+
* Update annotations on the map.
106+
*
107+
* @param annotationList list of annotation to be updated
108+
*/
109+
@UiThread
110+
public void update(List<T> annotationList) {
111+
for (T annotation : annotationList) {
112+
annotations.put(annotation.getId(), annotation);
113+
}
66114
updateSource();
67115
}
68116

@@ -157,7 +205,7 @@ public void onMapClick(@NonNull LatLng point) {
157205
return;
158206
}
159207

160-
T annotation= queryMapForFeatures(point);
208+
T annotation = queryMapForFeatures(point);
161209
if (annotation != null) {
162210
for (U clickListener : clickListeners) {
163211
clickListener.onAnnotationClick(annotation);
@@ -171,7 +219,7 @@ public void onMapLongClick(@NonNull LatLng point) {
171219
return;
172220
}
173221

174-
T annotation= queryMapForFeatures(point);
222+
T annotation = queryMapForFeatures(point);
175223
if (annotation != null) {
176224
for (V clickListener : longClickListeners) {
177225
clickListener.onAnnotationLongClick(annotation);

0 commit comments

Comments
 (0)