Skip to content
Open
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
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

dependencies {
// https://developers.google.com/android/guides/releases
implementation 'com.google.android.gms:play-services-maps:19.2.0'
implementation 'com.google.android.gms:play-services-maps:20.0.0'

// https://github.com/googlemaps/android-maps-utils/releases
implementation 'com.google.maps.android:android-maps-utils:3.14.0'
implementation 'com.google.maps.android:android-maps-utils:3.16.0'

// https://developer.android.com/jetpack/androidx/releases/fragment
implementation 'androidx.fragment:fragment:1.7.1'
implementation 'androidx.fragment:fragment:1.8.9'
}
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 5.7.0
version: 5.8.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: External version of Map module using native Google Maps library
Expand Down
133 changes: 57 additions & 76 deletions android/src/ti/map/AnnotationProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,15 @@ public AnnotationProxy()
@Override
public void release()
{
if (hasProperty(MapModule.PROPERTY_CUSTOM_VIEW)) {
TiViewProxy customView = (TiViewProxy) getProperty(MapModule.PROPERTY_CUSTOM_VIEW);
customView.release();
}
/*
if (markerOptions != null) {
markerOptions = null;
}
if (clusterMarker != null) {
clusterMarker = null;
Object customViewProperty = getProperty(MapModule.PROPERTY_CUSTOM_VIEW);
if (customViewProperty instanceof TiViewProxy) {
((TiViewProxy) customViewProperty).release();
}
if (infoWindow != null) {
infoWindow.removeAllViews();
infoWindow = null;
}
if (delegate != null) {
delegate = null;
}
*/
delegate = null;
super.release();
}

Expand Down Expand Up @@ -159,19 +150,19 @@ public boolean handleMessage(Message msg)

case MSG_SET_HIDDEN: {
result = (AsyncResult) msg.obj;
Marker m = marker.getMarker();
if (m != null) {
m.setVisible(!(Boolean) result.getArg());
Marker hiddenMarker = getNativeMarker();
if (hiddenMarker != null) {
hiddenMarker.setVisible(!(Boolean) result.getArg());
}
result.setResult(null);
return true;
}

case MSG_SET_DRAGGABLE: {
result = (AsyncResult) msg.obj;
Marker m = marker.getMarker();
if (m != null) {
m.setDraggable((Boolean) result.getArg());
Marker draggableMarker = getNativeMarker();
if (draggableMarker != null) {
draggableMarker.setDraggable((Boolean) result.getArg());
}
result.setResult(null);
return true;
Expand All @@ -182,24 +173,31 @@ public boolean handleMessage(Message msg)
return true;
}

case MSG_SET_IMAGE:
case MSG_SET_IMAGE: {
result = (AsyncResult) msg.obj;
Marker m = marker.getMarker();
if (m != null) {
updateImage(m, result.getArg());
}
updateImage(getNativeMarker(), result.getArg());
result.setResult(null);
return true;
}

default: {
return super.handleMessage(msg);
}
}
}

/**
* The native marker, or null while the annotation is not (yet) rendered on the map.
* Clustered annotations only get one once TiClusterRenderer has rendered them.
*/
private Marker getNativeMarker()
{
return (marker != null) ? marker.getMarker() : null;
}

public void setPosition(double latitude, double longitude)
{
Marker m = marker.getMarker();
Marker m = getNativeMarker();
if (m != null) {
animateMarkerToPosition(m, new LatLng(latitude, longitude));
}
Expand Down Expand Up @@ -315,32 +313,20 @@ private void handleCustomView(Object obj)

private void handleImage(Object image)
{
// Image path
Bitmap bitmap = null;
if (image instanceof String) {
TiDrawableReference imageref = TiDrawableReference.fromUrl(this, (String) image);
Bitmap bitmap = imageref.getBitmap();
if (bitmap != null) {
try {
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
setIconImageDimensions(bitmap.getWidth(), bitmap.getHeight());
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
return;
}
bitmap = TiDrawableReference.fromUrl(this, (String) image).getBitmap();
} else if (image instanceof TiBlob) {
bitmap = ((TiBlob) image).getImage();
}

// Image blob
if (image instanceof TiBlob) {
Bitmap bitmap = ((TiBlob) image).getImage();
if (bitmap != null) {
try {
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
setIconImageDimensions(bitmap.getWidth(), bitmap.getHeight());
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
if (bitmap != null) {
try {
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
setIconImageDimensions(bitmap.getWidth(), bitmap.getHeight());
return;
} catch (Exception e) {
Log.e(TAG, "Unable to apply the marker image", e);
}
}

Expand All @@ -355,46 +341,41 @@ public MarkerOptions getMarkerOptions()

public void updateImage(Marker m, Object value)
{
if (m == null) {
return;
}
if (hasProperty(MapModule.PROPERTY_CUSTOM_VIEW)) {
// Custom view used. Update image not allowed
return;
}

// Clearing the image falls back to the pin, tinted with "pinColor" when one is set.
if (value == null) {
m.setIcon(BitmapDescriptorFactory.defaultMarker(TiConvert.toFloat(getProperty(TiC.PROPERTY_PINCOLOR))));
Object pinColor = getProperty(TiC.PROPERTY_PINCOLOR);
m.setIcon(pinColor != null ? BitmapDescriptorFactory.defaultMarker(TiConvert.toFloat(pinColor))
: BitmapDescriptorFactory.defaultMarker());
setIconImageDimensions(-1, -1);
return;
}

// image not null has only effect if customView is null. Any other case, customView has more priority
if (value != null) {
// Image path
if (value instanceof String) {
TiDrawableReference imageref = TiDrawableReference.fromUrl(this, (String) value);
Bitmap bitmap = imageref.getBitmap();
if (bitmap != null) {
try {
if (m != null) {
m.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
setIconImageDimensions(bitmap.getWidth(), bitmap.getHeight());
}
} catch (Exception e) {
}
return;
}
}
Bitmap bitmap = null;
if (value instanceof String) {
bitmap = TiDrawableReference.fromUrl(this, (String) value).getBitmap();
} else if (value instanceof TiBlob) {
bitmap = ((TiBlob) value).getImage();
}

// Image blob
if (value instanceof TiBlob) {
Bitmap bitmap = ((TiBlob) value).getImage();
if (bitmap != null) {
if (m != null) {
m.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
setIconImageDimensions(bitmap.getWidth(), bitmap.getHeight());
}
return;
}
}
if (bitmap == null) {
Log.w(TAG, "Unable to get the image from: " + value);
return;
}

try {
m.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
setIconImageDimensions(bitmap.getWidth(), bitmap.getHeight());
} catch (Exception e) {
Log.e(TAG, "Unable to apply the marker image", e);
}
}

Expand Down
11 changes: 11 additions & 0 deletions android/src/ti/map/CameraProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public void onPropertyChanged(String name, Object value)

private void updateCamera()
{
// CameraPosition requires a target. Without "centerCoordinates" there is nothing to move the camera to.
if (position == null) {
cameraPosition = null;
return;
}
cameraPosition = new CameraPosition.Builder().target(position).zoom(zoom).bearing(heading).tilt(pitch).build();
}

Expand All @@ -94,4 +99,10 @@ public CameraUpdate getCamera()
return null;
}
}

@Override
public String getApiName()
{
return "Ti.Map.Camera";
}
}
14 changes: 10 additions & 4 deletions android/src/ti/map/ImageOverlayProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package ti.map;

import com.google.android.gms.maps.model.BitmapDescriptor;
import android.graphics.Bitmap;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.GroundOverlayOptions;
Expand All @@ -16,6 +16,7 @@
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.view.TiDrawableReference;

@Kroll.proxy(creatableInModule = MapModule.class)
Expand Down Expand Up @@ -73,10 +74,15 @@ private void handleBoundsCoordinate(KrollDict boundsCoordinateDict)
private void handleImage(Object image)
{
TiDrawableReference source = TiDrawableReference.fromObject(this, image);
if (!source.isTypeNull()) {
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(source.getBitmap());
groundOverlayOptions.image(bitmapDescriptor);
if (source.isTypeNull()) {
return;
}
Bitmap bitmap = source.getBitmap();
if (bitmap == null) {
Log.w(TAG, "Unable to load the image overlay image: " + image);
return;
}
groundOverlayOptions.image(BitmapDescriptorFactory.fromBitmap(bitmap));
}

public GroundOverlayOptions getGroundOverlayOptions()
Expand Down
7 changes: 4 additions & 3 deletions android/src/ti/map/PolylineProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,18 @@ else if (name.equals(TiC.PROPERTY_TOUCH_ENABLED)) {
private List<PatternItem> processPatternDefinition(HashMap definition)
{
List<PatternItem> pattern = null;
int type = (Integer) definition.get("type");
int gapLength = (Integer) definition.get("gapLength");

if (definition.get("type") == null) {
Log.e(TAG, "No pattern type specified. Using default dashed pattern.");

return DEFAULT_DASHED_PATTERN;
}

int type = TiConvert.toInt(definition.get("type"));
int gapLength = TiConvert.toInt(definition.get("gapLength"), DEFAULT_PATTERN_GAP_LENGTH_PX);

if (type == MapModule.POLYLINE_PATTERN_DASHED) {
int dashLength = (Integer) definition.get("dashLength");
int dashLength = TiConvert.toInt(definition.get("dashLength"), DEFAULT_PATTERN_DASH_LENGTH_PX);

pattern = Arrays.asList(new Dash(dashLength), new Gap(gapLength));
} else if (type == MapModule.POLYLINE_PATTERN_DOTTED) {
Expand Down
3 changes: 1 addition & 2 deletions android/src/ti/map/Shape/PolylineBoundary.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ti.map.Shape;

import android.graphics.PointF;
import android.util.Log;
import com.google.android.gms.maps.model.LatLng;
import java.util.ArrayList;
import ti.map.PolylineProxy;
Expand Down Expand Up @@ -76,7 +75,7 @@ public boolean contains(PointF[] points, PointF test)
{

double diffX = point2.x - point1.x;
double diffY = point2.y - point.y;
double diffY = point2.y - point1.y;
if ((diffX == 0) && (diffY == 0)) {
diffX = test.x - point1.x;
diffY = test.y - point1.y;
Expand Down
34 changes: 14 additions & 20 deletions android/src/ti/map/TiClusterRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ protected void onBeforeClusterItemRendered(TiMarker clusterItem, MarkerOptions m
if (anno != null) {
if (anno.hasProperty(TiC.PROPERTY_IMAGE)) {
handleImage(anno, markerOptions, anno.getProperty(TiC.PROPERTY_IMAGE));
} else {
// Fall back to the default icon size so "centerOffset" below does not divide by zero.
setIconImageDimensions(-1, -1);
}

if (anno.hasProperty(MapModule.PROPERTY_CENTER_OFFSET)) {
Expand All @@ -53,28 +56,20 @@ protected void onBeforeClusterItemRendered(TiMarker clusterItem, MarkerOptions m

private void handleImage(AnnotationProxy anno, MarkerOptions markerOptions, Object image)
{
// Image path
Bitmap bitmap = null;
if (image instanceof String) {
TiDrawableReference imageref =
TiDrawableReference.fromUrl(anno, (String) anno.getProperty(TiC.PROPERTY_IMAGE));
Bitmap bitmap = imageref.getBitmap();
if (bitmap != null) {
try {
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
setIconImageDimensions(bitmap.getWidth(), bitmap.getHeight());
} catch (Exception e) {
}
return;
}
bitmap = TiDrawableReference.fromUrl(anno, (String) image).getBitmap();
} else if (image instanceof TiBlob) {
bitmap = ((TiBlob) image).getImage();
}

// Image blob
if (image instanceof TiBlob) {
Bitmap bitmap = ((TiBlob) image).getImage();
if (bitmap != null) {
if (bitmap != null) {
try {
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
setIconImageDimensions(bitmap.getWidth(), bitmap.getHeight());
return;
} catch (Exception e) {
Log.e(TAG, "Unable to apply the cluster item image", e);
}
}

Expand All @@ -89,6 +84,7 @@ protected void onClusterItemRendered(TiMarker clusterItem, Marker marker)
clusterItem.setMarker(marker);
}

@Override
protected void onClusterItemUpdated(TiMarker item, Marker marker)
{
boolean changed = false;
Expand All @@ -110,10 +106,8 @@ protected void onClusterItemUpdated(TiMarker item, Marker marker)
changed = true;
}
// Update marker position if the item changed position
if (!marker.getPosition().equals(item.getPosition())) {
if (item.getPosition() != null) {
marker.setPosition(item.getPosition());
}
if (item.getPosition() != null && !item.getPosition().equals(marker.getPosition())) {
marker.setPosition(item.getPosition());
changed = true;
}
if (changed && marker.isInfoWindowShown()) {
Expand Down
Loading
Loading