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

Create KML mutli track #309

Merged
merged 18 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 11 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
40 changes: 40 additions & 0 deletions samples/create-kml-multi-track/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Create KML multi track

Create a KML multi-track by recording simulated location data, then save and preview your recorded hiking paths.

![Create KML multi track sample app](create-kml-multi-track.png)

## Use case

When you are hiking along a trail, it can be useful to record your path and share it later as a KML file. You might also want to capture multiple tracks in one trip. This sample demonstrates how you can collect individual KML tracks during a navigation session, then combine and export them as a single KML multi-track.
shubham7109 marked this conversation as resolved.
Show resolved Hide resolved

## How to use the sample

Tap **Start Navigation** to begin moving along a simulated trail. Tap **Record Track** to start recording your current path. Tap **Stop Recording** to end recording. Repeat steps to capture multiple KML tracks in a single session. Tap **Save** button to save your recorded tracks as a `.kmz` file to local storage. Then review tracks to load and display the created `.kmz` file containing your KML multi-track.

## How it works

1. Use an `ArcGISMap` to display a basemap and a path geometry for your navigation route.
2. Create a simulated location data source (`SimulatedLocationDataSource`) to drive the `LocationDisplay`.
shubham7109 marked this conversation as resolved.
Show resolved Hide resolved
3. As you receive `Location` updates, add each point to a list of `KmlTrackElement` objects while recording.
4. Combine one or more `KmlTrack` objects into a `KmlMultiTrack`.
shubham7109 marked this conversation as resolved.
Show resolved Hide resolved
5. Save the `KmlMultiTrack` inside a `KmlDocument`, then export the document to a `.kmz` file.
6. Load the saved `.kmz` file into a `KmlDataset` to preview your tracks on the map.

## Relevant API

- KmlDataset
- KmlDocument
- KmlMultiTrack
- KmlPlacemark
- KmlTrack
- LocationDisplay
- SimulatedLocationDataSource

## Additional information

This sample uses the GeoView-Compose Toolkit module to be able to implement a composable MapView.

## Tags

export, geoview-compose, hiking, kml, kmz, mutli-track, record, track
shubham7109 marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions samples/create-kml-multi-track/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"category": "Edit and Manage Data",
"description": "Create a KML multi-track by recording simulated location data, then save and preview your recorded hiking paths.",
"formal_name": "CreateKmlMultiTrack",
"ignore": false,
"images": [
"create-kml-multi-track.png"
],
"keywords": [
"export",
"geoview-compose",
"hiking",
"kml",
"kmz",
"mutli-track",
shubham7109 marked this conversation as resolved.
Show resolved Hide resolved
"record",
"track",
"KmlDataset",
"KmlDocument",
"KmlMultiTrack",
"KmlPlacemark",
"KmlTrack",
"LocationDisplay",
"SimulatedLocationDataSource"
],
"language": "kotlin",
"redirect_from": "",
"relevant_apis": [
"KmlDataset",
"KmlDocument",
"KmlMultiTrack",
"KmlPlacemark",
"KmlTrack",
"LocationDisplay",
"SimulatedLocationDataSource"
],
"snippets": [
"src/main/java/com/esri/arcgismaps/sample/createkmlmultitrack/components/CreateKMLMultiTrackViewModel.kt",
"src/main/java/com/esri/arcgismaps/sample/createkmlmultitrack/MainActivity.kt",
"src/main/java/com/esri/arcgismaps/sample/createkmlmultitrack/screens/CreateKMLMultiTrackScreen.kt"
],
"title": "Create KML multi track"
}
22 changes: 22 additions & 0 deletions samples/create-kml-multi-track/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
alias(libs.plugins.arcgismaps.android.library)
alias(libs.plugins.arcgismaps.android.library.compose)
alias(libs.plugins.arcgismaps.kotlin.sample)
alias(libs.plugins.gradle.secrets)
}

secrets {
// this file doesn't contain secrets, it just provides defaults which can be committed into git.
defaultPropertiesFileName = "secrets.defaults.properties"
}

android {
namespace = "com.esri.arcgismaps.sample.createkmlmultitrack"
buildFeatures {
buildConfig = true
}
}

dependencies {
// Only module specific dependencies needed here
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions samples/create-kml-multi-track/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application><activity
android:exported="true"
android:name=".MainActivity"
android:label="@string/create_kml_multi_track_app_name">

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.esri.arcgismaps.sample.createkmlmultitrack

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.createkmlmultitrack.screens.CreateKMLMultiTrackScreen

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)

setContent {
SampleAppTheme {
CreateKMLMultiTrackApp()
}
}
}

@Composable
private fun CreateKMLMultiTrackApp() {
Surface(color = MaterialTheme.colorScheme.background) {
CreateKMLMultiTrackScreen(
sampleName = getString(R.string.create_kml_multi_track_app_name)
)
}
}
}
Loading
Loading