Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #352 - migrated Annotation implementation to Shape, reworke…
Browse files Browse the repository at this point in the history
…d package structure
  • Loading branch information
tobrun committed Jul 26, 2016
1 parent ffcb8bc commit ddc9245
Show file tree
Hide file tree
Showing 35 changed files with 185 additions and 405 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.mapbox.mapboxsdk.annotations;

public interface AnnotationDefinition {

}
Original file line number Diff line number Diff line change
@@ -1,73 +1,70 @@
package com.mapbox.mapboxsdk.annotations;

import java.util.HashMap;

import java.util.Map;

/**
* Feature is used to provide details about geographic features
* contained in a map view’s.
* <p>
* 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 `MGLShape` in turn has a subclass that conforms to
* Each concrete subclass of `Shape` in turn has a subclass that conforms to
* this protocol.
* </p>
* <p>
* Typically, you do not create feature objects yourself but rather obtain them
* using `-[MGLMapView visibleFeaturesAtPoint:]` and related methods. Each feature
* object associates a shape with an identifier and attributes as specified by the
* source. Like ordinary `MGLAnnotation` objects, some kinds of `MGLFeature`
* 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 AnnotationDefinition objects,some kinds of `Feature`
* objects can also be added to a map view using `-[MGLMapView addAnnotations:]`
* and related methods.
* </p>
*/
public class Feature {
public interface Feature extends AnnotationDefinition {

/**
* An object that uniquely identifies the feature in its containing
* 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/>
* <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/>
* <table>
* <thead>
* <tr><th>In the tile source</th><th>This property</th></tr>
* </thead>
* <tbody>
* <tr><td>Integer</td> <td><code>NSNumber</code> (use the <code>unsignedLongLongValue</code> or <code>longLongValue</code> property)</td></tr>
* <tr><td>Floating-point number</td> <td><code>NSNumber</code> (use the <code>doubleValue</code> property)</td></tr>
* <tr><td>String</td> <td><code>NSString</code></td></tr>
* </tbody>
* </table>
* <p/>
* <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
*/
private long id = -1;

long getFeatureId();

/**
* A HashMap of attributes for this feature specified by the
* 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/>
* <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.
* <p/>
* <p/>
* 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.
*/
private HashMap<String, Object> attributes = new HashMap<>();

}
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);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* An {@link InfoWindow} can be shown when a Marker is pressed
* </p>
*/
public class Marker extends Annotation {
public class Marker extends Shape {

private LatLng position;
private String snippet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,5 @@
package com.mapbox.mapboxsdk.annotations;

import com.mapbox.mapboxsdk.geometry.LatLng;
public class MultiPoint extends PointCollectionShape {

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

/**
* Multipoint is an abstract annotation for combining geographical locations.
*/
public abstract class MultiPoint extends Annotation {

private List<LatLng> points;
private float alpha = 1.0f;

protected MultiPoint() {
super();
points = new ArrayList<>();
}

/**
* Returns a copy of the points.
*
* @return points - as a copy
*/
public List<LatLng> getPoints() {
return new ArrayList<>(points);
}

/**
* Sets the points of this polyline. This method will take a copy
* of the points, so further mutations to points will have no effect
* on this polyline.
*
* @param points the points of the polyline
*/
void setPoints(List<LatLng> points) {
this.points = new ArrayList<>(points);
}

void addPoint(LatLng point) {
points.add(point);
}

public float getAlpha() {
return alpha;
}

void setAlpha(float alpha) {
this.alpha = alpha;
}
}
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 MultiPolygon extends Shape{

private List<Polygon> polygons;

public MultiPolygon(List<Polygon> polygons) {
this.polygons = polygons;
}

public List<Polygon> getPolygons() {
return polygons;
}
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.mapbox.mapboxsdk.annotations;

import com.mapbox.mapboxsdk.geometry.LatLng;

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

public abstract class PointCollectionShape extends Shape {

private List<LatLng> points;
private float alpha = 1.0f;

protected PointCollectionShape() {
super();
points = new ArrayList<>();
}

/**
* Returns a copy of the points.
*
* @return points - as a copy
*/
public List<LatLng> getPoints() {
return new ArrayList<>(points);
}

/**
* Sets the points of this polyline. This method will take a copy
* of the points, so further mutations to points will have no effect
* on this polyline.
*
* @param points the points of the polyline
*/
void setPoints(List<LatLng> points) {
this.points = new ArrayList<>(points);
}

void addPoint(LatLng point) {
points.add(point);
}

public float getAlpha() {
return alpha;
}

void setAlpha(float alpha) {
this.alpha = alpha;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Polygon is a geometry annotation that's a closed loop of coordinates.
*/
public final class Polygon extends MultiPoint {
public final class Polygon extends PointCollectionShape {

private int fillColor = Color.BLACK; // default fillColor is black
private int strokeColor = Color.BLACK; // default strokeColor is black
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Polyline is a geometry feature with an unclosed list of coordinates drawn as a line
*/
public final class Polyline extends MultiPoint {
public final class Polyline extends PointCollectionShape {

private int color = Color.BLACK; // default color is black
private float width = 10; // As specified by Google API Docs (in pixels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
public final class PolylineOptions implements Parcelable {


public static final Parcelable.Creator<PolylineOptions> CREATOR
= new Parcelable.Creator<PolylineOptions>() {
public PolylineOptions createFromParcel(Parcel in) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* content to be placed at a geographical point.
* </p>
*/
public abstract class Annotation implements Comparable<Annotation> {
public abstract class Shape implements AnnotationDefinition, Comparable<Shape> {

/**
* <p>
Expand All @@ -25,7 +25,7 @@ public abstract class Annotation implements Comparable<Annotation> {
protected MapboxMap mapboxMap;
protected MapView mapView;

protected Annotation() {
protected Shape() {
}

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ protected MapView getMapView() {
}

@Override
public int compareTo(@NonNull Annotation annotation) {
public int compareTo(@NonNull Shape annotation) {
if (id < annotation.getId()) {
return 1;
} else if (id > annotation.getId()) {
Expand All @@ -98,8 +98,8 @@ public int compareTo(@NonNull Annotation annotation) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof Annotation)) return false;
Annotation that = (Annotation) o;
if (o == null || !(o instanceof Shape)) return false;
Shape that = (Shape) o;
return id == that.getId();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mapbox.mapboxsdk.annotations;

import java.util.List;

/**
* The `MGLShapeCollection` class represents a shape consisting of one or more
* distinct but related shapes that are instances of `MGLShape`. The constituent
* shapes can be a mixture of different kinds of shapes.
* <p>
* `ShapeCollection` objects cannot be added to a map view using
* {@link com.mapbox.mapboxsdk.maps.MapboxMap#addAnnotations} and related methods.
* </p>
*/
public class ShapeCollection extends Shape {

private List<Shape> shapes;

public ShapeCollection(List<Shape> shapes) {
this.shapes = shapes;
}

public List<Shape> getShapes() {
return shapes;
}
}
Loading

0 comments on commit ddc9245

Please sign in to comment.