-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include 200.6 samples changes (#249)
- Loading branch information
1 parent
869aec6
commit 5da2313
Showing
33 changed files
with
1,579 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Add ENC exchange set | ||
|
||
Display nautical charts per the ENC specification. | ||
|
||
![Image showing the add ENC exchange set app](add-enc-exchange-set.png) | ||
|
||
## Use case | ||
|
||
The [ENC specification](https://docs.iho.int/iho_pubs/standard/S-57Ed3.1/20ApB1.pdf) describes how hydrographic data should be displayed digitally. | ||
|
||
An ENC exchange set is a catalog of data files which can be loaded as cells. The cells contain information on how symbols should be displayed in relation to one another, so as to represent information such as depth and obstacles accurately. | ||
|
||
## How to use the sample | ||
|
||
Run the sample and view the ENC data. Pan and zoom around the map. Take note of the high level of detail in the data and the smooth rendering of the layer. | ||
|
||
## How it works | ||
|
||
1. Specify the path to a local CATALOG.031 file to create an `EncExchangeSet`. | ||
2. After loading the exchange set, get the `EncDataset` objects in the exchange set with `EncExchangeSet.datasets`. | ||
3. Create an `EncCell` for each dataset. Then create an `EncLayer` for each cell. | ||
4. Add the ENC layer to a map's operational layers collection to display it. | ||
|
||
## Relevant API | ||
|
||
* EncCell | ||
* EncDataset | ||
* EncExchangeSet | ||
* EncLayer | ||
|
||
## Offline data | ||
|
||
This sample downloads the [ENC Exchange Set without updates](https://www.arcgis.com/home/item.html?id=9d2987a825c646468b3ce7512fb76e2d) and [Hydrography dataset resources](https://www.arcgis.com/home/item.html?id=5028bf3513ff4c38b28822d010a4937c) from ArcGIS Online. | ||
|
||
## Additional information | ||
|
||
This sample uses the GeoViewCompose Toolkit module to be able to implement a Composable SceneView. | ||
|
||
## Tags | ||
|
||
data, ENC, geoviewcompose, hydrographic, layers, maritime, nautical chart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"category": "Layers", | ||
"description": "Display nautical charts per the ENC specification.", | ||
"formal_name": "AddEncExchangeSet", | ||
"ignore": false, | ||
"images": [ | ||
"add-enc-exchange-set.png" | ||
], | ||
"keywords": [ | ||
"ENC", | ||
"data", | ||
"geoviewcompose", | ||
"hydrographic", | ||
"layers", | ||
"maritime", | ||
"nautical chart", | ||
"EncCell", | ||
"EncDataset", | ||
"EncExchangeSet", | ||
"EncLayer" | ||
], | ||
"language": "kotlin", | ||
"provision_from": [ | ||
"https://www.arcgis.com/home/item.html?id=9d2987a825c646468b3ce7512fb76e2d", | ||
"https://www.arcgis.com/home/item.html?id=5028bf3513ff4c38b28822d010a4937c" | ||
], | ||
"provision_to": [], | ||
"redirect_from": "", | ||
"relevant_apis": [ | ||
"EncCell", | ||
"EncDataset", | ||
"EncExchangeSet", | ||
"EncLayer" | ||
], | ||
"snippets": [ | ||
"src/main/java/com/esri/arcgismaps/sample/addencexchangeset/MainActivity.kt", | ||
"src/main/java/com/esri/arcgismaps/sample/addencexchangeset/DownloadActivity.kt", | ||
"src/main/java/com/esri/arcgismaps/sample/addencexchangeset/components/MapViewModel.kt", | ||
"src/main/java/com/esri/arcgismaps/sample/addencexchangeset/screens/MainScreen.kt" | ||
], | ||
"title": "Add ENC exchange set" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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.addencexchangeset" | ||
// For view based samples | ||
buildFeatures { | ||
buildConfig = true | ||
} | ||
} | ||
|
||
dependencies { | ||
// Only module specific dependencies needed here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?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:name=".DownloadActivity" | ||
android:exported="true" | ||
android:label="@string/add_enc_exchange_set_app_name"> | ||
|
||
</activity> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:label="@string/add_enc_exchange_set_app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
38 changes: 38 additions & 0 deletions
38
...change-set/src/main/java/com/esri/arcgismaps/sample/addencexchangeset/DownloadActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Copyright 2024 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.addencexchangeset | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import com.esri.arcgismaps.sample.sampleslib.DownloaderActivity | ||
|
||
class DownloadActivity : DownloaderActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
downloadAndStartSample( | ||
Intent(this, MainActivity::class.java), | ||
// get the app name of the sample | ||
getString(R.string.add_enc_exchange_set_app_name), | ||
listOf( | ||
// ArcGIS Portal item containing ENC hydrography resources | ||
"https://www.arcgis.com/home/item.html?id=5028bf3513ff4c38b28822d010a4937c", | ||
// ArcGIS Portal item containing the ENC dataset | ||
"https://www.arcgis.com/home/item.html?id=9d2987a825c646468b3ce7512fb76e2d" | ||
) | ||
) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...c-exchange-set/src/main/java/com/esri/arcgismaps/sample/addencexchangeset/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* Copyright 2024 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.addencexchangeset | ||
|
||
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.addencexchangeset.screens.MainScreen | ||
|
||
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 { | ||
SampleApp() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SampleApp() { | ||
Surface( | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
MainScreen( | ||
sampleName = getString(R.string.add_enc_exchange_set_app_name) | ||
) | ||
} | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
...set/src/main/java/com/esri/arcgismaps/sample/addencexchangeset/components/MapViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* Copyright 2024 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.addencexchangeset.components | ||
|
||
import android.app.Application | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.AndroidViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.arcgismaps.geometry.Envelope | ||
import com.arcgismaps.geometry.GeometryEngine | ||
import com.arcgismaps.hydrography.EncCell | ||
import com.arcgismaps.hydrography.EncEnvironmentSettings | ||
import com.arcgismaps.hydrography.EncExchangeSet | ||
import com.arcgismaps.mapping.ArcGISMap | ||
import com.arcgismaps.mapping.BasemapStyle | ||
import com.arcgismaps.mapping.Viewpoint | ||
import com.arcgismaps.mapping.layers.EncLayer | ||
import com.esri.arcgismaps.sample.addencexchangeset.R | ||
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel | ||
import kotlinx.coroutines.launch | ||
import java.io.File | ||
|
||
class MapViewModel(application: Application) : AndroidViewModel(application) { | ||
private val provisionPath: String by lazy { | ||
application.getExternalFilesDir(null)?.path.toString() + | ||
File.separator + | ||
application.getString(R.string.add_enc_exchange_set_app_name) | ||
} | ||
|
||
// Paths to ENC data and hydrology resources | ||
private val encResourcesPath = provisionPath + application.getString(R.string.enc_res_dir) | ||
private val encDataPath = provisionPath + application.getString(R.string.enc_data_dir) | ||
|
||
// Create an ENC exchange set from the local ENC data | ||
private val encExchangeSet = EncExchangeSet(listOf(encDataPath)) | ||
private val encEnvironmentSettings: EncEnvironmentSettings = EncEnvironmentSettings | ||
|
||
// Create an empty map, to be updated once ENC data is loaded | ||
var arcGISMap by mutableStateOf(ArcGISMap()) | ||
|
||
// Create a message dialog view model for handling error messages | ||
val messageDialogVM = MessageDialogViewModel() | ||
|
||
init { | ||
// Provide ENC environment with location of ENC resources and configure SENC caching location | ||
encEnvironmentSettings.resourcePath = encResourcesPath | ||
encEnvironmentSettings.sencDataPath = application.externalCacheDir?.path | ||
|
||
viewModelScope.launch { | ||
encExchangeSet.load().onSuccess { | ||
|
||
// Calculate the combined extent of all datasets in the exchange set | ||
val exchangeSetExtent: Envelope? = encExchangeSet.extentOrNull() | ||
|
||
// Set the map to the oceans basemap style, and viewpoint to the exchange set extent | ||
arcGISMap = ArcGISMap(BasemapStyle.ArcGISOceans).apply { | ||
exchangeSetExtent?.let { | ||
initialViewpoint = Viewpoint(exchangeSetExtent) | ||
} | ||
} | ||
|
||
encExchangeSet.datasets.forEach { encDataset -> | ||
// Create a layer for each ENC dataset and add it to the map | ||
val encCell = EncCell(encDataset) | ||
val encLayer = EncLayer(encCell) | ||
arcGISMap.operationalLayers.add(encLayer) | ||
|
||
encLayer.load().onFailure { err -> | ||
messageDialogVM.showMessageDialog( | ||
"Error loading ENC layer", | ||
err.message.toString() | ||
) | ||
} | ||
} | ||
}.onFailure { err -> | ||
messageDialogVM.showMessageDialog( | ||
"Error loading ENC exchange set", | ||
err.message.toString() | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get the combined extent of every dataset in the exchange set. | ||
*/ | ||
private fun EncExchangeSet.extentOrNull(): Envelope? { | ||
var extent: Envelope? = null | ||
|
||
datasets.forEach { dataset -> | ||
if (extent == null) { | ||
extent = dataset.extent | ||
} | ||
|
||
if (extent != null && dataset.extent != null) { | ||
// Update the combined extent of the exchange set if geometry engine returns non-null | ||
extent = GeometryEngine.combineExtentsOrNull(extent!!, dataset.extent!!) ?: extent | ||
} | ||
} | ||
return extent | ||
} |
Oops, something went wrong.