From c3cfdc2203e6eea5d2037b2aa9c2b04b5225f8b4 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 3 Apr 2024 11:20:21 +0200 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] 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()); From 62b9d166f88a6b0eb195fb42198d4d8d29a80999 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 1 Oct 2025 20:45:29 +0200 Subject: [PATCH 05/12] geojson, setters --- android/src/ti/map/TiUIMapView.java | 37 +++++++++++++++++++---------- android/src/ti/map/ViewProxy.java | 19 ++++++++++----- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index 02e90745..bf343dfc 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.geojson.GeoJsonLayer; import com.google.maps.android.data.kml.KmlLayer; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -1449,17 +1450,27 @@ public boolean onClusterItemClick(TiMarker tiMarker) return onMarkerClick(tiMarker.getMarker()); } - public void loadKml(KrollDict args) - { - 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()); - } - } - } + public void loadKml(TiBlob file) { + if (map != null) { + try { + KmlLayer layer = + new KmlLayer(map, file.getInputStream(), TiApplication.getInstance().getApplicationContext()); + layer.addLayerToMap(); + } catch (Exception ex) { + Log.e(TAG, "Error: " + ex.getMessage()); + } + } + } + + public void loadGeoJSON(String json) { + if (map != null) { + try { + JSONObject jsonObject = new JSONObject(json); + GeoJsonLayer layer = new GeoJsonLayer(map, jsonObject); + 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 2a561f28..05b1f210 100644 --- a/android/src/ti/map/ViewProxy.java +++ b/android/src/ti/map/ViewProxy.java @@ -27,6 +27,7 @@ import org.appcelerator.kroll.common.Log; import org.appcelerator.kroll.common.TiMessenger; import org.appcelerator.titanium.TiApplication; +import org.appcelerator.titanium.TiBlob; import org.appcelerator.titanium.TiC; import org.appcelerator.titanium.proxy.TiViewProxy; import org.appcelerator.titanium.util.TiConvert; @@ -1514,17 +1515,23 @@ public void setClusterAnnotation() { } - @Kroll.method - public void loadKml(KrollDict args) + @Kroll.setProperty + public void kml(TiBlob file) { - 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(file); + } else { + Log.e(TAG, "Map is not available"); } + } + @Kroll.setProperty + public void geoJSON(String json) + { TiUIView view = peekView(); if (view instanceof TiUIMapView) { - ((TiUIMapView) view).loadKml(args); + ((TiUIMapView) view).loadGeoJSON(json); } else { Log.e(TAG, "Map is not available"); } From 47a82d7c487e97cf3abd5d3aac06c65bda65b655 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 1 Oct 2025 20:49:03 +0200 Subject: [PATCH 06/12] docs --- apidoc/Map.yml | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/apidoc/Map.yml b/apidoc/Map.yml index 47fcc00a..cf2df492 100644 --- a/apidoc/Map.yml +++ b/apidoc/Map.yml @@ -506,6 +506,23 @@ properties: osver: {ios: {min: "13.0"} } since: "12.3.0" + - name: kml + 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. + type: Object + exclude-platforms: [iphone, ipad, macos] + since: "13.1.0" + + - name: geoJSON + summary: | + Loads a geoJSON and displays the content on the map. + type: String + exclude-platforms: [iphone, ipad, macos] + since: "13.1.0" + methods: - name: isGooglePlayServicesAvailable returns: @@ -537,19 +554,6 @@ 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: Object - platforms: [android] - since: "12.4.0" - - name: geocodeAddress summary: | Resolve address details using the `CLGeocoder` to get information (e.g. From a96ad3f982a4de9f483f32d98642e03a823be411 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 1 Oct 2025 20:53:04 +0200 Subject: [PATCH 07/12] lint --- android/src/ti/map/TiUIMapView.java | 48 +++++++++++++++-------------- android/src/ti/map/ViewProxy.java | 2 -- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index bf343dfc..92732c7a 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -1450,27 +1450,29 @@ public boolean onClusterItemClick(TiMarker tiMarker) return onMarkerClick(tiMarker.getMarker()); } - public void loadKml(TiBlob file) { - if (map != null) { - try { - KmlLayer layer = - new KmlLayer(map, file.getInputStream(), TiApplication.getInstance().getApplicationContext()); - layer.addLayerToMap(); - } catch (Exception ex) { - Log.e(TAG, "Error: " + ex.getMessage()); - } - } - } - - public void loadGeoJSON(String json) { - if (map != null) { - try { - JSONObject jsonObject = new JSONObject(json); - GeoJsonLayer layer = new GeoJsonLayer(map, jsonObject); - layer.addLayerToMap(); - } catch (Exception ex) { - Log.e(TAG, "Error: " + ex.getMessage()); - } - } - } + public void loadKml(TiBlob file) + { + if (map != null) { + try { + KmlLayer layer = + new KmlLayer(map, file.getInputStream(), TiApplication.getInstance().getApplicationContext()); + layer.addLayerToMap(); + } catch (Exception ex) { + Log.e(TAG, "Error: " + ex.getMessage()); + } + } + } + + public void loadGeoJSON(String json) + { + if (map != null) { + try { + JSONObject jsonObject = new JSONObject(json); + GeoJsonLayer layer = new GeoJsonLayer(map, jsonObject); + 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 05b1f210..07622118 100644 --- a/android/src/ti/map/ViewProxy.java +++ b/android/src/ti/map/ViewProxy.java @@ -10,9 +10,7 @@ import android.os.Message; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.MapView; import com.google.android.gms.maps.model.LatLng; -import com.google.android.gms.maps.model.TileOverlay; import com.google.android.gms.maps.model.TileOverlayOptions; import com.google.maps.android.heatmaps.HeatmapTileProvider; import java.util.ArrayList; From 639c8a72342e96bb581414d6274331fa54ec23f6 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 1 Oct 2025 21:03:12 +0200 Subject: [PATCH 08/12] property and loading optimization --- android/src/ti/map/TiUIMapView.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index 92732c7a..bf80ae71 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -90,6 +90,8 @@ public class TiUIMapView extends TiUIFragment private DefaultClusterRenderer clusterRender; private MarkerManager mMarkerManager; private MarkerManager.Collection collection; + private String localGeoJson; + private TiBlob localKml; public TiUIMapView(final TiViewProxy proxy, Activity activity) { @@ -324,6 +326,12 @@ public void processMapProperties(KrollDict d) if (clusterRender != null) clusterRender.setMinClusterSize(d.getInt(MapModule.PROPERTY_MIN_CLUSTER_SIZE)); } + if (d.containsKey("kml")) { + localKml = TiConvert.toBlob(d.get("kml")); + } + if (d.containsKey("geoJSON")) { + localGeoJson = d.getString("geoJSON"); + } } @Override @@ -1418,6 +1426,12 @@ public void onMapLoaded() if (proxy != null) { proxy.fireEvent(TiC.EVENT_COMPLETE, null); } + if (!localGeoJson.isEmpty()) { + loadGeoJSON(localGeoJson); + } + if (localKml != null) { + loadKml(localKml); + } } protected void onViewCreated() @@ -1460,6 +1474,9 @@ public void loadKml(TiBlob file) } catch (Exception ex) { Log.e(TAG, "Error: " + ex.getMessage()); } + localKml = null; + } else { + localKml = file; } } @@ -1473,6 +1490,9 @@ public void loadGeoJSON(String json) } catch (Exception ex) { Log.e(TAG, "Error: " + ex.getMessage()); } + localGeoJson = null; + } else { + localGeoJson = json; } } } From 27f885c2bdbbfc51c472bc993847d392679a9931 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 1 Oct 2025 21:04:39 +0200 Subject: [PATCH 09/12] version --- android/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/manifest b/android/manifest index 41316e6a..93033be0 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.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 From 157f3b604ec168d5d566598d6b1cabe478d27da6 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 1 Oct 2025 21:37:00 +0200 Subject: [PATCH 10/12] more properties --- android/src/ti/map/TiUIMapView.java | 29 ++++++++++++++++++++++------- android/src/ti/map/ViewProxy.java | 4 ++-- apidoc/Map.yml | 19 ++++++++++++++++++- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index bf80ae71..0e25315b 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -40,6 +40,7 @@ import com.google.maps.android.clustering.view.DefaultClusterRenderer; import com.google.maps.android.collections.MarkerManager; import com.google.maps.android.data.geojson.GeoJsonLayer; +import com.google.maps.android.data.geojson.GeoJsonPolygonStyle; import com.google.maps.android.data.kml.KmlLayer; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -90,7 +91,7 @@ public class TiUIMapView extends TiUIFragment private DefaultClusterRenderer clusterRender; private MarkerManager mMarkerManager; private MarkerManager.Collection collection; - private String localGeoJson; + private KrollDict localGeoJson; private TiBlob localKml; public TiUIMapView(final TiViewProxy proxy, Activity activity) @@ -326,11 +327,11 @@ public void processMapProperties(KrollDict d) if (clusterRender != null) clusterRender.setMinClusterSize(d.getInt(MapModule.PROPERTY_MIN_CLUSTER_SIZE)); } - if (d.containsKey("kml")) { + if (d.containsKeyAndNotNull("kml")) { localKml = TiConvert.toBlob(d.get("kml")); } - if (d.containsKey("geoJSON")) { - localGeoJson = d.getString("geoJSON"); + if (d.containsKeyAndNotNull("geoJSON")) { + localGeoJson = d.getKrollDict("geoJSON"); } } @@ -1426,7 +1427,7 @@ public void onMapLoaded() if (proxy != null) { proxy.fireEvent(TiC.EVENT_COMPLETE, null); } - if (!localGeoJson.isEmpty()) { + if (localGeoJson != null) { loadGeoJSON(localGeoJson); } if (localKml != null) { @@ -1480,19 +1481,33 @@ public void loadKml(TiBlob file) } } - public void loadGeoJSON(String json) + public void loadGeoJSON(KrollDict obj) { if (map != null) { try { + String json = obj.getString("json"); JSONObject jsonObject = new JSONObject(json); GeoJsonLayer layer = new GeoJsonLayer(map, jsonObject); + GeoJsonPolygonStyle polygonStyle = layer.getDefaultPolygonStyle(); + + if (obj.containsKeyAndNotNull("strokeWidth")) { + polygonStyle.setStrokeWidth(obj.getInt("strokeWidth")); + } + if (obj.containsKeyAndNotNull("strokeColor")) { + polygonStyle.setStrokeColor( + TiConvert.toColor(obj.getString("strokeColor"), TiApplication.getAppRootOrCurrentActivity())); + } + if (obj.containsKeyAndNotNull("dimColor")) { + polygonStyle.setFillColor( + TiConvert.toColor(obj.getString("dimColor"), TiApplication.getAppRootOrCurrentActivity())); + } layer.addLayerToMap(); } catch (Exception ex) { Log.e(TAG, "Error: " + ex.getMessage()); } localGeoJson = null; } else { - localGeoJson = json; + localGeoJson = obj; } } } diff --git a/android/src/ti/map/ViewProxy.java b/android/src/ti/map/ViewProxy.java index 07622118..21df6184 100644 --- a/android/src/ti/map/ViewProxy.java +++ b/android/src/ti/map/ViewProxy.java @@ -1525,11 +1525,11 @@ public void kml(TiBlob file) } @Kroll.setProperty - public void geoJSON(String json) + public void geoJSON(KrollDict obj) { TiUIView view = peekView(); if (view instanceof TiUIMapView) { - ((TiUIMapView) view).loadGeoJSON(json); + ((TiUIMapView) view).loadGeoJSON(obj); } else { Log.e(TAG, "Map is not available"); } diff --git a/apidoc/Map.yml b/apidoc/Map.yml index cf2df492..8be3805b 100644 --- a/apidoc/Map.yml +++ b/apidoc/Map.yml @@ -519,7 +519,7 @@ properties: - name: geoJSON summary: | Loads a geoJSON and displays the content on the map. - type: String + type: GeoJsonType exclude-platforms: [iphone, ipad, macos] since: "13.1.0" @@ -806,6 +806,23 @@ examples: }); ``` +--- +name: GeoJsonType +summary: An object representing a geoJSON object. +properties: + - name: json + summary: JSON string to render on the map + type: String + - name: dimColor + summary: color of the area + type: String + - name: strokeColor + summary: stroke color of the area + type: String + - name: strokeWidth + summary: width of the stroke + type: Number + --- name: MapPointType summary: An object representing a point on the map. From f0b20558046916613386e6b62b20a37ebba4dedb Mon Sep 17 00:00:00 2001 From: m1ga Date: Thu, 2 Oct 2025 14:21:00 +0200 Subject: [PATCH 11/12] change property names --- android/src/ti/map/TiUIMapView.java | 34 ++++++++++++++++++++++------- apidoc/Map.yml | 16 ++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index 0e25315b..872d79c0 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -53,6 +53,7 @@ import org.appcelerator.titanium.TiApplication; import org.appcelerator.titanium.TiBlob; import org.appcelerator.titanium.TiC; +import org.appcelerator.titanium.io.TiBaseFile; import org.appcelerator.titanium.io.TiFileFactory; import org.appcelerator.titanium.proxy.TiViewProxy; import org.appcelerator.titanium.util.TiConvert; @@ -1485,21 +1486,38 @@ public void loadGeoJSON(KrollDict obj) { if (map != null) { try { - String json = obj.getString("json"); - JSONObject jsonObject = new JSONObject(json); + JSONObject jsonObject; + + if (obj.containsKeyAndNotNull("json")) { + String json = obj.getString("json"); + jsonObject = new JSONObject(json); + } else if (obj.containsKeyAndNotNull(TiC.PROPERTY_FILE)) { + String url = proxy.resolveUrl(null, obj.getString(TiC.PROPERTY_FILE)); + TiBaseFile file = TiFileFactory.createTitaniumFile(new String[]{url}, false); + if (file.exists()) { + jsonObject = new JSONObject(file.read().toString()); + } else { + Log.e(TAG, "File not found"); + return; + } + } else { + Log.e(TAG, "To use a geoJSON you'll need to either set the 'file' or 'json' property."); + return; + } + GeoJsonLayer layer = new GeoJsonLayer(map, jsonObject); GeoJsonPolygonStyle polygonStyle = layer.getDefaultPolygonStyle(); - if (obj.containsKeyAndNotNull("strokeWidth")) { - polygonStyle.setStrokeWidth(obj.getInt("strokeWidth")); + if (obj.containsKeyAndNotNull(TiC.PROPERTY_BORDER_WIDTH)) { + polygonStyle.setStrokeWidth(obj.getInt(TiC.PROPERTY_BORDER_WIDTH)); } - if (obj.containsKeyAndNotNull("strokeColor")) { + if (obj.containsKeyAndNotNull(TiC.PROPERTY_BORDER_COLOR)) { polygonStyle.setStrokeColor( - TiConvert.toColor(obj.getString("strokeColor"), TiApplication.getAppRootOrCurrentActivity())); + TiConvert.toColor(obj.getString(TiC.PROPERTY_BORDER_COLOR), TiApplication.getAppRootOrCurrentActivity())); } - if (obj.containsKeyAndNotNull("dimColor")) { + if (obj.containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_COLOR)) { polygonStyle.setFillColor( - TiConvert.toColor(obj.getString("dimColor"), TiApplication.getAppRootOrCurrentActivity())); + TiConvert.toColor(obj.getString(TiC.PROPERTY_BACKGROUND_COLOR), TiApplication.getAppRootOrCurrentActivity())); } layer.addLayerToMap(); } catch (Exception ex) { diff --git a/apidoc/Map.yml b/apidoc/Map.yml index 8be3805b..c74a6e9f 100644 --- a/apidoc/Map.yml +++ b/apidoc/Map.yml @@ -811,16 +811,18 @@ name: GeoJsonType summary: An object representing a geoJSON object. properties: - name: json - summary: JSON string to render on the map + summary: JSON string to render on the map (use either 'json' or 'file'). + - name: file + summary: file name of the geoJSON file (use either 'json' or 'file'). type: String - - name: dimColor - summary: color of the area + - name: backgroundColor + summary: background color of the area. type: String - - name: strokeColor - summary: stroke color of the area + - name: borderColor + summary: border color of the area. type: String - - name: strokeWidth - summary: width of the stroke + - name: borderWidth + summary: width of the border. type: Number --- From af237f7cede4103b0aeebc22a2655b162c71c35c Mon Sep 17 00:00:00 2001 From: m1ga Date: Thu, 2 Oct 2025 14:22:26 +0200 Subject: [PATCH 12/12] lint --- android/src/ti/map/TiUIMapView.java | 10 +++++----- apidoc/Map.yml | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index 872d79c0..111d3470 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -1493,7 +1493,7 @@ public void loadGeoJSON(KrollDict obj) jsonObject = new JSONObject(json); } else if (obj.containsKeyAndNotNull(TiC.PROPERTY_FILE)) { String url = proxy.resolveUrl(null, obj.getString(TiC.PROPERTY_FILE)); - TiBaseFile file = TiFileFactory.createTitaniumFile(new String[]{url}, false); + TiBaseFile file = TiFileFactory.createTitaniumFile(new String[] { url }, false); if (file.exists()) { jsonObject = new JSONObject(file.read().toString()); } else { @@ -1512,12 +1512,12 @@ public void loadGeoJSON(KrollDict obj) polygonStyle.setStrokeWidth(obj.getInt(TiC.PROPERTY_BORDER_WIDTH)); } if (obj.containsKeyAndNotNull(TiC.PROPERTY_BORDER_COLOR)) { - polygonStyle.setStrokeColor( - TiConvert.toColor(obj.getString(TiC.PROPERTY_BORDER_COLOR), TiApplication.getAppRootOrCurrentActivity())); + polygonStyle.setStrokeColor(TiConvert.toColor(obj.getString(TiC.PROPERTY_BORDER_COLOR), + TiApplication.getAppRootOrCurrentActivity())); } if (obj.containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_COLOR)) { - polygonStyle.setFillColor( - TiConvert.toColor(obj.getString(TiC.PROPERTY_BACKGROUND_COLOR), TiApplication.getAppRootOrCurrentActivity())); + polygonStyle.setFillColor(TiConvert.toColor(obj.getString(TiC.PROPERTY_BACKGROUND_COLOR), + TiApplication.getAppRootOrCurrentActivity())); } layer.addLayerToMap(); } catch (Exception ex) { diff --git a/apidoc/Map.yml b/apidoc/Map.yml index c74a6e9f..03acf82f 100644 --- a/apidoc/Map.yml +++ b/apidoc/Map.yml @@ -812,8 +812,9 @@ summary: An object representing a geoJSON object. properties: - name: json summary: JSON string to render on the map (use either 'json' or 'file'). + type: String - name: file - summary: file name of the geoJSON file (use either 'json' or 'file'). + summary: filename of the geoJSON file (use either 'json' or 'file'). type: String - name: backgroundColor summary: background color of the area.