Skip to content

Commit

Permalink
fix: add poi-click listener to map instance
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Jul 13, 2019
1 parent 6b22c99 commit 5e6f870
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
33 changes: 23 additions & 10 deletions android/src/ti/map/TiUIMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public void onMapReady(GoogleMap gMap)
map.setOnMapLongClickListener(this);
map.setOnMapLoadedCallback(this);
map.setOnMyLocationChangeListener(this);
map.setOnPoiClickListener(this);
mClusterManager.setOnClusterClickListener(this);
mClusterManager.setOnClusterItemClickListener(this);

Expand Down Expand Up @@ -269,22 +270,18 @@ public void processMapProperties(KrollDict d)
Object[] annotations = (Object[]) d.get(TiC.PROPERTY_ANNOTATIONS);
addAnnotations(annotations);
}

if (d.containsKey(MapModule.PROPERTY_POLYGONS)) {
Object[] polygons = (Object[]) d.get(MapModule.PROPERTY_POLYGONS);
addPolygons(polygons);
}

if (d.containsKey(MapModule.PROPERTY_POLYLINES)) {
Object[] polylines = (Object[]) d.get(MapModule.PROPERTY_POLYLINES);
addPolylines(polylines);
}

if (d.containsKey(MapModule.PROPERTY_CIRCLES)) {
Object[] circles = (Object[]) d.get(MapModule.PROPERTY_CIRCLES);
addCircles(circles);
}

if (d.containsKey(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) {
setZoomControlsEnabled(TiConvert.toBoolean(d, TiC.PROPERTY_ENABLE_ZOOM_CONTROLS, true));
}
Expand All @@ -303,6 +300,9 @@ public void processMapProperties(KrollDict d)
if (d.containsKey(MapModule.PROPERTY_INDOOR_ENABLED)) {
setIndoorEnabled(d.getBoolean(MapModule.PROPERTY_INDOOR_ENABLED));
}
if (d.containsKey(TiC.PROPERTY_PADDING)) {
setPadding(d.getKrollDict(TiC.PROPERTY_PADDING));
}
}

@Override
Expand Down Expand Up @@ -341,6 +341,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
setStyle(TiConvert.toString(newValue, ""));
} else if (key.equals(MapModule.PROPERTY_INDOOR_ENABLED)) {
setIndoorEnabled(TiConvert.toBoolean(newValue, true));
} else if (key.equals(TiC.PROPERTY_PADDING)) {
setPadding(new KrollDict((HashMap) newValue));
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down Expand Up @@ -454,14 +456,19 @@ protected void setTrafficEnabled(boolean enabled)
}
}

protected void setPadding(int left, int top, int right, int bottom)
protected void setPadding(KrollDict args)
{
int left = TiConvert.toInt(args.getInt(TiC.PROPERTY_LEFT), 0);
int top = TiConvert.toInt(args.getInt(TiC.PROPERTY_TOP), 0);
int right = TiConvert.toInt(args.getInt(TiC.PROPERTY_RIGHT), 0);
int bottom = TiConvert.toInt(args.getInt(TiC.PROPERTY_BOTTOM), 0);

if (map != null) {
map.setPadding(left, top, right, bottom);
}
}

protected void showAnnotations(Object[] annotations) {
protected void showAnnotations(Object[] annotations, int padding, boolean animated) {
ArrayList<TiMarker> markers = new ArrayList<TiMarker>();

// Use supplied annotations first. If none available, select all (parity with iOS)
Expand All @@ -478,13 +485,19 @@ protected void showAnnotations(Object[] annotations) {

LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (TiMarker marker : markers) {
builder.include(marker.getPosition());
if (marker != null) {
builder.include(marker.getPosition());
}
}
LatLngBounds bounds = builder.build();

int padding = 30;
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
map.animateCamera(cu);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);

if (animated) {
map.animateCamera(cameraUpdate);
} else {
map.moveCamera(cameraUpdate);
}
}

protected void setZoomControlsEnabled(boolean enabled)
Expand Down
32 changes: 7 additions & 25 deletions android/src/ti/map/ViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
TiC.PROPERTY_REGION, TiC.PROPERTY_ANNOTATIONS, TiC.PROPERTY_ANIMATE,
MapModule.PROPERTY_TRAFFIC, TiC.PROPERTY_STYLE, TiC.PROPERTY_ENABLE_ZOOM_CONTROLS,
MapModule.PROPERTY_COMPASS_ENABLED, MapModule.PROPERTY_SCROLL_ENABLED, MapModule.PROPERTY_ZOOM_ENABLED,
MapModule.PROPERTY_POLYLINES })
MapModule.PROPERTY_POLYLINES, TiC.PROPERTY_PADDING })
public class ViewProxy extends TiViewProxy implements AnnotationDelegate
{
private static final String TAG = "MapViewProxy";
Expand Down Expand Up @@ -310,7 +310,7 @@ public boolean handleMessage(Message msg)

case MSG_SHOW_ANNOTATIONS: {
result = ((AsyncResult) msg.obj);
handleShowAnnotations((Object[]) result.getArg());
handleShowAnnotations((Object[]) result.getArg(), 30, false);
result.setResult(null);
return true;
}
Expand Down Expand Up @@ -416,15 +416,15 @@ private void handleSnapshot()
}

@Kroll.method
public void showAnnotations(Object annotations) {
public void showAnnotations(Object annotations, int padding, boolean animated) {
if (TiApplication.isUIThread()) {
handleShowAnnotations(annotations);
handleShowAnnotations(annotations, padding, animated);
} else {
getMainHandler().obtainMessage(MSG_SHOW_ANNOTATIONS).sendToTarget();
}
}

private void handleShowAnnotations(Object annotations) {
private void handleShowAnnotations(Object annotations, int padding, boolean animated) {
if (!(annotations instanceof Object[])) {
Log.e(TAG, "Invalid argument to addAnnotations", Log.DEBUG_MODE);
return;
Expand All @@ -433,7 +433,7 @@ private void handleShowAnnotations(Object annotations) {

TiUIMapView mapView = (TiUIMapView) peekView();
if (mapView.getMap() != null) {
mapView.showAnnotations(annos);
mapView.showAnnotations(annos, padding, animated);
}
}

Expand Down Expand Up @@ -1206,19 +1206,6 @@ public void refreshAnnotation(AnnotationProxy annotation)
}
}

// clang-format off
@Kroll.method
@Kroll.setProperty
public void setPadding(KrollDict padding)
// clang-format on
{
if (TiApplication.isUIThread()) {
handleSetPadding(padding);
} else {
getMainHandler().obtainMessage(MSG_SET_PADDING, padding).sendToTarget();
}
}

private void addPreloadImageOverlay(ImageOverlayProxy proxy)
{
if (!(preloadOverlaysList.contains(proxy))) {
Expand Down Expand Up @@ -1330,12 +1317,7 @@ public void handleSetPadding(KrollDict args)
{
TiUIView view = peekView();
if (view instanceof TiUIMapView) {
int left = TiConvert.toInt(args.getInt(TiC.PROPERTY_LEFT), 0);
int top = TiConvert.toInt(args.getInt(TiC.PROPERTY_TOP), 0);
int right = TiConvert.toInt(args.getInt(TiC.PROPERTY_RIGHT), 0);
int bottom = TiConvert.toInt(args.getInt(TiC.PROPERTY_BOTTOM), 0);

((TiUIMapView) view).setPadding(left, top, right, bottom);
((TiUIMapView) view).setPadding(args);
}
}

Expand Down

0 comments on commit 5e6f870

Please sign in to comment.