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

Commit

Permalink
refs #5238: back of out JNI-plumbed approach and just opportunistical…
Browse files Browse the repository at this point in the history
…ly insert into view invalidation list
  • Loading branch information
incanus committed Aug 2, 2016
1 parent fb4e607 commit 91e3ab5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
protected String snippet;
protected String title;
protected Icon icon;
protected MarkerView aboveMarkerView;
protected boolean flat;
protected float anchorU = 0.5f;
protected float anchorV = 1f;
Expand Down Expand Up @@ -81,6 +82,17 @@ public T icon(Icon icon) {
return getThis();
}

/**
* Set the MarkerView above which this MarkerView is shown.
*
* @param aboveMarkerView the MarkerView above which to show
* @return the object for which the method was called
*/
public T aboveMarkerView(MarkerView aboveMarkerView) {
this.aboveMarkerView = aboveMarkerView;
return getThis();
}

/**
* Set the flat state of the MarkerView.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class MarkerView extends Marker {

private Icon markerViewIcon;

private MarkerView aboveMarkerView;

private boolean selected;

/**
Expand All @@ -71,6 +73,7 @@ public MarkerView(BaseMarkerViewOptions baseMarkerViewOptions) {
this.anchorU = baseMarkerViewOptions.anchorU;
this.anchorV = baseMarkerViewOptions.anchorV;
this.selected = baseMarkerViewOptions.selected;
this.aboveMarkerView = baseMarkerViewOptions.aboveMarkerView;
}

/**
Expand Down Expand Up @@ -329,6 +332,8 @@ public Icon getIcon() {
return markerViewIcon;
}

public MarkerView getAboveMarkerView() { return aboveMarkerView; }

/**
* Set the MapboxMap associated tot the MapView containing the MarkerView.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,14 +1050,10 @@ private void ensureIconLoaded(Marker marker) {
}

long addMarker(@NonNull Marker marker) {
return addMarker(marker, null);
}

long addMarker(@NonNull Marker marker, MarkerView aboveMarker) {
if (mDestroyed) {
return 0l;
}
return mNativeMapView.addMarker(marker, aboveMarker);
return mNativeMapView.addMarker(marker);
}

long[] addMarkers(@NonNull List<Marker> markerList) {
Expand Down Expand Up @@ -1154,7 +1150,16 @@ public List<MarkerView> getMarkerViewsInBounds(@NonNull LatLngBounds bbox) {
for (int i = 0; i < count; i++) {
Annotation annotation = annotationList.get(i);
if (annotation instanceof MarkerView) {
annotations.add((MarkerView) annotation);
MarkerView aboveMarkerView = ((MarkerView) annotation).getAboveMarkerView();
int index = -1;
if (aboveMarkerView != null) {
index = annotations.indexOf(aboveMarkerView);
}
if (index != -1) {
annotations.add(index + 1, (MarkerView) annotation);
} else {
annotations.add((MarkerView) annotation);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,26 +736,9 @@ public Marker addMarker(@NonNull BaseMarkerOptions markerOptions) {
@UiThread
@NonNull
public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions) {
return addMarker(markerOptions, null);
}

/**
* <p>
* Adds a marker to this map above an existing marker.
* </p>
* The marker's icon is rendered on the map at the location {@code Marker.position}.
* If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet.
*
* @param markerOptions A marker options object that defines how to render the marker.
* @param aboveMarker An existing map marker on top of which to add the new marker.
* @return The {@code Marker} that was added to the map.
*/
@UiThread
@NonNull
public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions, MarkerView aboveMarker) {
MarkerView marker = prepareViewMarker(markerOptions);
marker.setMapboxMap(this);
long id = mMapView.addMarker(marker, aboveMarker);
long id = mMapView.addMarker(marker);
marker.setId(id);
mAnnotations.put(id, marker);
mMarkerViewManager.invalidateViewMarkersInBounds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,12 @@ public void resetNorth() {
}

public long addMarker(Marker marker) {
return addMarker(marker, null);
}

public long addMarker(Marker marker, Marker aboveMarker) {
Marker[] markers = {marker};
return nativeAddMarkers(mNativeMapViewPtr, markers, aboveMarker)[0];
return nativeAddMarkers(mNativeMapViewPtr, markers)[0];
}

public long[] addMarkers(List<Marker> markers) {
return nativeAddMarkers(mNativeMapViewPtr, markers.toArray(new Marker[markers.size()]), null);
return nativeAddMarkers(mNativeMapViewPtr, markers.toArray(new Marker[markers.size()]));
}

public long addPolyline(Polyline polyline) {
Expand Down Expand Up @@ -625,7 +621,7 @@ private native void nativeSetBearingXY(long nativeMapViewPtr, double degrees,

private native void nativeUpdateMarker(long nativeMapViewPtr, long markerId, double lat, double lon, String iconId);

private native long[] nativeAddMarkers(long mNativeMapViewPtr, Marker[] markers, Marker aboveMarker);
private native long[] nativeAddMarkers(long mNativeMapViewPtr, Marker[] markers);

private native long[] nativeAddPolylines(long mNativeMapViewPtr, Polyline[] polylines);

Expand Down
7 changes: 2 additions & 5 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,14 @@ void nativeUpdateMarker(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr,
nativeMapView->getMap().updateAnnotation(markerId, mbgl::SymbolAnnotation { mbgl::Point<double>(lon, lat), iconId });
}

jni::jarray<jlong>* nativeAddMarkers(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jarray<jni::jobject>* jarray, jni::jobject* aboveMarker) {
jni::jarray<jlong>* nativeAddMarkers(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jarray<jni::jobject>* jarray) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddMarkers");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);

NullCheck(*env, jarray);
std::size_t len = jni::GetArrayLength(*env, *jarray);

// Only allow relative placement for single markers.
assert(len == 1 || aboveMarker == nullptr);

std::vector<mbgl::AnnotationID> ids;
ids.reserve(len);

Expand Down Expand Up @@ -1759,7 +1756,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
MAKE_NATIVE_METHOD(nativeSetBearingXY, "(JDDD)V"),
MAKE_NATIVE_METHOD(nativeGetBearing, "(J)D"),
MAKE_NATIVE_METHOD(nativeResetNorth, "(J)V"),
MAKE_NATIVE_METHOD(nativeAddMarkers, "(J[Lcom/mapbox/mapboxsdk/annotations/Marker;Lcom/mapbox/mapboxsdk/annotations/Marker;)[J"),
MAKE_NATIVE_METHOD(nativeAddMarkers, "(J[Lcom/mapbox/mapboxsdk/annotations/Marker;)[J"),
MAKE_NATIVE_METHOD(nativeAddPolylines, "(J[Lcom/mapbox/mapboxsdk/annotations/Polyline;)[J"),
MAKE_NATIVE_METHOD(nativeAddPolygons, "(J[Lcom/mapbox/mapboxsdk/annotations/Polygon;)[J"),
MAKE_NATIVE_METHOD(nativeUpdateMarker, "(JJDDLjava/lang/String;)V"),
Expand Down

0 comments on commit 91e3ab5

Please sign in to comment.