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

5663 updatable shape annotations #5848

Merged
merged 1 commit into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,24 @@ public List<LatLng> getPoints() {
*
* @param points the points of the polyline
*/
void setPoints(List<LatLng> points) {
public void setPoints(List<LatLng> points) {
this.points = new ArrayList<>(points);
update();
}

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

public float getAlpha() {
return alpha;
}

void setAlpha(float alpha) {
public void setAlpha(float alpha) {
this.alpha = alpha;
update();
}

abstract void update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import android.graphics.Color;

import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.ArrayList;
import java.util.List;
import com.mapbox.mapboxsdk.maps.MapboxMap;

/**
* Polygon is a geometry annotation that's a closed loop of coordinates.
Expand All @@ -19,19 +16,49 @@ public final class Polygon extends MultiPoint {
super();
}

/**
* Get the color of the fill region of the polygon.
*
* @return the color of the fill
*/
public int getFillColor() {
return fillColor;
}

/**
* Get the color fo the stroke of the polygon.
*
* @return the color of the stroke
*/
public int getStrokeColor() {
return strokeColor;
}

void setFillColor(int color) {
/**
* Sets the color of the fill region of the polygon.
*
* @param color - the color in ARGB format
*/
public void setFillColor(int color) {
fillColor = color;
update();
}

void setStrokeColor(int color) {
/**
* Sets the color of the stroke of the polygon.
*
* @param color - the color in ARGB format
*/
public void setStrokeColor(int color) {
strokeColor = color;
update();
}

@Override
void update() {
MapboxMap mapboxMap = getMapboxMap();
if (mapboxMap != null) {
mapboxMap.updatePolygon(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.graphics.Color;

import com.mapbox.mapboxsdk.maps.MapboxMap;

/**
* Polyline is a geometry feature with an unclosed list of coordinates drawn as a line
*/
Expand All @@ -14,10 +16,20 @@ public final class Polyline extends MultiPoint {
super();
}

/**
* Returns the Polyline tint color.
*
* @return the tint color
*/
public int getColor() {
return color;
}

/**
* Returns the Polyline width.
*
* @return the width
*/
public float getWidth() {
return width;
}
Expand All @@ -27,16 +39,26 @@ public float getWidth() {
*
* @param color - the color in ARGB format
*/
void setColor(int color) {
public void setColor(int color) {
this.color = color;
update();
}

/**
* Sets the width of the polyline.
*
* @param width in pixels
*/
void setWidth(float width) {
public void setWidth(float width) {
this.width = width;
update();
}

@Override
void update() {
MapboxMap mapboxMap = getMapboxMap();
if (mapboxMap != null) {
mapboxMap.updatePolyline(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ void updateMarker(@NonNull Marker updatedMarker) {

if (updatedMarker.getId() == -1) {
Log.w(MapboxConstants.TAG, "marker has an id of -1, possibly was not added yet, doing nothing");
return;
}

if (!(updatedMarker instanceof MarkerView)) {
Expand All @@ -1025,6 +1026,43 @@ void updateMarker(@NonNull Marker updatedMarker) {
mNativeMapView.updateMarker(updatedMarker);
}


void updatePolygon(Polygon polygon) {
if (mDestroyed) {
return;
}

if (polygon == null) {
Log.w(MapboxConstants.TAG, "polygon was null, doing nothing");
return;
}

if (polygon.getId() == -1) {
Log.w(MapboxConstants.TAG, "polygon has an id of -1, indicating the polygon was not added to the map yet.");
return;
}

mNativeMapView.updatePolygon(polygon);
}

void updatePolyline(Polyline polyline) {
if (mDestroyed) {
return;
}

if (polyline == null) {
Log.w(MapboxConstants.TAG, "polygon was null, doing nothing");
return;
}

if (polyline.getId() == -1) {
Log.w(MapboxConstants.TAG, "polygon has an id of -1, indicating the polygon was not added to the map yet.");
return;
}

mNativeMapView.updatePolyline(polyline);
}

private void ensureIconLoaded(Marker marker) {
Icon icon = marker.getIcon();
if (icon == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,36 @@ public void updateMarker(@NonNull Marker updatedMarker) {
}
}

/**
* Update a polygon on this map.
*
* @param polygon An updated polygon object.
*/
@UiThread
public void updatePolygon(Polygon polygon) {
mMapView.updatePolygon(polygon);

int index = mAnnotations.indexOfKey(polygon.getId());
if (index > -1) {
mAnnotations.setValueAt(index, polygon);
}
}

/**
* Update a polyline on this map.
*
* @param polyline An updated polyline object.
*/
@UiThread
public void updatePolyline(Polyline polyline) {
mMapView.updatePolyline(polyline);

int index = mAnnotations.indexOfKey(polyline.getId());
if (index > -1) {
mAnnotations.setValueAt(index, polyline);
}
}

/**
* Adds a polyline to this map.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,18 @@ public void updateMarker(Marker marker) {
nativeUpdateMarker(mNativeMapViewPtr, marker.getId(), position.getLatitude(), position.getLongitude(), icon.getId());
}

public void updatePolygon(Polygon polygon) {
//TODO remove new id assignment, https://github.com/mapbox/mapbox-gl-native/issues/5844
long newId = nativeUpdatePolygon(mNativeMapViewPtr, polygon.getId(), polygon);
polygon.setId(newId);
}

public void updatePolyline(Polyline polyline) {
//TODO remove new id assignment, https://github.com/mapbox/mapbox-gl-native/issues/5844
long newId = nativeUpdatePolyline(mNativeMapViewPtr, polyline.getId(), polyline);
polyline.setId(newId);
}

public void removeAnnotation(long id) {
long[] ids = {id};
removeAnnotations(ids);
Expand Down Expand Up @@ -670,4 +682,8 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat
private native void nativeAddSource(long mNativeMapViewPtr, String id, Source source);

private native void nativeRemoveSource(long mNativeMapViewPtr, String sourceId);

private native long nativeUpdatePolygon(long nativeMapViewPtr, long polygonId, Polygon polygon);

private native long nativeUpdatePolyline(long nativeMapviewPtr, long polylineId, Polyline polyline);
}
Loading