Last active
October 1, 2022 15:40
-
-
Save ComBatVision/18d058fe0386e29e949e9332ed56aaf9 to your computer and use it in GitHub Desktop.
Example of usage WorldWindKotlin on Android
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
/** | |
* Creates a simple view of a globe with touch navigation and a few layers. | |
*/ | |
open class BasicGlobeActivity: Activity() { | |
/** | |
* The WorldWindow (GLSurfaceView) maintained by this activity | |
*/ | |
override lateinit var wwd: WorldWindow | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
// Establish the activity content | |
setContentView(R.layout.activity_globe) | |
// Create the WorldWindow (a GLSurfaceView) which displays the globe. | |
wwd = WorldWindow(this) | |
// Add the WorldWindow view object to the layout that was reserved for the globe. | |
val globeLayout = findViewById<FrameLayout>(R.id.globe) | |
globeLayout.addView(wwd) | |
// Setting up the WorldWindow's layers. | |
with(wwd.engine.layers) { | |
addLayer(BackgroundLayer()) | |
addLayer(BlueMarbleLandsatLayer().apply { | |
configureCache(File(cacheDir, "cache.gpkg").absolutePath, "BMLS") | |
}) | |
addLayer(AtmosphereLayer()) | |
} | |
// Setting up the WorldWindow's elevation coverages. | |
wwd.engine.globe.elevationModel.addCoverage(BasicElevationCoverage().apply { | |
configureCache(File(cacheDir, "cache.gpkg").absolutePath, "SRTM") | |
}) | |
} | |
override fun onPause() { | |
super.onPause() | |
wwd.onPause() // pauses the rendering thread | |
} | |
override fun onResume() { | |
super.onResume() | |
wwd.onResume() // resumes a paused rendering thread | |
} | |
override fun onLowMemory() { | |
super.onLowMemory() | |
// Reduce cache size on low memory | |
wwd.engine.renderResourceCache.trimStale() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment