Skip to content

Commit

Permalink
feat(android): support android (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Jan 30, 2024
1 parent 2fa6a07 commit 54e90a6
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 4 deletions.
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.6.1
version: 5.7.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: External version of Map module using native Google Maps library
Expand Down
1 change: 1 addition & 0 deletions android/src/ti/map/MapModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class MapModule extends KrollModule implements OnMapsSdkInitializedCallba
public static final String PROPERTY_STROKE_COLOR = "strokeColor";
public static final String PROPERTY_STROKE_WIDTH = "strokeWidth";
public static final String PROPERTY_FILL_COLOR = "fillColor";
public static final String PROPERTY_OVERLAY_COLOR = "overlayColor";
public static final String PROPERTY_ZINDEX = "zIndex";
public static final String PROPERTY_POLYGON = "polygon";
public static final String PROPERTY_POLYGONS = "polygons";
Expand Down
37 changes: 37 additions & 0 deletions android/src/ti/map/TiMapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,41 @@ public static ArrayList<LatLng> processPoints(Object points)
}
return locationArray;
}

public static List<LatLng> createOuterBounds() {
float delta = 0.01f;

return new ArrayList<LatLng>() {{
add(new LatLng(90 - delta, -180 + delta));
add(new LatLng(0, -180 + delta));
add(new LatLng(-90 + delta, -180 + delta));
add(new LatLng(-90 + delta, 0));
add(new LatLng(-90 + delta, 180 - delta));
add(new LatLng(0, 180 - delta));
add(new LatLng(90 - delta, 180 - delta));
add(new LatLng(90 - delta, 0));
add(new LatLng(90 - delta, -180 + delta));
}};
}

public static Iterable<LatLng> createHole(LatLng center, int radius) {
int points = 50; // number of corners of inscribed polygon

double radiusLatitude = Math.toDegrees(radius / 1000 / 6371.0);
double radiusLongitude = radiusLatitude / Math.cos(Math.toRadians(center.latitude));

List<LatLng> result = new ArrayList<>(points);

double anglePerCircleRegion = 2 * Math.PI / points;

for (int i = 0; i < points; i++) {
double theta = i * anglePerCircleRegion;
double latitude = center.latitude + (radiusLatitude * Math.sin(theta));
double longitude = center.longitude + (radiusLongitude * Math.cos(theta));

result.add(new LatLng(latitude, longitude));
}

return result;
}
}
31 changes: 31 additions & 0 deletions android/src/ti/map/TiUIMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

package ti.map;

import static ti.map.TiMapUtils.createHole;
import static ti.map.TiMapUtils.createOuterBounds;
import static ti.map.TiMapUtils.parseLocation;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -34,6 +38,7 @@
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MapStyleOptions;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.PolygonOptions;
import com.google.android.gms.maps.model.TileOverlayOptions;
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterManager;
Expand Down Expand Up @@ -894,6 +899,32 @@ public void removeAllPolylines()
currentPolylines.clear();
}

/**
* Cutout Circle
*/
protected void addCutoutCircle(KrollDict circleConfig) {
if (map == null) {
return;
}

Activity currentActivity = TiApplication.getAppCurrentActivity();

LatLng center = parseLocation(circleConfig);
int radius = circleConfig.getInt(MapModule.PROPERTY_RADIUS);
float strokeWidth = circleConfig.getDouble(MapModule.PROPERTY_STROKE_WIDTH).floatValue();
int strokeColor = TiConvert.toColor(circleConfig.getString(MapModule.PROPERTY_STROKE_COLOR), currentActivity);
int overlayColor = TiConvert.toColor(circleConfig.getString(MapModule.PROPERTY_OVERLAY_COLOR), currentActivity);

PolygonOptions options = new PolygonOptions()
.fillColor(overlayColor)
.addAll(createOuterBounds())
.addHole(createHole(center, radius))
.strokeColor(strokeColor)
.strokeWidth(strokeWidth);

map.addPolygon(options);
}

/**
* Circle
*/
Expand Down
25 changes: 25 additions & 0 deletions android/src/ti/map/ViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class ViewProxy extends TiViewProxy implements AnnotationDelegate
private static final int MSG_ADD_CIRCLE = MSG_FIRST_ID + 921;
private static final int MSG_REMOVE_CIRCLE = MSG_FIRST_ID + 922;
private static final int MSG_REMOVE_ALL_CIRCLES = MSG_FIRST_ID + 923;
private static final int MSG_ADD_CUTOUT_CIRCLE = MSG_FIRST_ID + 924;

private static final int MSG_ADD_IMAGE_OVERLAY = MSG_FIRST_ID + 931;
private static final int MSG_REMOVE_IMAGE_OVERLAY = MSG_FIRST_ID + 932;
Expand Down Expand Up @@ -289,6 +290,13 @@ public boolean handleMessage(Message msg)
return true;
}

case MSG_ADD_CUTOUT_CIRCLE: {
result = (AsyncResult) msg.obj;
handleAddCutoutCircle((KrollDict) result.getArg());
result.setResult(null);
return true;
}

case MSG_REMOVE_CIRCLE: {
result = (AsyncResult) msg.obj;
handleRemoveCircle((CircleProxy) result.getArg());
Expand Down Expand Up @@ -1105,6 +1113,23 @@ public void handleAddCircle(CircleProxy circle)
}
}

@Kroll.method
public void addCutoutCircle(KrollDict circleConfiguration)
{
handleAddCutoutCircle(circleConfiguration);
}

public void handleAddCutoutCircle(KrollDict circleConfiguration)
{
TiUIView view = peekView();
if (view instanceof TiUIMapView) {
TiUIMapView mapView = (TiUIMapView) view;
if (mapView.getMap() != null) {
mapView.addCutoutCircle(circleConfiguration);
}
}
}

public void addPreloadCircle(CircleProxy c)
{
if (!preloadCircles.contains(c)) {
Expand Down
2 changes: 1 addition & 1 deletion apidoc/Map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ properties:

---
name: CutoutCircleConfiguration
summary: Options to configure a cutout circle (iOS only right now).
summary: Options to configure a cutout circle.
properties:
- name: longitude
summary: Longitude value of the map point, in decimal degrees.
Expand Down
3 changes: 1 addition & 2 deletions apidoc/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ methods:
A cutout circle represents a special polygon that spans over the
whole world and has a cutout in the shape of a circle. The radius
of the shape, the overlay color and stroke properties can be configured.
exclude-platforms: [android]
since: { iphone: "12.3.0", ipad: "12.3.0", macos: "12.3.0" }
since: "12.4.0"
parameters:
- name: circleConfiguration
summary: A <CutoutCircleConfiguration> object.
Expand Down

0 comments on commit 54e90a6

Please sign in to comment.