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

update new module script to use geo-compose toolkit component #148

Merged
merged 10 commits into from
Dec 14, 2023
Merged
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
3 changes: 3 additions & 0 deletions display-composable-mapview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation project(path: ':samples-lib')
// Toolkit dependencies
implementation(platform("com.esri:arcgis-maps-kotlin-toolkit-bom:$arcgisToolkitVersion"))
implementation('com.esri:arcgis-maps-kotlin-toolkit-geo-compose')
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new module created when the script is used, but I don't think it should require any sample changes. The DisplayComposableMapView sample should be a basic implementation of the DisplayMap sample, i.e. render a map with a basemap style.

The module script can spin up a sample with touch event implementation, but let's keep this sample similar to DisplayMap with the geo-compose module.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this change. Although with the previous version of display-composable-mapview sample, we did have the touch event implementation in addition to displaying the map with a particular basemap style. Not sure if there was any particular intention of doing it that way back then? But I too feel it should be similar to the display map sample.

Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,20 @@ package com.esri.arcgismaps.sample.displaycomposablemapview
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.mapping.Viewpoint
import com.arcgismaps.toolkit.geocompose.MapView
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme

class MainActivity : ComponentActivity() {

private val viewpointAmerica = Viewpoint(39.8, -98.6, 10e7)
private val viewpointAsia = Viewpoint(39.8, 98.6, 10e7)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
Expand All @@ -47,27 +41,12 @@ class MainActivity : ComponentActivity() {

setContent {
SampleAppTheme {
Column(
// create a map with a navigation night basemap style
val map = ArcGISMap(BasemapStyle.ArcGISNavigationNight)
MapView(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
// a mutable/immutable state is computed by remember to store its value during
// initial composition, and updates the composition on the state value change
var viewpoint by remember { mutableStateOf(viewpointAmerica) }
val map by remember { mutableStateOf(ArcGISMap(BasemapStyle.ArcGISNavigationNight)) }

// Composable function that wraps the MapView
MapViewWithCompose(
arcGISMap = map,
viewpoint = viewpoint,
// lambda to retrieve the MapView's onSingleTapConfirmed
onSingleTap = {
// swap between America and Asia viewpoints
viewpoint =
if (viewpoint == viewpointAmerica) viewpointAsia else viewpointAmerica
}
)
}
arcGISMap = map
)
}
}
}
Expand Down

This file was deleted.

Binary file modified tools/NewModuleScript.jar
Binary file not shown.
87 changes: 0 additions & 87 deletions tools/NewModuleScript/ComposeMapViewTemplate.kt

This file was deleted.

32 changes: 16 additions & 16 deletions tools/NewModuleScript/MainScreenTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
package com.esri.arcgismaps.sample.displaycomposablemapview.screens

import android.app.Application
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.esri.arcgismaps.sample.displaycomposablemapview.components.ComposeMapView
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.toolkit.geocompose.MapView
import com.arcgismaps.toolkit.geocompose.MapViewpointOperation
import com.esri.arcgismaps.sample.displaycomposablemapview.components.MapViewModel
import com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar

Expand All @@ -34,24 +39,19 @@ import com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar
fun MainScreen(sampleName: String, application: Application) {
// create a ViewModel to handle MapView interactions
val mapViewModel = MapViewModel(application)
val arcGISMap by remember { mutableStateOf(ArcGISMap(BasemapStyle.ArcGISNavigationNight)) }

Scaffold(
topBar = { SampleTopAppBar(title = sampleName) },
content = {
Column(
modifier = Modifier
.fillMaxSize()
.padding(it)
) {
// composable function that wraps the MapView
ComposeMapView(
modifier = Modifier.fillMaxSize(),
mapViewModel = mapViewModel,
onSingleTap = {
mapViewModel.changeBasemap()
}
)
}
MapView(
modifier = Modifier.fillMaxSize().padding(it),
arcGISMap = arcGISMap,
viewpointOperation = MapViewpointOperation.Set(viewpoint = mapViewModel.viewpoint.value),
onSingleTapConfirmed = {
mapViewModel.changeBasemap()
}
)
}
)
}
29 changes: 6 additions & 23 deletions tools/NewModuleScript/MapViewModelTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,19 @@
package com.esri.arcgismaps.sample.displaycomposablemapview.components

import android.app.Application
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.AndroidViewModel
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.mapping.Viewpoint
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update

class MapViewModel(application: Application) : AndroidViewModel(application) {
// set the MapView mutable stateflow
val mapViewState = MutableStateFlow(MapViewState())

private val viewpointAmerica = Viewpoint(39.8, -98.6, 10e7)
private val viewpointAsia = Viewpoint(39.8, 98.6, 10e7)
var viewpoint = mutableStateOf(viewpointAmerica)
/**
* Switch between two basemaps
*/
fun changeBasemap() {
val newArcGISMap: ArcGISMap =
if (mapViewState.value.arcGISMap.basemap.value?.name.equals("ArcGIS:NavigationNight")) {
ArcGISMap(BasemapStyle.ArcGISStreets)
} else {
ArcGISMap(BasemapStyle.ArcGISNavigationNight)
}
mapViewState.update { it.copy(arcGISMap = newArcGISMap) }
viewpoint.value =
if (viewpoint.value == viewpointAmerica) viewpointAsia else viewpointAmerica
}
}


/**
* Data class that represents the MapView state
*/
data class MapViewState( // This would change based on each sample implementation
var arcGISMap: ArcGISMap = ArcGISMap(BasemapStyle.ArcGISNavigationNight),
var viewpoint: Viewpoint = Viewpoint(39.8, -98.6, 10e7)
)
32 changes: 8 additions & 24 deletions tools/NewModuleScript/src/main/java/ScriptMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private void createFilesAndFolders() {

// Copy Kotlin template files to new sample
File mainActivityTemplate = new File(samplesRepoPath + "/tools/NewModuleScript/MainActivityTemplate.kt");
File composeMapViewTemplate = new File(samplesRepoPath + "/tools/NewModuleScript/ComposeMapViewTemplate.kt");
File mapViewModelTemplate = new File(samplesRepoPath + "/tools/NewModuleScript/MapViewModelTemplate.kt");
File mainScreenTemplate = new File(samplesRepoPath + "/tools/NewModuleScript/MainScreenTemplate.kt");

Expand All @@ -109,20 +108,17 @@ private void createFilesAndFolders() {
Path source = Paths.get(packageDirectory+"/MainActivityTemplate.kt");
Files.move(source, source.resolveSibling("MainActivity.kt"));

File composeComponentsDir = new File(packageDirectory + "/components");
composeComponentsDir.mkdirs();
FileUtils.copyFileToDirectory(composeMapViewTemplate, composeComponentsDir);
source = Paths.get(composeComponentsDir+"/ComposeMapViewTemplate.kt");
Files.move(source, source.resolveSibling("ComposeMapView.kt"));
File componentsDir = new File(packageDirectory + "/components");
componentsDir.mkdirs();

FileUtils.copyFileToDirectory(mapViewModelTemplate, composeComponentsDir);
source = Paths.get(composeComponentsDir+"/MapViewModelTemplate.kt");
FileUtils.copyFileToDirectory(mapViewModelTemplate, componentsDir);
source = Paths.get(componentsDir+"/MapViewModelTemplate.kt");
Files.move(source, source.resolveSibling("MapViewModel.kt"));

composeComponentsDir = new File(packageDirectory + "/screens");
composeComponentsDir.mkdirs();
FileUtils.copyFileToDirectory(mainScreenTemplate, composeComponentsDir);
source = Paths.get(composeComponentsDir+"/MainScreenTemplate.kt");
componentsDir = new File(packageDirectory + "/screens");
componentsDir.mkdirs();
FileUtils.copyFileToDirectory(mainScreenTemplate, componentsDir);
source = Paths.get(componentsDir+"/MainScreenTemplate.kt");
Files.move(source, source.resolveSibling("MainScreen.kt"));
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -201,18 +197,6 @@ private void updateSampleContent() {
exitProgram(e);
}

//Update ComposeMapView.kt
file = new File(samplesRepoPath + "/" + sampleWithHyphen + "/src/main/java/com/esri/arcgismaps/sample/"+sampleWithoutSpaces+"/components/ComposeMapView.kt");
try {
String fileContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
fileContent = fileContent.replace("Copyright 2023", "Copyright " + Calendar.getInstance().get(Calendar.YEAR));
fileContent = fileContent.replace("sample.displaycomposablemapview", "sample." + sampleWithoutSpaces);
FileUtils.write(file,fileContent, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
exitProgram(e);
}

//Update MapViewModel.kt
file = new File(samplesRepoPath + "/" + sampleWithHyphen + "/src/main/java/com/esri/arcgismaps/sample/"+sampleWithoutSpaces+"/components/MapViewModel.kt");
try {
Expand Down
2 changes: 1 addition & 1 deletion version.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext {
// ArcGIS Maps SDK for Kotlin version
arcgisVersion = '200.3.0-4075'
// ArcGIS Maps SDK for Kotlin Toolkit version
arcgisToolkitVersion = '200.3.0-4075'
arcgisToolkitVersion = '200.3.0-1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be 200.3.0 ?

Copy link
Author

@prupani-7 prupani-7 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

200.3.0-1 is the published toolkit version where the geo-compose MapView is available
https://devtopia.esri.com/runtime/kotlin/issues/3358#issuecomment-4463774

// SDK versions
compileSdkVersion = 33
minSdkVersion = 26
Expand Down
Loading