Skip to content

Commit c2fa48d

Browse files
rom14514sorenoid
andauthored
Sample - Set surface placement mode (#434)
Co-authored-by: Soren Roth <sroth@esri.com>
1 parent 91f673e commit c2fa48d

File tree

9 files changed

+546
-0
lines changed

9 files changed

+546
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Set surface placement mode
2+
3+
Position graphics relative to a surface using different surface placement modes.
4+
5+
![Image of set surface placement mode](set-surface-placement-mode.png)
6+
7+
## Use case
8+
9+
Depending on the use case, data might be displayed at an absolute height (e.g. flight data recorded with altitude information), at a relative height to the terrain (e.g. transmission lines positioned relative to the ground), at a relative height to objects in the scene (e.g. extruded polygons, integrated mesh scene layer), or draped directly onto the terrain (e.g. location markers, area boundaries).
10+
11+
## How to use the sample
12+
13+
The sample loads a scene showing four points that use the individual surface placement rules (absolute, relative, relative to scene, and either draped billboarded or draped flat). Use the toggle to change the draped mode and the slider to dynamically adjust the z value of the graphics. Explore the scene by zooming in/out and by panning around to observe the effects of the surface placement rules.
14+
15+
## How it works
16+
17+
1. Create a `GraphicsOverlay` for each `SurfacePlacement`:
18+
* `Absolute` positions the graphic using only its z-value.
19+
* `DrapedBillboarded` positions the graphic upright on the surface, always facing the camera, ignoring its z-value.
20+
* `DrapedFlat` positions the graphic flat on the surface, ignoring its z-value.
21+
* `Relative` positions the graphic using its z-value plus the elevation of the surface.
22+
* `RelativeToScene` positions the graphic using its z-value plus the altitude values of the scene.
23+
2. Create and add graphics to the graphics overlays.
24+
3. Set `GraphicsOverlay.sceneProperties.surfacePlacement` to the respective `SurfacePlacement`.
25+
4. Create a `SceneView` instance with a scene and the graphics overlays.
26+
27+
## Relevant API
28+
29+
* GeometryEngine.createWithZ
30+
* Graphic
31+
* GraphicsOverlay
32+
* LayerSceneProperties
33+
* Surface
34+
* SurfacePlacement
35+
36+
## About the data
37+
38+
The scene shows a view of Brest, France. Four points are shown hovering with positions defined by each of the different surface placement modes (absolute, relative, relative to scene, and either draped billboarded or draped flat).
39+
40+
## Additional information
41+
42+
This sample uses an elevation service to add elevation/terrain to the scene. Graphics are positioned relative to that surface for the drapedBillboarded, drapedFlat, and relative surface placement modes. It also uses a scene layer containing 3D models of buildings. Graphics are positioned relative to that scene layer for the relativeToScene surface placement mode.
43+
44+
## Tags
45+
46+
3D, absolute, altitude, draped, elevation, floating, relative, scenes, sea level, surface placement
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"category": "Scenes",
3+
"description": "Position graphics relative to a surface using different surface placement modes.",
4+
"formal_name": "SetSurfacePlacementMode",
5+
"ignore": false,
6+
"images": [
7+
"set-surface-placement-mode.png"
8+
],
9+
"keywords": [
10+
"3D",
11+
"absolute",
12+
"altitude",
13+
"draped",
14+
"elevation",
15+
"floating",
16+
"relative",
17+
"scenes",
18+
"sea level",
19+
"surface placement",
20+
"GeometryEngine.createWithZ",
21+
"Graphic",
22+
"GraphicsOverlay",
23+
"LayerSceneProperties",
24+
"Surface",
25+
"SurfacePlacement"
26+
],
27+
"language": "kotlin",
28+
"redirect_from": "",
29+
"relevant_apis": [
30+
"GeometryEngine.createWithZ",
31+
"Graphic",
32+
"GraphicsOverlay",
33+
"LayerSceneProperties",
34+
"Surface",
35+
"SurfacePlacement"
36+
],
37+
"snippets": [
38+
"src/main/java/com/esri/arcgismaps/sample/setsurfaceplacementmode/components/SetSurfacePlacementModeViewModel.kt",
39+
"src/main/java/com/esri/arcgismaps/sample/setsurfaceplacementmode/MainActivity.kt",
40+
"src/main/java/com/esri/arcgismaps/sample/setsurfaceplacementmode/screens/SetSurfacePlacementModeScreen.kt"
41+
],
42+
"title": "Set surface placement mode"
43+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
alias(libs.plugins.arcgismaps.android.library)
3+
alias(libs.plugins.arcgismaps.android.library.compose)
4+
alias(libs.plugins.arcgismaps.kotlin.sample)
5+
alias(libs.plugins.gradle.secrets)
6+
}
7+
8+
secrets {
9+
// this file doesn't contain secrets, it just provides defaults which can be committed into git.
10+
defaultPropertiesFileName = "secrets.defaults.properties"
11+
}
12+
13+
android {
14+
namespace = "com.esri.arcgismaps.sample.setsurfaceplacementmode"
15+
buildFeatures {
16+
buildConfig = true
17+
}
18+
}
19+
20+
dependencies {
21+
// Only module specific dependencies needed here
22+
}
239 KB
Loading
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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><activity
7+
android:exported="true"
8+
android:name=".MainActivity"
9+
android:label="@string/set_surface_placement_mode_app_name">
10+
11+
</activity>
12+
</application>
13+
14+
</manifest>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Copyright 2025 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.setsurfaceplacementmode
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 com.arcgismaps.ApiKey
26+
import com.arcgismaps.ArcGISEnvironment
27+
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
28+
import com.esri.arcgismaps.sample.setsurfaceplacementmode.screens.SetSurfacePlacementModeScreen
29+
30+
class MainActivity : ComponentActivity() {
31+
32+
override fun onCreate(savedInstanceState: Bundle?) {
33+
super.onCreate(savedInstanceState)
34+
// authentication with an API key or named user is
35+
// required to access basemaps and other location services
36+
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
37+
38+
setContent {
39+
SampleAppTheme {
40+
SetSurfacePlacementModeApp()
41+
}
42+
}
43+
}
44+
45+
@Composable
46+
private fun SetSurfacePlacementModeApp() {
47+
Surface(color = MaterialTheme.colorScheme.background) {
48+
SetSurfacePlacementModeScreen(
49+
sampleName = getString(R.string.set_surface_placement_mode_app_name)
50+
)
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)