Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6b22c99
feat(android): add „poiclick“ event
hansemannn Mar 11, 2019
5e6f870
fix: add poi-click listener to map instance
hansemannn Jul 13, 2019
bf2373e
fix: fix null-check in MapView#zoom
hansemannn Aug 2, 2019
7cef29e
fix: add „conatinsCoordinate“ method for parity
hansemannn Aug 2, 2019
2a2ba17
refactor: remove old xcode version guards
hansemannn Aug 31, 2019
fd5a51c
refactor: use TitaniumKit imports, fix all warnings and leaks
hansemannn Aug 31, 2019
8c07870
chore: remove old build scripts, require SDK 8
hansemannn Aug 31, 2019
91a76f2
Merge branch 'master' into add-poi-click
hansemannn Aug 31, 2019
a0c6cda
Merge branch 'master' into add-poi-click
hansemannn Nov 2, 2019
67816d6
feat: add containsCoordinate method
hansemannn Nov 2, 2019
7888c77
build: replace maps utils with latest version
hansemannn Nov 2, 2019
db1582a
feat(android): add new API’s
hansemannn Nov 2, 2019
fac8c27
Merge branch 'add-poi-click' of https://github.com/hansemannn/ti.map …
hansemannn Nov 2, 2019
7bc0632
fix: use current activity for permission check
hansemannn Jan 8, 2020
4c94feb
chore(ios): expose mapType
hansemannn Feb 28, 2020
409d4ce
refactor(android): use new „OnPolylineClickListener“
hansemannn Feb 28, 2020
ade2bcc
Merge branch 'master' of github.com:appcelerator-modules/ti.map into …
hansemannn May 3, 2020
d5259bb
chore: bump version
hansemannn May 3, 2020
57d57d6
fix: remove unused aar
hansemannn May 3, 2020
8c306c3
feat: add geodesic support
hansemannn May 29, 2020
7eabf4a
Merge branch 'master' into add-poi-click
hansemannn Jun 3, 2020
8542fbf
chore: use latest dependencies
hansemannn Aug 23, 2020
2380d12
fix: fix imports
hansemannn Aug 23, 2020
a300247
feat: support encoded polylines
hansemannn Aug 23, 2020
b6adf41
Merge branch 'add-poi-click' of https://github.com/hansemannn/ti.map …
hansemannn Aug 23, 2020
3626571
Merge branch 'master' of github.com:appcelerator-modules/ti.map into …
hansemannn Aug 23, 2020
ccc621c
fix: fix polyline encoding
hansemannn Sep 3, 2020
09c3510
fix(android): pass zoom level to region changed event
hansemannn Sep 3, 2020
7992bc0
feat(android): add „drawRoundedPolylineBetweenCoordinates“ method
hansemannn Oct 26, 2020
64aa434
chore: allow “userLocation: true” with “ACCESS_COARSE_LOCATION”
hansemannn Mar 12, 2021
033e7f5
fix: fix brackets
hansemannn Mar 12, 2021
26015f5
fix: guard proxy
hansemannn May 14, 2021
150a3f7
fix(android): guard markers
hansemannn May 14, 2021
121d567
chore: migrate from MKPinAnnotationView
hansemannn Jul 18, 2021
167fafa
fix: guard markers to prevent uncaught exceptions
hansemannn Oct 20, 2021
c3d2864
fix: add null check
hansemannn Oct 22, 2021
fd20292
chore: add try-catch block
hansemannn Oct 27, 2021
fc76248
chore: merge changes
hansemannn Feb 3, 2022
d23583d
Merge branch 'master' of https://github.com/appcelerator-modules/ti.m…
hansemannn Feb 3, 2022
56c7b20
fix: fix additional merge conflicts
hansemannn Feb 3, 2022
89eb31e
fix: fix merge issues
hansemannn Feb 3, 2022
03cdcc4
Merge branch 'master' into add-poi-click-merged
m1ga May 13, 2023
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2013 Appcelerator, Inc.
Copyright 2013-present Appcelerator, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
42 changes: 42 additions & 0 deletions android/src/ti/map/MapModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,33 @@
*/
package ti.map;

import android.location.Location;
import androidx.annotation.NonNull;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapsSdkInitializedCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.maps.android.PolyUtil;

import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.TiC;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Kroll.module(name = "Map", id = "ti.map")
public class MapModule extends KrollModule implements OnMapsSdkInitializedCallback
{
public static final String EVENT_MAP_CLICK = "mapclick";
public static final String EVENT_POI_CLICK = "poiclick";
public static final String EVENT_PIN_CHANGE_DRAG_STATE = "pinchangedragstate";
public static final String EVENT_ON_SNAPSHOT_READY = "onsnapshotready";
public static final String EVENT_REGION_WILL_CHANGE = "regionwillchange";
Expand Down Expand Up @@ -70,6 +82,7 @@ public class MapModule extends KrollModule implements OnMapsSdkInitializedCallba
public static final String PROPERTY_CENTER = "center";
public static final String PROPERTY_RADIUS = "radius";
public static final String PROPERTY_INDOOR_ENABLED = "indoorEnabled";
public static final String PROPERTY_PLACE_ID = "placeID";
public static final String PROPERTY_DESELECTED = "deselected";
public static final String PROPERTY_LITE_MODE = "liteMode";
public static final String PROPERTY_MIN_CLUSTER_SIZE = "minClusterSize";
Expand Down Expand Up @@ -159,6 +172,35 @@ public int isGooglePlayServicesAvailable()
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(TiApplication.getInstance());
}

@Kroll.method
public boolean geometryContainsLocation(KrollDict dict)
{
HashMap<String, String> point = (HashMap<String, String>) dict.get("location");
LatLng location = new LatLng(TiConvert.toDouble(point.get(TiC.PROPERTY_LATITUDE)),TiConvert.toDouble(point.get(TiC.PROPERTY_LONGITUDE)));
List<LatLng> polygon = new ArrayList<>();
Object[] dictPoints =(Object[]) dict.get("points");
for (Object _point : dictPoints) {
HashMap<String, String> _location = (HashMap<String, String>)_point;
polygon.add(new LatLng(TiConvert.toDouble(_location.get(TiC.PROPERTY_LATITUDE)), TiConvert.toDouble(_location.get(TiC.PROPERTY_LONGITUDE))));
}
return PolyUtil.containsLocation(location, polygon, true);
}

@Kroll.method
public double geometryDistanceBetweenPoints(Object jsLocation1, Object jsLocation2)
{
HashMap<String, String> location1Dict = (HashMap<String, String>) jsLocation1;
HashMap<String, String> location2Dict = (HashMap<String, String>) jsLocation2;

LatLng location1 = new LatLng(TiConvert.toDouble(location1Dict.get(TiC.PROPERTY_LATITUDE)), TiConvert.toDouble(location1Dict.get(TiC.PROPERTY_LONGITUDE)));
LatLng location2 = new LatLng(TiConvert.toDouble(location2Dict.get(TiC.PROPERTY_LATITUDE)), TiConvert.toDouble(location2Dict.get(TiC.PROPERTY_LONGITUDE)));

float[] results = new float[1];
Location.distanceBetween(location1.latitude, location1.longitude, location2.latitude, location2.longitude, results);

return results[0];
}

@Override
public String getApiName()
{
Expand Down
27 changes: 21 additions & 6 deletions android/src/ti/map/PolygonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,41 @@ public void addLocation(Object loc, ArrayList<LatLng> locationArray, boolean lis
}
}

public ArrayList<LatLng> processPoints(Object points, boolean list)
public List<LatLng> processPoints(Object points, boolean list)
{

ArrayList<LatLng> locationArray = new ArrayList<LatLng>();
// encoded (result from routing API)
if (points instanceof String) {
List<LatLng> locationList = PolyUtil.decode((String) points);
return new ArrayList<LatLng>(locationList);
}
// multiple points
if (points instanceof Object[]) {
// Handle an array of points
} else if (points instanceof Object[]) {
Object[] pointsArray = (Object[]) points;
for (int i = 0; i < pointsArray.length; i++) {
Object obj = pointsArray[i];
addLocation(obj, locationArray, list);
}

return locationArray;
// Handle encoded polyline
} else if (points instanceof Object[]) {
Object[] pointsArray = (Object[]) points;
for (int i = 0; i < pointsArray.length; i++) {
Object obj = pointsArray[i];
addLocation(obj, locationArray, list);
}

return locationArray;
// Handle encoded polyline
} else if (points instanceof String) {
for (LatLng point : PolyUtil.decode((String) points)) {
addLocation(point, locationArray, list);
}

return locationArray;
}

// single point
// Single point
addLocation(points, locationArray, list);
return locationArray;
}
Expand Down
70 changes: 57 additions & 13 deletions android/src/ti/map/PolylineProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
propertyAccessors = { MapModule.PROPERTY_STROKE_COLOR, MapModule.PROPERTY_STROKE_WIDTH,
PolylineProxy.PROPERTY_STROKE_COLOR2, PolylineProxy.PROPERTY_STROKE_WIDTH2,
PolylineProxy.PROPERTY_STROKE_PATTERN2, PolylineProxy.PROPERTY_ZINDEX,
MapModule.PROPERTY_POINTS, TiC.PROPERTY_TOUCH_ENABLED })
MapModule.PROPERTY_POINTS, TiC.PROPERTY_TOUCH_ENABLED, PolylineProxy.PROPERTY_GEODESIC })
public class PolylineProxy extends KrollProxy implements IShape
{

private PolylineOptions options;
private Polyline polyline;
private boolean clickable;
Expand All @@ -53,13 +52,15 @@ public class PolylineProxy extends KrollProxy implements IShape
private static final int MSG_SET_TOUCH_ENABLED = MSG_FIRST_ID + 504;
private static final int MSG_SET_STROKE_PATTERN = MSG_FIRST_ID + 505;
private static final int MSG_SET_STROKE_JOINT = MSG_FIRST_ID + 506;
private static final int MSG_SET_GEODESIC = MSG_FIRST_ID + 507;

public static final String PROPERTY_STROKE_COLOR2 = "color";
public static final String PROPERTY_STROKE_WIDTH2 = "width";
public static final String PROPERTY_STROKE_PATTERN2 = "pattern";
public static final String PROPERTY_JOINT_TYPE = "jointType";

public static final String PROPERTY_ZINDEX = "zIndex";
public static final String PROPERTY_GEODESIC = "geodesic";

private static final int DEFAULT_PATTERN_DASH_LENGTH_PX = 50;
private static final int DEFAULT_PATTERN_GAP_LENGTH_PX = 20;
Expand All @@ -79,8 +80,8 @@ public PolylineProxy()
@Override
public boolean handleMessage(Message msg)
{

AsyncResult result = null;
AsyncResult result;

switch (msg.what) {
case MSG_SET_POINTS: {
result = (AsyncResult) msg.obj;
Expand Down Expand Up @@ -126,6 +127,12 @@ public boolean handleMessage(Message msg)
result.setResult(null);
return true;
}
case MSG_SET_GEODESIC: {
result = (AsyncResult) msg.obj;
polyline.setGeodesic(TiConvert.toBoolean(result.getArg(), false));
result.setResult(null);
return true;
}
default: {
return super.handleMessage(msg);
}
Expand Down Expand Up @@ -173,6 +180,10 @@ public void processOptions()
clickable = TiConvert.toBoolean(getProperty(TiC.PROPERTY_TOUCH_ENABLED));
}

if (hasProperty(PolylineProxy.PROPERTY_GEODESIC)) {
options = options.geodesic(TiConvert.toBoolean(getProperty(PolylineProxy.PROPERTY_GEODESIC)));
}

if (hasProperty(PolylineProxy.PROPERTY_STROKE_PATTERN2)) {
if (getProperty(PolylineProxy.PROPERTY_STROKE_PATTERN2) instanceof HashMap) {
options.pattern(
Expand All @@ -198,22 +209,31 @@ public void addLocation(Object loc, ArrayList<LatLng> locationArray, boolean lis
}
}

public ArrayList<LatLng> processPoints(Object points, boolean list)
public List<LatLng> processPoints(Object points, boolean list)
{

ArrayList<LatLng> locationArray = new ArrayList<LatLng>();
// encoded (result from routing API)
if (points instanceof String) {

// Handle an array of points
if (points instanceof Object[]) {
Object[] pointsArray = (Object[]) points;
for (int i = 0; i < pointsArray.length; i++) {
Object obj = pointsArray[i];
addLocation(obj, locationArray, list);
}

return locationArray;
// Handle encoded polyline
} else if (points instanceof String) {
List<LatLng> locationList = PolyUtil.decode((String) points);
return new ArrayList<LatLng>(locationList);
}
// multiple points
if (points instanceof Object[]) {
// multiple points
} else if (points instanceof Object[]) {
Object[] pointsArray = (Object[]) points;
for (int i = 0; i < pointsArray.length; i++) {
Object obj = pointsArray[i];
addLocation(obj, locationArray, list);
}

return locationArray;
}

Expand Down Expand Up @@ -245,7 +265,6 @@ public Polyline getPolyline()
@Override
public void onPropertyChanged(String name, Object value)
{

super.onPropertyChanged(name, value);
Activity currentActivity = TiApplication.getAppCurrentActivity();
if (polyline == null) {
Expand Down Expand Up @@ -283,8 +302,33 @@ else if (name.equals(PolylineProxy.PROPERTY_ZINDEX)) {

else if (name.equals(TiC.PROPERTY_TOUCH_ENABLED)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_TOUCH_ENABLED),
TiConvert.toBoolean(value));
TiConvert.toBoolean(value));
}

else if (name.equals(PolylineProxy.PROPERTY_GEODESIC)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_GEODESIC),
TiConvert.toBoolean(value));
}
}

// A location can either be a an array of longitude, latitude pairings or
// an array of longitude, latitude objects.
// e.g. [123.33, 34.44], OR {longitude: 123.33, latitude, 34.44}
private LatLng parseLocation(Object loc)
{
LatLng location = null;
if (loc instanceof HashMap) {
HashMap<String, String> point = (HashMap<String, String>) loc;
location = new LatLng(TiConvert.toDouble(point.get(TiC.PROPERTY_LATITUDE)),
TiConvert.toDouble(point.get(TiC.PROPERTY_LONGITUDE)));
} else if (loc instanceof Object[]) {
Object[] temp = (Object[]) loc;
location = new LatLng(TiConvert.toDouble(temp[1]), TiConvert.toDouble(temp[0]));
} else if (loc instanceof LatLng) {
return (LatLng) loc;
}

return location;
}

private List<PatternItem> processPatternDefinition(HashMap definition)
Expand Down
Loading