Merge branch 'android-annotations' of git://github.com/TrueFlow/mapbox-gl-native into TrueFlow-android-annotations
This commit is contained in:
@@ -23,7 +23,7 @@ public abstract class Annotation {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,17 +49,6 @@ public class Marker extends Annotation {
|
||||
return anchorV;
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: Google Maps Android API uses String for IDs.
|
||||
*
|
||||
* Internal C++ id is stored as unsigned int.
|
||||
*
|
||||
* @return the annotation id
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public LatLng getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
@@ -41,6 +42,8 @@ import com.mapbox.mapboxgl.geometry.LatLngZoom;
|
||||
|
||||
import org.apache.commons.validator.routines.UrlValidator;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -216,6 +219,16 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
}
|
||||
|
||||
public void setSprite(String symbol, float scale, Bitmap bitmap) {
|
||||
if(bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
|
||||
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
|
||||
bitmap.copyPixelsToBuffer(buffer);
|
||||
|
||||
mNativeMapView.setSprite(symbol, bitmap.getWidth(), bitmap.getHeight(), scale, buffer.array());
|
||||
}
|
||||
|
||||
public Marker addMarker(MarkerOptions markerOptions) {
|
||||
Marker marker = markerOptions.getMarker();
|
||||
Long id = mNativeMapView.addMarker(marker);
|
||||
@@ -243,6 +256,23 @@ public class MapView extends SurfaceView {
|
||||
return polygon;
|
||||
}
|
||||
|
||||
public List<Polygon> addPolygons(List<PolygonOptions> polygonOptions) {
|
||||
List<Polygon> polygons = new ArrayList<>();
|
||||
for(PolygonOptions popts : polygonOptions) {
|
||||
polygons.add(popts.getPolygon());
|
||||
}
|
||||
|
||||
long[] ids = mNativeMapView.addPolygons(polygons);
|
||||
|
||||
for(int i=0; i<polygons.size(); i++) {
|
||||
polygons.get(i).setId(ids[i]);
|
||||
polygons.get(i).setMapView(this);
|
||||
annotations.add(polygons.get(i));
|
||||
}
|
||||
|
||||
return polygons;
|
||||
}
|
||||
|
||||
public void removeAnnotation(Annotation annotation) {
|
||||
long id = annotation.getId();
|
||||
mNativeMapView.removeAnnotation(id);
|
||||
@@ -253,9 +283,16 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
|
||||
public void removeAnnotations() {
|
||||
for (Annotation annotation : annotations) {
|
||||
annotation.remove();
|
||||
long[] ids = new long[annotations.size()];
|
||||
for(int i=0; i<annotations.size(); i++) {
|
||||
Long id = annotations.get(i).getId();
|
||||
if(id == null) {
|
||||
ids[i] = -1;
|
||||
} else {
|
||||
ids[i] = id;
|
||||
}
|
||||
}
|
||||
mNativeMapView.removeAnnotations(ids);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -177,7 +177,7 @@ class NativeMapView {
|
||||
}
|
||||
|
||||
public void setStyleJson(String newStyleJson) {
|
||||
setStyleJson(newStyleJson, "");
|
||||
setStyleJson(newStyleJson, "");
|
||||
}
|
||||
|
||||
public void setStyleJson(String newStyleJson, String base) {
|
||||
@@ -216,6 +216,10 @@ class NativeMapView {
|
||||
nativeSetLatLng(mNativeMapViewPtr, latLng, duration);
|
||||
}
|
||||
|
||||
public void setSprite(String symbol, int width, int height, float scale, byte[] pixels) {
|
||||
nativeSetSprite(mNativeMapViewPtr, symbol, width, height, scale, pixels);
|
||||
}
|
||||
|
||||
public long addMarker(Marker marker) {
|
||||
return nativeAddMarker(mNativeMapViewPtr, marker);
|
||||
}
|
||||
@@ -230,10 +234,19 @@ class NativeMapView {
|
||||
return nativeAddPolygon(mNativeMapViewPtr, polygon);
|
||||
}
|
||||
|
||||
public long[] addPolygons(List<Polygon> polygon) {
|
||||
// NH TODO Throw exception if returns -1
|
||||
return nativeAddPolygons(mNativeMapViewPtr, polygon);
|
||||
}
|
||||
|
||||
public void removeAnnotation(long id) {
|
||||
nativeRemoveAnnotation(mNativeMapViewPtr, id);
|
||||
}
|
||||
|
||||
public void removeAnnotations(long[] ids) {
|
||||
nativeRemoveAnnotations(mNativeMapViewPtr, ids);
|
||||
}
|
||||
|
||||
public LatLng getLatLng() {
|
||||
return nativeGetLatLng(mNativeMapViewPtr);
|
||||
}
|
||||
@@ -466,14 +479,21 @@ class NativeMapView {
|
||||
private native void nativeSetLatLng(long nativeMapViewPtr, LatLng latLng,
|
||||
long duration);
|
||||
|
||||
private native void nativeSetSprite(long nativeMapViewPtr, String symbol,
|
||||
int width, int height, float scale, byte[] pixels);
|
||||
|
||||
private native long nativeAddMarker(long nativeMapViewPtr, Marker marker);
|
||||
|
||||
private native long nativeAddPolyline(long nativeMapViewPtr, Polyline polyline);
|
||||
|
||||
private native long nativeAddPolygon(long mNativeMapViewPtr, Polygon polygon);
|
||||
|
||||
private native long[] nativeAddPolygons(long mNativeMapViewPtr, List<Polygon> polygon);
|
||||
|
||||
private native void nativeRemoveAnnotation(long nativeMapViewPtr, long id);
|
||||
|
||||
private native void nativeRemoveAnnotations(long nativeMapViewPtr, long[] id);
|
||||
|
||||
private native LatLng nativeGetLatLng(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeResetPosition(long nativeMapViewPtr);
|
||||
|
||||
@@ -330,10 +330,12 @@ public class MainActivity extends ActionBarActivity {
|
||||
geojsonStr = Util.loadStringFromAssets(this, "small_poly.geojson");
|
||||
LatLng[] latLngs = Util.parseGeoJSONCoordinates(geojsonStr);
|
||||
MapView map = mMapFragment.getMap();
|
||||
Polygon polygon = map.addPolygon(new PolygonOptions()
|
||||
.add(latLngs)
|
||||
.strokeColor(Color.MAGENTA)
|
||||
.fillColor(Color.BLUE));
|
||||
ArrayList<PolygonOptions> opts = new ArrayList<PolygonOptions>();
|
||||
opts.add(new PolygonOptions()
|
||||
.add(latLngs)
|
||||
.strokeColor(Color.MAGENTA)
|
||||
.fillColor(Color.BLUE));
|
||||
Polygon polygon = map.addPolygons(opts).get(0);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
|
||||
Reference in New Issue
Block a user