Skip to content

Commit

Permalink
Merge pull request #572 from m1ga/centerPoly
Browse files Browse the repository at this point in the history
feat(android): polygon bounds
  • Loading branch information
hansemannn committed Sep 23, 2023
2 parents 94ff4b9 + bf8ac44 commit 26cae56
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion android/manifest
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 5.5.3
version: 5.6.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: External version of Map module using native Google Maps library
Expand Down
22 changes: 22 additions & 0 deletions android/src/ti/map/PolygonProxy.java
Expand Up @@ -9,6 +9,7 @@
import android.app.Activity;
import android.os.Message;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Polygon;
import com.google.android.gms.maps.model.PolygonOptions;
import com.google.maps.android.PolyUtil;
Expand Down Expand Up @@ -304,6 +305,27 @@ else if (name.equals(TiC.PROPERTY_TOUCH_ENABLED)) {
}
}

@Kroll.getProperty
public HashMap getBounds()
{
if (polygon == null) {
return null;
}
final LatLngBounds.Builder centerBuilder = LatLngBounds.builder();
List<LatLng> points = polygon.getPoints();
for (LatLng point : points) {
centerBuilder.include(point);
}

LatLngBounds llb = centerBuilder.build();
HashMap hm = new HashMap();
hm.put(TiC.PROPERTY_LONGITUDE, llb.getCenter().longitude);
hm.put(TiC.PROPERTY_LATITUDE, llb.getCenter().latitude);
hm.put(TiC.PROPERTY_LATITUDE_DELTA, Math.abs(llb.northeast.latitude - llb.southwest.latitude));
hm.put(TiC.PROPERTY_LONGITUDE_DELTA, Math.abs(llb.northeast.longitude - llb.southwest.longitude));
return hm;
}

public String getApiName()
{
return "Ti.Map.Polygon";
Expand Down
6 changes: 6 additions & 0 deletions apidoc/Polygon.yml
Expand Up @@ -57,3 +57,9 @@ properties:
availability: creation
type: Number
platforms: [android]

- name: bounds
summary: Returns the bounding box of the polygon. Useful to center the region.
type: MapRegionTypev2
platforms: [android]
since: "12.3.0"

0 comments on commit 26cae56

Please sign in to comment.