Skip to content

Commit cd8fbec

Browse files
authored
[New Sample] Create and save map (#236)
2 parents 87bdc41 + 4419063 commit cd8fbec

File tree

26 files changed

+1072
-0
lines changed

26 files changed

+1072
-0
lines changed

configure-clusters/src/main/java/com/esri/arcgismaps/sample/configureclusters/screens/MainScreen.kt

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import androidx.compose.material3.DropdownMenuItem
3636
import androidx.compose.material3.ExperimentalMaterial3Api
3737
import androidx.compose.material3.ExposedDropdownMenuBox
3838
import androidx.compose.material3.ExposedDropdownMenuDefaults
39+
import androidx.compose.material3.ExtendedFloatingActionButton
3940
import androidx.compose.material3.FloatingActionButton
4041
import androidx.compose.material3.HorizontalDivider
4142
import androidx.compose.material3.Icon

create-and-save-map/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

create-and-save-map/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Create and save map
2+
3+
Create and save a map as a web map item to an ArcGIS portal.
4+
5+
![Image of create and save map](create-and-save-map.png)
6+
7+
## Use case
8+
9+
Maps can be created programmatically in code and then serialized and saved as an ArcGIS portal item. In this case, the portal item is a web map which can be shared with others and opened in various applications and APIs throughout the platform, such as ArcGIS Pro, ArcGIS Online, the JavaScript API, Collector, and Explorer.
10+
11+
## How to use the sample
12+
13+
When you run the sample, you will be challenged for an ArcGIS Online login. Enter a username and password for an ArcGIS Online named user account (such as your ArcGIS for Developers account). Then, tap the Edit Map button to choose the basemap and layers for your new map. To save the map, add a title, tags and description (optional), and a folder on your portal (you will need to create one in your portal's My Content section if you don't already have one). Click the Save to Account button to save the map to the chosen folder.
14+
15+
## How it works
16+
17+
1. Configure an `AuthenticatorState` to handle authentication challenges.
18+
2. Add the `AuthenticatorState` to a `DialogAuthenticator` in the app's `MainActivity` to invoke the authentication challenge.
19+
3. Create a new `Portal` and load it.
20+
4. Access the `PortalUserContent` with `portal.portalInfo?.user?.fetchContent()?.onSuccess`, to get the user's list of portal folders with `portalUserContent.folders`.
21+
5. Create an `ArcGISMap` with a `BasemapStyle` and a few operational layers.
22+
6. Call `ArcGISMap.saveMap()` to save a new `ArcGISMap` with the specified title, tags, and folder to the portal.
23+
24+
## Relevant API
25+
26+
* ArcGISMap
27+
* Portal
28+
29+
## Additional information
30+
31+
This sample uses the GeoViewCompose Toolkit module to be able to implement a Composable MapView.
32+
33+
## Tags
34+
35+
ArcGIS Online, ArcGIS Pro, geoviewcompose, portal, publish, share, web map
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"category": "Maps",
3+
"description": "Create and save a map as a web map item to an ArcGIS portal.",
4+
"formal_name": "CreateAndSaveMap",
5+
"ignore": false,
6+
"images": [
7+
"create-and-save-map.png"
8+
],
9+
"keywords": [
10+
"ArcGIS Online",
11+
"ArcGIS Pro",
12+
"geoviewcompose",
13+
"portal",
14+
"publish",
15+
"share",
16+
"web map",
17+
"ArcGISMap",
18+
"Portal"
19+
],
20+
"language": "kotlin",
21+
"redirect_from": "",
22+
"relevant_apis": [
23+
"ArcGISMap",
24+
"Portal"
25+
],
26+
"snippets": [
27+
"src/main/java/com/esri/arcgismaps/sample/createandsavemap/MainActivity.kt",
28+
"src/main/java/com/esri/arcgismaps/sample/createandsavemap/components/MapViewModel.kt",
29+
"src/main/java/com/esri/arcgismaps/sample/createandsavemap/screens/MainScreen.kt"
30+
],
31+
"title": "Create and save map"
32+
}

create-and-save-map/build.gradle.kts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
compileSdk = libs.versions.compileSdk.get().toInt()
8+
9+
defaultConfig {
10+
applicationId = "com.esri.arcgismaps.sample.createandsavemap"
11+
minSdk = libs.versions.minSdk.get().toInt()
12+
targetSdk = libs.versions.targetSdk.get().toInt()
13+
versionCode = libs.versions.versionCode.get().toInt()
14+
versionName = libs.versions.versionName.get()
15+
buildConfigField("String", "API_KEY", project.properties["API_KEY"].toString())
16+
}
17+
18+
buildTypes {
19+
release {
20+
isMinifyEnabled = false
21+
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
22+
}
23+
}
24+
25+
buildFeatures {
26+
compose = true
27+
buildConfig = true
28+
}
29+
30+
composeOptions {
31+
kotlinCompilerExtensionVersion = libs.versions.kotlinCompilerExt.get()
32+
}
33+
34+
namespace = "com.esri.arcgismaps.sample.createandsavemap"
35+
}
36+
37+
dependencies {
38+
// lib dependencies from rootProject build.gradle.kts
39+
implementation(libs.androidx.core.ktx)
40+
implementation(libs.androidx.lifecycle.runtime.ktx)
41+
implementation(libs.androidx.lifecycle.viewmodel.compose)
42+
implementation(libs.androidx.activity.compose)
43+
// Jetpack Compose Bill of Materials
44+
implementation(platform(libs.androidx.compose.bom))
45+
// Jetpack Compose dependencies
46+
implementation(libs.androidx.compose.ui)
47+
implementation(libs.androidx.compose.material3)
48+
implementation(libs.androidx.compose.ui.tooling)
49+
implementation(libs.androidx.compose.ui.tooling.preview)
50+
implementation(project(":samples-lib"))
51+
// Toolkit dependencies
52+
implementation(platform(libs.arcgis.maps.kotlin.toolkit.bom))
53+
implementation(libs.arcgis.maps.kotlin.toolkit.geoview.compose)
54+
implementation(libs.arcgis.maps.kotlin.toolkit.authentication)
55+
}
105 KB
Loading
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.kts.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity
14+
android:name=".MainActivity"
15+
android:exported="true">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
<activity
23+
android:name="com.arcgismaps.toolkit.authentication.OAuthUserSignInActivity"
24+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
25+
android:exported="true"
26+
android:launchMode="singleTop"> <!--keeps only one instance to the top of the stack-->
27+
<intent-filter>
28+
<action android:name="android.intent.action.VIEW" />
29+
<!--required to launch a custom browser tab-->
30+
<category android:name="android.intent.category.DEFAULT" />
31+
<category android:name="android.intent.category.BROWSABLE" />
32+
<!-- used as a redirect URI to navigate back to the app after prompting for OAuth credentials -->
33+
<data
34+
android:host="auth"
35+
android:scheme="create-save-map" />
36+
</intent-filter>
37+
</activity>
38+
</application>
39+
40+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Copyright 2024 Esri
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
17+
package com.esri.arcgismaps.sample.createandsavemap
18+
19+
import android.os.Bundle
20+
import androidx.activity.ComponentActivity
21+
import androidx.activity.compose.setContent
22+
import androidx.compose.material3.MaterialTheme
23+
import androidx.compose.material3.Surface
24+
import androidx.compose.runtime.Composable
25+
import androidx.lifecycle.viewmodel.compose.viewModel
26+
27+
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
28+
import com.esri.arcgismaps.sample.createandsavemap.screens.MainScreen
29+
import com.arcgismaps.toolkit.authentication.DialogAuthenticator
30+
import com.esri.arcgismaps.sample.createandsavemap.components.MapViewModel
31+
32+
class MainActivity : ComponentActivity() {
33+
34+
override fun onCreate(savedInstanceState: Bundle?) {
35+
super.onCreate(savedInstanceState)
36+
37+
setContent {
38+
SampleAppTheme {
39+
SampleApp()
40+
}
41+
}
42+
}
43+
44+
@Composable
45+
private fun SampleApp() {
46+
val mapViewModel: MapViewModel = viewModel()
47+
Surface(
48+
color = MaterialTheme.colorScheme.background
49+
) {
50+
MainScreen(
51+
sampleName = getString(R.string.app_name)
52+
)
53+
}
54+
55+
// authenticator at bottom can draw over the top of the sample
56+
DialogAuthenticator(authenticatorState = mapViewModel.authenticatorState)
57+
}
58+
}

0 commit comments

Comments
 (0)