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

Commit

Permalink
[android] Cleaned up documentation; fixed build
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Dec 13, 2016
1 parent c356dd7 commit 774a2aa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
public abstract class MultiPoint extends Annotation {

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

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

/**
Expand All @@ -29,14 +27,6 @@ public List<LatLng> getPoints() {
return new ArrayList<>(points);
}

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

/**
* 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.
Expand All @@ -58,10 +48,6 @@ public void addPoint(LatLng point) {
update();
}

void addHole(List<LatLng> hole) {
holes.add(hole);
}

/**
* Value between 0 and 1 defining the polyline alpha.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,48 @@

import android.graphics.Color;

import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;

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

/**
* Polygon is a geometry annotation that's a closed loop of coordinates.
*/
public final class Polygon extends MultiPoint {

private List<List<LatLng>> holes;
private int fillColor = Color.BLACK; // default fillColor is black
private int strokeColor = Color.BLACK; // default strokeColor is black

Polygon() {
super();
holes = new ArrayList<>();
}

/**
* Returns a copy of the holes.
*
* @return A {@link List} of holes.
*/
public List<List<LatLng>> getHoles() {
return new ArrayList<>(holes);
}

/**
* Sets the holes of this polygon. This method will take a copy of the holes, so further
* mutations to holes will have no effect on this polygon.
*
* @param points A {@link List} {@link List}s of {@link LatLng} points making up the holes.
*/
public void setHoles(List<? extends List<LatLng>> holes) {
this.holes = new ArrayList<>(holes);
update();
}

void addHole(List<LatLng> hole) {
holes.add(hole);
}

/**
Expand All @@ -26,7 +56,7 @@ public int getFillColor() {
}

/**
* Get the color fo the stroke of the polygon.
* Get the color for the stroke of the polygon.
*
* @return The color of the stroke.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,20 @@ public PolygonOptions addAll(Iterable<LatLng> points) {
}
return this;
}

/**
* Adds a hole to the outline of the polygon being built.
*
* @param points {@link Iterable} list made up of {@link LatLng} points defining the hole
* @return This {@link PolygonOptions} object with the given hole added to the outline.
*/
public PolygonOptions addHole(Iterable<LatLng> points) {
List<LatLng> hole = new ArrayList<LatLng>();
for (LatLng point : points) {
hole.add(point);
}

polygon.addHole(hole);

return this;
}

Expand Down Expand Up @@ -193,17 +198,20 @@ public List<LatLng> getPoints() {
return polygon.getPoints();
}

/**
* Gets the holes set for this {@link PolygonOptions} object.
*/
public List<List<LatLng>> getHoles() {
return polygon.getHoles();
}

/**
* Compares this {@link PolygonOptions} object with another {@link PolygonOptions} and
* determines if their color, alpha, stroke color, and vertices match.
* determines if their color, alpha, stroke color, vertices, and holes match.
*
* @param o Another {@link PolygonOptions} to compare with this object.
* @return True if color, alpha, stroke color, and vertices match this {@link PolygonOptions}
* object. Else, false.
* @return True if color, alpha, stroke color, vertices, and holes match this
* {@link PolygonOptions} object. Else, false.
*/
@Override
public boolean equals(Object o) {
Expand All @@ -215,8 +223,8 @@ public boolean equals(Object o) {
if (Float.compare(polygon.getAlpha(), getAlpha()) != 0) return false;
if (getFillColor() != polygon.getFillColor()) return false;
if (getStrokeColor() != polygon.getStrokeColor()) return false;
if (getHoles() != null ? !getHoles().equals(polygon.getHoles()) : polygon.getHoles() != null) return false;
return !(getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null);
if (getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null) return false;
return !(getHoles() != null ? !getHoles().equals(polygon.getHoles()) : polygon.getHoles() != null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
hole3.add(new LatLng(lat, lon - 0.005));
hole3.add(new LatLng(lat, lon));

polygon.addHole(hole1)
.addHole(hole2)
.addHole(hole3);
List<List<LatLng>> holes = new ArrayList<>();
holes.add(hole1);
holes.add(hole2);
holes.add(hole3);
polygon.setHoles(holes);

return true;

Expand Down
4 changes: 2 additions & 2 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ jni::jarray<jlong>* nativeAddPolygons(JNIEnv *env, jni::jobject* obj, jlong nati
NullCheck(*env, jarrayHoles);

std::size_t size = jni::GetArrayLength(*env, *jarrayHoles);
for (std::size_t i = 0; i < size; i++) {
jni::jobject* hole = reinterpret_cast<jni::jobject*>(jni::GetObjectArrayElement(*env, *jarrayHoles, i));
for (std::size_t j = 0; j < size; j++) {
jni::jobject* hole = reinterpret_cast<jni::jobject*>(jni::GetObjectArrayElement(*env, *jarrayHoles, j));
NullCheck(*env, hole);
geometry.push_back(toGeometry<mbgl::LinearRing<double>>(env, hole));
jni::DeleteLocalRef(*env, hole);
Expand Down

0 comments on commit 774a2aa

Please sign in to comment.