Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: KML support #692

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
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
15 changes: 15 additions & 0 deletions android/src/ti/map/TiUIMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1447,4 +1448,18 @@ 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());
}
}
}
}
16 changes: 16 additions & 0 deletions android/src/ti/map/ViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,22 @@ 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");
}
}

public String getApiName()
{
return "Ti.Map.View";
Expand Down
31 changes: 22 additions & 9 deletions apidoc/Map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ description: |
<manifest>
<application>
<!-- Replace "YOUR_API_KEY" with the Google API key you obtained -->
<meta-data
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />
</application>
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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: Object
platforms: [android]
since: "12.4.0"

- name: geocodeAddress
summary: |
Resolve address details using the `CLGeocoder` to get information (e.g.
Expand Down Expand Up @@ -614,7 +627,7 @@ examples:

const mapView = Map.createView({
mapType: Map.NORMAL_TYPE,
region: {
region: {
latitude: 33.74511,
longitude: -84.38993,
latitudeDelta: 0.01,
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -817,4 +830,4 @@ properties:
- <Modules.Map.SEARCH_RESULT_TYPE_ADDRESS>
- <Modules.Map.SEARCH_RESULT_TYPE_POINT_OF_INTEREST>
- <Modules.Map.SEARCH_RESULT_TYPE_QUERY>
type: Array<Number>
type: Array<Number>
Loading