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

Commit

Permalink
[android] #352 - rework annotations inheritance, added feature concept
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 31, 2016
1 parent 472ab74 commit 414206c
Show file tree
Hide file tree
Showing 28 changed files with 857 additions and 155 deletions.
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));
}
}
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);
}
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();
}
}
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
Expand Up @@ -5,10 +5,7 @@
import java.util.ArrayList;
import java.util.List;

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

private List<LatLng> points;
private float alpha = 1.0f;
Expand Down
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);
}

}
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;
}
}
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);
}
}
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,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);
}
}
Loading

0 comments on commit 414206c

Please sign in to comment.