Merge branch 'master' of github.com:mapbox/mapbox-gl-native
This commit is contained in:
@@ -821,6 +821,73 @@ jlong JNICALL nativeAddMarker(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
|
||||
return nativeMapView->getMap().addPointAnnotation(mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), sprite));
|
||||
}
|
||||
|
||||
jlongArray JNICALL nativeAddMarkers(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject jlist) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddMarkers");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
|
||||
std::vector<mbgl::PointAnnotation> markers;
|
||||
|
||||
if (jlist == nullptr) {
|
||||
if (env->ThrowNew(nullPointerExceptionClass, "List cannot be null.") < 0) {
|
||||
env->ExceptionDescribe();
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jobjectArray jarray =
|
||||
reinterpret_cast<jobjectArray>(env->CallObjectMethod(jlist, listToArrayId));
|
||||
if (env->ExceptionCheck() || (jarray == nullptr)) {
|
||||
env->ExceptionDescribe();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jsize len = env->GetArrayLength(jarray);
|
||||
if (len < 0) {
|
||||
env->ExceptionDescribe();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
markers.reserve(len);
|
||||
|
||||
for (jsize i = 0; i < len; i++) {
|
||||
jobject marker = reinterpret_cast<jobject>(env->GetObjectArrayElement(jarray, i));
|
||||
|
||||
jobject position = env->GetObjectField(marker, markerPositionId);
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jstring jsprite = reinterpret_cast<jstring>(env->GetObjectField(marker, markerSpriteId));
|
||||
std::string sprite = std_string_from_jstring(env, jsprite);
|
||||
|
||||
jdouble latitude = env->GetDoubleField(position, latLngLatitudeId);
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jdouble longitude = env->GetDoubleField(position, latLngLongitudeId);
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
markers.emplace_back(mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), sprite));
|
||||
|
||||
/* Do I need to delete other LocalRefs? */
|
||||
env->DeleteLocalRef(marker);
|
||||
}
|
||||
|
||||
env->DeleteLocalRef(jarray);
|
||||
|
||||
std::vector<uint32_t> pointAnnotationIDs = nativeMapView->getMap().addPointAnnotations(markers);
|
||||
return std_vector_uint_to_jobject(env, pointAnnotationIDs);
|
||||
}
|
||||
|
||||
|
||||
jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polyline) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolyline");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
@@ -1689,6 +1756,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
{"nativeResetNorth", "(J)V", reinterpret_cast<void *>(&nativeResetNorth)},
|
||||
{"nativeAddMarker", "(JLcom/mapbox/mapboxgl/annotations/Marker;)J",
|
||||
reinterpret_cast<void *>(&nativeAddMarker)},
|
||||
{"nativeAddMarkers", "(JLjava/util/List;)[J",
|
||||
reinterpret_cast<void *>(&nativeAddMarkers)},
|
||||
{"nativeAddPolyline", "(JLcom/mapbox/mapboxgl/annotations/Polyline;)J",
|
||||
reinterpret_cast<void *>(&nativeAddPolyline)},
|
||||
{"nativeAddPolygon", "(JLcom/mapbox/mapboxgl/annotations/Polygon;)J",
|
||||
|
||||
@@ -1057,6 +1057,19 @@ public class MapView extends FrameLayout implements LocationListener, CompassVie
|
||||
return marker;
|
||||
}
|
||||
|
||||
public List<Marker> addMarkers(List<Marker> markers){
|
||||
long[] ids = mNativeMapView.addMarkers(markers);
|
||||
Marker m;
|
||||
int count = markers.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
m = markers.get(i);
|
||||
m.setId(ids[i]);
|
||||
m.setMapView(this);
|
||||
mAnnotations.add(m);
|
||||
}
|
||||
return markers;
|
||||
}
|
||||
|
||||
public Polyline addPolyline(PolylineOptions polylineOptions) {
|
||||
Polyline polyline = polylineOptions.getPolyline();
|
||||
long id = mNativeMapView.addPolyline(polyline);
|
||||
|
||||
@@ -333,6 +333,10 @@ class NativeMapView {
|
||||
return nativeAddMarker(mNativeMapViewPtr, marker);
|
||||
}
|
||||
|
||||
public long[] addMarkers(List<Marker> markers) {
|
||||
return nativeAddMarkers(mNativeMapViewPtr, markers);
|
||||
}
|
||||
|
||||
public long addPolyline(Polyline polyline) {
|
||||
return nativeAddPolyline(mNativeMapViewPtr, polyline);
|
||||
}
|
||||
@@ -561,6 +565,8 @@ class NativeMapView {
|
||||
|
||||
private native long nativeAddMarker(long nativeMapViewPtr, Marker marker);
|
||||
|
||||
private native long[] nativeAddMarkers(long nativeMapViewPtr, List<Marker> markers);
|
||||
|
||||
private native long nativeAddPolyline(long nativeMapViewPtr, Polyline polyline);
|
||||
|
||||
private native long nativeAddPolygon(long mNativeMapViewPtr, Polygon polygon);
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@@ -404,26 +405,34 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void addMarkers() {
|
||||
LatLng backLot = new LatLng(38.649441, -121.369064);
|
||||
final Marker marker = mMapView.addMarker(new MarkerOptions()
|
||||
.position(backLot)
|
||||
.title("Back Lot")
|
||||
.snippet("The back lot behind my house"));
|
||||
marker.setInfoWindowOnTouchListener(new View.OnTouchListener() {
|
||||
List<Marker> markerList = new ArrayList<>();
|
||||
|
||||
final Marker backLot = generateMarker("Back Lot", "The back lot behind my house", "default_marker", 38.649441, -121.369064);
|
||||
markerList.add(backLot);
|
||||
|
||||
final Marker cheeseRoom = generateMarker("Cheese Room", "The only air conditioned room on the property", "dog-park-15", 38.531577, -122.010646);
|
||||
markerList.add(cheeseRoom);
|
||||
|
||||
mMapView.addMarkers(markerList);
|
||||
|
||||
// need to call this after adding markers to map, click event hook into InfoWindow needs refactoring
|
||||
backLot.setInfoWindowOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
Toast.makeText(getApplicationContext(), "Custom Info Touch Listener!!", Toast.LENGTH_SHORT).show();
|
||||
marker.hideInfoWindow();
|
||||
backLot.hideInfoWindow();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
LatLng cheeseRoom = new LatLng(38.531577,-122.010646);
|
||||
mMapView.addMarker(new MarkerOptions()
|
||||
.position(cheeseRoom)
|
||||
.sprite("dog-park-15")
|
||||
.title("Cheese Room")
|
||||
.snippet("The only air conditioned room on the property!"));
|
||||
private Marker generateMarker(String title, String snippet, String sprite, double lat, double lng){
|
||||
return new MarkerOptions()
|
||||
.position(new LatLng(lat,lng))
|
||||
.title(title)
|
||||
.sprite(sprite)
|
||||
.snippet(snippet)
|
||||
.getMarker();
|
||||
}
|
||||
|
||||
private void addPolyline() {
|
||||
|
||||
Reference in New Issue
Block a user