This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] #352 - rework annotations inheritance, added feature concept
- Loading branch information
Showing
28 changed files
with
857 additions
and
155 deletions.
There are no files selected for viewing
107 changes: 3 additions & 104 deletions
107
...android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,9 @@ | ||
package com.mapbox.mapboxsdk.annotations; | ||
|
||
import android.support.annotation.NonNull; | ||
public interface Annotation { | ||
|
||
import com.mapbox.mapboxsdk.maps.MapView; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
long getId(); | ||
|
||
/** | ||
* Annotation is an overlay on top of a {@link MapView}, | ||
* from which {@link Polygon}, {@link Polyline} and {@link Marker} are derived. | ||
* <p> | ||
* it manages attachment to a map and identification, but does not require | ||
* content to be placed at a geographical point. | ||
* </p> | ||
*/ | ||
public abstract class Annotation implements Comparable<Annotation> { | ||
void setId(long id); | ||
|
||
/** | ||
* <p> | ||
* The annotation id | ||
* </p> | ||
* Internal C++ id is stored as unsigned int. | ||
*/ | ||
private long id = -1; // -1 unless added to a MapView | ||
protected MapboxMap mapboxMap; | ||
protected MapView mapView; | ||
|
||
protected Annotation() { | ||
} | ||
|
||
/** | ||
* <p> | ||
* Gets the annotation's unique ID. | ||
* </p> | ||
* This ID is unique for a MapView instance and is suitable for associating your own extra | ||
* data with. | ||
*/ | ||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void remove() { | ||
if (mapboxMap == null) { | ||
return; | ||
} | ||
mapboxMap.removeAnnotation(this); | ||
} | ||
|
||
/** | ||
* Do not use this method. Used internally by the SDK. | ||
*/ | ||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* Do not use this method. Used internally by the SDK. | ||
*/ | ||
public void setMapboxMap(MapboxMap mapboxMap) { | ||
this.mapboxMap = mapboxMap; | ||
} | ||
|
||
/** | ||
* Gets the associated MapboxMap | ||
* | ||
* @return The MapboxMap | ||
*/ | ||
protected MapboxMap getMapboxMap() { | ||
return mapboxMap; | ||
} | ||
|
||
/** | ||
* Don not use this method. Used internally by the SDK. | ||
*/ | ||
public void setMapView(MapView mapView) { | ||
this.mapView = mapView; | ||
} | ||
|
||
/** | ||
* Gets the associated MapView | ||
* | ||
* @return The MapView | ||
*/ | ||
protected MapView getMapView() { | ||
return mapView; | ||
} | ||
|
||
@Override | ||
public int compareTo(@NonNull Annotation annotation) { | ||
if (id < annotation.getId()) { | ||
return 1; | ||
} else if (id > annotation.getId()) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || !(o instanceof Annotation)) return false; | ||
Annotation that = (Annotation) o; | ||
return id == that.getId(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return (int) (getId() ^ (getId() >>> 32)); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...rm/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Feature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.mapbox.mapboxsdk.annotations; | ||
|
||
|
||
import java.util.Map; | ||
|
||
/** | ||
* The `Feature` protocol is used to provide details about geographic features | ||
* contained in a map view’s | ||
* <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile sources</a>. | ||
* Each concrete subclass of `Shape` in turn has a subclass that conforms to | ||
* this protocol. | ||
* <p> | ||
* Typically,you do not create feature objects yourself but rather obtain them | ||
* using{ | ||
* | ||
* @link com.mapbox.mapboxsdk.maps.MapboxMap#getVisibleFeatures(PointF)} | ||
* and related methods.Each feature object associates a shape with an identifier and | ||
* attributes as specified by the source.Like ordinary Annotation objects,some kinds of `Feature` | ||
* objects can also be added to a map view using `-[MGLMapView addAnnotations:]` | ||
* and related methods. | ||
*/ | ||
public interface Feature extends Annotation { | ||
|
||
/** | ||
* A long that uniquely identifies the feature in its containing | ||
* <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>. | ||
* <p> | ||
* The identifier corresponds to the | ||
* <a href="https://github.com/mapbox/vector-tile-spec/tree/master/2.1#42-features">feature identifier</a> | ||
* (`id`) in the tile source. If the source does not specify the feature’s | ||
* identifier, the value of this property is `nil`. If specified, the identifier | ||
* may be an integer, floating-point number, or string. These data types are | ||
* mapped to instances of the following Foundation classes: | ||
* <p> | ||
* For details about the identifiers used in most Mapbox-provided styles, consult | ||
* the | ||
* <a href="https://www.mapbox.com/vector-tiles/mapbox-streets/">Mapbox Streets</a> | ||
* layer reference. | ||
* | ||
* @return the identifier associated with this feature | ||
*/ | ||
long getFeatureId(); | ||
|
||
/** | ||
* A Map of attributes for this feature specified by the | ||
* <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>. | ||
* <p> | ||
* The keys and values of this dictionary are determined by the tile source. In | ||
* the tile source, each attribute name is a string, while each attribute value | ||
* may be a null value, Boolean value, integer, floating-point number, or string. | ||
* These data types are mapped to instances of the following Foundation classes: | ||
* For details about the attribute names and values found in Mapbox-provided | ||
* vector tile sources, consult the | ||
* <a href="https://www.mapbox.com/vector-tiles/mapbox-streets/">Mapbox Streets</a> | ||
* and | ||
* <a href="https://www.mapbox.com/vector-tiles/mapbox-terrain/">Mapbox Terrain</a> | ||
* layer references. | ||
*/ | ||
Map<String, Object> getAttributes(); | ||
|
||
/** | ||
* Returns the feature attribute for the given attribute name. | ||
* <p> | ||
* See the `attributes` property’s documentation for details on keys and values | ||
* associated with this method. | ||
* | ||
* @param key the key associated to the attribute | ||
* @return the | ||
*/ | ||
Object getAttribute(String key); | ||
} |
26 changes: 26 additions & 0 deletions
26
...oid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/FeatureWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mapbox.mapboxsdk.annotations; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FeatureWrapper { | ||
|
||
private List<Feature> features; | ||
|
||
public FeatureWrapper() { | ||
features = new ArrayList<>(); | ||
} | ||
|
||
public void add(Feature feature) { | ||
features.add(feature); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder builder = new StringBuilder(); | ||
for (Feature f : features) { | ||
builder.append("\n").append(f.getClass().getSimpleName()); | ||
} | ||
return builder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPointFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mapbox.mapboxsdk.annotations; | ||
|
||
import java.util.Map; | ||
|
||
public class MultiPointFeature extends MultiPoint implements Feature { | ||
|
||
private long featureId; | ||
private Map<String, Object> attributes; | ||
|
||
public MultiPointFeature() { | ||
} | ||
|
||
@Override | ||
public long getFeatureId() { | ||
return featureId; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
@Override | ||
public Object getAttribute(String key) { | ||
return attributes.get(key); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...droid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPolygon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mapbox.mapboxsdk.annotations; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MultiPolygon extends Shape{ | ||
|
||
private List<Polygon> polygons; | ||
|
||
public MultiPolygon() { | ||
polygons = new ArrayList<>(); | ||
} | ||
|
||
public void addPolygon(Polygon polygon){ | ||
polygons.add(polygon); | ||
} | ||
|
||
public List<Polygon> getPolygons() { | ||
return polygons; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...apboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPolygonFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mapbox.mapboxsdk.annotations; | ||
|
||
import java.util.Map; | ||
|
||
public class MultiPolygonFeature extends MultiPolygon implements Feature{ | ||
private long featureId; | ||
private Map<String, Object> attributes; | ||
|
||
public MultiPolygonFeature() { | ||
} | ||
|
||
@Override | ||
public long getFeatureId() { | ||
return featureId; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
@Override | ||
public Object getAttribute(String key) { | ||
return attributes.get(key); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...roid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPolyline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.mapbox.mapboxsdk.annotations; | ||
|
||
import java.util.List; | ||
|
||
public class MultiPolyline extends Shape { | ||
|
||
private List<Polyline> polylines; | ||
|
||
public MultiPolyline(List<Polyline> polylines) { | ||
this.polylines = polylines; | ||
} | ||
|
||
public List<Polyline> getPolylines() { | ||
return polylines; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...pboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPolylineFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mapbox.mapboxsdk.annotations; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class MultiPolylineFeature extends MultiPolyline implements Feature { | ||
private long featureId; | ||
private Map<String, Object> attributes; | ||
|
||
public MultiPolylineFeature(List<Polyline> polylineList) { | ||
super(polylineList); | ||
} | ||
|
||
@Override | ||
public long getFeatureId() { | ||
return featureId; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
@Override | ||
public Object getAttribute(String key) { | ||
return attributes.get(key); | ||
} | ||
} |
Oops, something went wrong.