Skip to content

Commit f54d51c

Browse files
committed
Update handling of date and suntime
1 parent e0cfc12 commit f54d51c

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

samples/show-realistic-light-and-shadows/src/main/java/com/esri/arcgismaps/sample/showrealisticlightandshadows/components/ShowRealisticLightAndShadowsViewModel.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel
3737
import java.time.Instant
3838
import java.time.LocalDateTime
3939
import java.time.ZoneId
40+
import java.time.ZonedDateTime
4041

4142
class ShowRealisticLightAndShadowsViewModel(application: Application) :
4243
AndroidViewModel(application) {
@@ -68,15 +69,14 @@ class ShowRealisticLightAndShadowsViewModel(application: Application) :
6869
)
6970
}
7071

71-
// default time for sun position and the slider
72-
val defaultTime = 15f * 60f * 60f // 15:00 in seconds since midnight
72+
// noon in the timezone our center point is located with an arbitrary date
73+
private val noon: ZonedDateTime = LocalDateTime.parse("2000-09-22T12:00:00").atZone(
74+
ZoneId.of("US/Pacific"))
7375

7476
// create a LightingOptionsState with default values that will be used by the scene view
7577
val lightingOptionsState = LightingOptionsState(
7678
mutableStateOf(
77-
LocalDateTime.parse("2000-09-22T00:00:00").atZone(
78-
ZoneId.of("US/Pacific")
79-
).plusSeconds(defaultTime.toLong()).toInstant()
79+
noon.toInstant() // initialize the time to noon to start with
8080
),
8181
mutableStateOf(LightingMode.LightAndShadows),
8282
mutableStateOf(Color(red = 220, green = 220, blue = 220, alpha = 255)),
@@ -89,12 +89,10 @@ class ShowRealisticLightAndShadowsViewModel(application: Application) :
8989

9090
/**
9191
* Update the sun time of the lighting options state used by the scene view.
92-
* Uses the range 0 seconds (12 am) to 86,340 seconds (11:59 pm).
92+
* Uses offset in seconds since noon, which is a range from -43200 (12 am) to 43140 seconds (11:59 pm).
9393
*/
9494
fun setSunTime(sunTime: Int) {
95-
lightingOptionsState.sunTime.value = LocalDateTime.parse("2000-09-22T00:00:00").atZone(
96-
ZoneId.of("US/Pacific")
97-
).plusSeconds(sunTime.toLong()).toInstant()
95+
lightingOptionsState.sunTime.value = noon.plusSeconds(sunTime.toLong()).toInstant()
9896
}
9997
}
10098

samples/show-realistic-light-and-shadows/src/main/java/com/esri/arcgismaps/sample/showrealisticlightandshadows/screens/ShowRealisticLightAndShadowsScreen.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import com.esri.arcgismaps.sample.showrealisticlightandshadows.components.ShowRe
5252
fun ShowRealisticLightAndShadowsScreen(sampleName: String) {
5353
val mapViewModel: ShowRealisticLightAndShadowsViewModel = viewModel()
5454
val lightingOptionsState = mapViewModel.lightingOptionsState
55-
var sliderPosition by remember { mutableFloatStateOf(mapViewModel.defaultTime) }
55+
var sliderPosition by remember { mutableFloatStateOf(0f) }
5656
val lightingModes = listOf(
5757
LightingMode.LightAndShadows,
5858
LightingMode.Light,
@@ -131,9 +131,10 @@ fun ShowRealisticLightAndShadowsScreen(sampleName: String) {
131131
sliderPosition = it
132132
mapViewModel.setSunTime(it.toInt())
133133
},
134-
// the range is 0 to 86,340 seconds ((60 seconds * 60 minutes * 24 hours) - 60 seconds),
135-
// which means 12 am to 11:59 pm.
136-
valueRange = 0f..86340f,
134+
// the range is -43200 (60 seconds * 60 minutes * 12 hours)
135+
// to 43140 ((60 seconds * 60 minutes * 12 hours) - 60 seconds),
136+
// which means 12 am to 11:59 pm in offset from noon.
137+
valueRange = -43200f..43140f
137138
)
138139
Text(
139140
text = "PM",

0 commit comments

Comments
 (0)