From c3cfdc2203e6eea5d2037b2aa9c2b04b5225f8b4 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 3 Apr 2024 11:20:21 +0200 Subject: [PATCH 1/4] kml support --- android/build.gradle | 2 +- android/manifest | 2 +- android/src/ti/map/TiUIMapView.java | 13 +++++++++++++ android/src/ti/map/ViewProxy.java | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index a323ad2b..769d70eb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -4,7 +4,7 @@ dependencies { implementation 'com.google.android.gms:play-services-maps:18.1.0' // https://github.com/googlemaps/android-maps-utils/releases - implementation 'com.google.maps.android:android-maps-utils:3.5.3' + implementation 'com.google.maps.android:android-maps-utils:3.8.2' // https://developer.android.com/jetpack/androidx/releases/fragment implementation 'androidx.fragment:fragment:1.5.7' diff --git a/android/manifest b/android/manifest index 6c6ce06c..949a175a 100644 --- a/android/manifest +++ b/android/manifest @@ -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 diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index f52b68c5..82baf1f2 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -39,6 +39,7 @@ import com.google.maps.android.clustering.ClusterManager; import com.google.maps.android.clustering.view.DefaultClusterRenderer; import com.google.maps.android.collections.MarkerManager; +import com.google.maps.android.data.kml.KmlLayer; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -1447,4 +1448,16 @@ public boolean onClusterItemClick(TiMarker tiMarker) { return onMarkerClick(tiMarker.getMarker()); } + + public void loadKml(KrollDict args) + { + TiBlob file = TiConvert.toBlob(args.get("file")); + try { + KmlLayer layer = + new KmlLayer(map, file.getInputStream(), TiApplication.getInstance().getApplicationContext()); + layer.addLayerToMap(); + } catch (Exception ex) { + Log.e(TAG, "Error: " + ex.getMessage()); + } + } } diff --git a/android/src/ti/map/ViewProxy.java b/android/src/ti/map/ViewProxy.java index a09b9faf..711a79e2 100644 --- a/android/src/ti/map/ViewProxy.java +++ b/android/src/ti/map/ViewProxy.java @@ -1514,6 +1514,15 @@ public void setClusterAnnotation() { } + @Kroll.method + public void loadKml(KrollDict args) + { + TiUIView view = peekView(); + if (view instanceof TiUIMapView) { + ((TiUIMapView) view).loadKml(args); + } + } + public String getApiName() { return "Ti.Map.View"; From 1a6dfbe22b6fb695f60f5f84fa1dcba9e0ca7789 Mon Sep 17 00:00:00 2001 From: m1ga Date: Fri, 5 Apr 2024 12:29:28 +0200 Subject: [PATCH 2/4] update docs, error messages --- android/src/ti/map/TiUIMapView.java | 16 ++++++++------- android/src/ti/map/ViewProxy.java | 7 +++++++ apidoc/Map.yml | 31 ++++++++++++++++++++--------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index 82baf1f2..c5806f65 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -1451,13 +1451,15 @@ public boolean onClusterItemClick(TiMarker tiMarker) public void loadKml(KrollDict args) { - TiBlob file = TiConvert.toBlob(args.get("file")); - try { - KmlLayer layer = - new KmlLayer(map, file.getInputStream(), TiApplication.getInstance().getApplicationContext()); - layer.addLayerToMap(); - } catch (Exception ex) { - Log.e(TAG, "Error: " + ex.getMessage()); + if (map != null) { + TiBlob file = TiConvert.toBlob(args.get("file")); + try { + KmlLayer layer = + new KmlLayer(map, file.getInputStream(), TiApplication.getInstance().getApplicationContext()); + layer.addLayerToMap(); + } catch (Exception ex) { + Log.e(TAG, "Error: " + ex.getMessage()); + } } } } diff --git a/android/src/ti/map/ViewProxy.java b/android/src/ti/map/ViewProxy.java index 711a79e2..2a561f28 100644 --- a/android/src/ti/map/ViewProxy.java +++ b/android/src/ti/map/ViewProxy.java @@ -1517,9 +1517,16 @@ public void setClusterAnnotation() @Kroll.method public void loadKml(KrollDict args) { + if (!args.containsKeyAndNotNull("file")) { + Log.w(TAG, "file property is not set to a TiBlob"); + return; + } + TiUIView view = peekView(); if (view instanceof TiUIMapView) { ((TiUIMapView) view).loadKml(args); + } else { + Log.e(TAG, "Map is not available"); } } diff --git a/apidoc/Map.yml b/apidoc/Map.yml index 3b980deb..209cd7a6 100644 --- a/apidoc/Map.yml +++ b/apidoc/Map.yml @@ -33,7 +33,7 @@ description: | - @@ -438,7 +438,7 @@ properties: since: "6.3.0" - name: FEATURE_TERRITORIES - summary: | + summary: | The option that represents territorial boundaries such as a national border, a state boundary, or a neighborhood. type: Number @@ -448,7 +448,7 @@ properties: since: "12.0.0" - name: FEATURE_PHYSICAL_FEATURES - summary: | + summary: | The option that represents physical map features such as mountain ranges, rivers, and ocean basins. type: Number @@ -484,14 +484,14 @@ properties: osver: {ios: {min: "11.0"} } exclude-platforms: [android] since: "6.3.0" - + - name: SEARCH_RESULT_TYPE_ADDRESS summary: A value that indicates that search results include addresses. type: Number permission: read-only osver: {ios: {min: "13.0"} } since: "12.3.0" - + - name: SEARCH_RESULT_TYPE_POINT_OF_INTEREST summary: A value that indicates that search results include points of interest. type: Number @@ -518,7 +518,7 @@ methods: summary: Returns a code to indicate whether Google Play Services is available on the device. since: "3.1.1" platforms: [android] - + - name: search summary: | Uses the native `MKLocalSearchCompleter` class to search places for @@ -537,6 +537,19 @@ methods: platforms: [iphone, ipad, macos] since: "12.3.0" + - name: loadKml + summary: | + Loads a KML file and displays the content on the map. + description: | + Check [Google Maps KML support](https://developers.google.com/maps/documentation/android-sdk/utility/kml#supported) + for more details. + parameters: + - name: file + summary: Ti.Blob of the KML file. + type: TiBlob + platforms: [android] + since: "12.4.0" + - name: geocodeAddress summary: | Resolve address details using the `CLGeocoder` to get information (e.g. @@ -614,7 +627,7 @@ examples: const mapView = Map.createView({ mapType: Map.NORMAL_TYPE, - region: { + region: { latitude: 33.74511, longitude: -84.38993, latitudeDelta: 0.01, @@ -769,7 +782,7 @@ examples: The following example shows the MapKit based search request. The options in `search` (2nd parameter) are optional, but improve the accuracy of the results. - + ```javascript import Map from 'ti.map'; @@ -817,4 +830,4 @@ properties: - - - - type: Array \ No newline at end of file + type: Array From 929267906530b97358b73f3aeb72ae5cb70d1340 Mon Sep 17 00:00:00 2001 From: m1ga Date: Fri, 5 Apr 2024 12:31:51 +0200 Subject: [PATCH 3/4] lint docs --- apidoc/Map.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apidoc/Map.yml b/apidoc/Map.yml index 209cd7a6..47fcc00a 100644 --- a/apidoc/Map.yml +++ b/apidoc/Map.yml @@ -546,7 +546,7 @@ methods: parameters: - name: file summary: Ti.Blob of the KML file. - type: TiBlob + type: Object platforms: [android] since: "12.4.0" From 09f01f6653552043109485e4bf9fd281f6fda9a7 Mon Sep 17 00:00:00 2001 From: m1ga Date: Fri, 5 Apr 2024 12:37:01 +0200 Subject: [PATCH 4/4] lint --- android/src/ti/map/TiUIMapView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index c5806f65..02e90745 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -1455,7 +1455,7 @@ public void loadKml(KrollDict args) TiBlob file = TiConvert.toBlob(args.get("file")); try { KmlLayer layer = - new KmlLayer(map, file.getInputStream(), TiApplication.getInstance().getApplicationContext()); + new KmlLayer(map, file.getInputStream(), TiApplication.getInstance().getApplicationContext()); layer.addLayerToMap(); } catch (Exception ex) { Log.e(TAG, "Error: " + ex.getMessage());