Skip to content
Draft
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
8 changes: 8 additions & 0 deletions worldwind-examples-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@
android:noHistory="true"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".TextureQuadExampleActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_texture_quad_example"
android:launchMode="singleInstance"
android:noHistory="true"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".KmlDemoActivity"
android:configChanges="orientation|screenSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ abstract class AbstractMainActivity: AppCompatActivity(), NavigationView.OnNavig
R.id.nav_placemarks_milstd2525_demo_activity -> startActivity(Intent(applicationContext, PlacemarksMilStd2525DemoActivity::class.java))
R.id.nav_placemarks_milstd2525_stress_activity -> startActivity(Intent(applicationContext, PlacemarksMilStd2525StressActivity::class.java))
R.id.nav_placemarks_select_drag_activity -> startActivity(Intent(applicationContext, PlacemarksSelectDragActivity::class.java))
R.id.nav_texture_quad_example_activity -> startActivity(Intent(applicationContext, TextureQuadExampleActivity::class.java))
R.id.nav_placemarks_stress_activity -> startActivity(Intent(applicationContext, PlacemarksStressTestActivity::class.java))
R.id.nav_texture_stress_test_activity -> startActivity(Intent(applicationContext, TextureStressTestActivity::class.java))
R.id.nav_kml_demo_activity -> startActivity(Intent(applicationContext, KmlDemoActivity::class.java))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
package earth.worldwind.examples

import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import earth.worldwind.WorldWind
import earth.worldwind.geom.AltitudeMode
import earth.worldwind.geom.Angle
import earth.worldwind.geom.Angle.Companion.degrees
import earth.worldwind.geom.Location
import earth.worldwind.geom.LookAt
import earth.worldwind.geom.Offset.Companion.bottomCenter
import earth.worldwind.geom.Sector
import earth.worldwind.layer.RenderableLayer
import earth.worldwind.render.image.ImageSource
import earth.worldwind.shape.SurfaceImage
import earth.worldwind.geom.Position
import earth.worldwind.geom.Position.Companion.fromDegrees
import earth.worldwind.gesture.SelectDragCallback
import earth.worldwind.render.Color
import earth.worldwind.render.Renderable
import earth.worldwind.render.image.ImageSource.Companion.fromResource
import earth.worldwind.shape.Highlightable
import earth.worldwind.shape.Placemark
import earth.worldwind.shape.Placemark.Companion.createWithImage
import earth.worldwind.shape.PlacemarkAttributes
import earth.worldwind.shape.TextureQuad
import earth.worldwind.shape.ShapeAttributes


class TextureQuadExampleActivity: GeneralGlobeActivity() {
private var selectedObject: Renderable? = null // Last "selected" object from single tap or double tap

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
aboutBoxTitle = "About the " + resources.getText(R.string.title_texture_quad_example)
aboutBoxText = """
Demonstrates how to stretch texture quad
""".trimIndent()

// Initialize the mapping of vehicle types to their icons.
for (i in automotiveTypes.indices) automotiveIconMap[automotiveTypes[i]] = automotiveIcons[i]

// Add dragging callback
wwd.selectDragDetector.callback = object : SelectDragCallback {
override fun canPickRenderable(renderable: Renderable) = true //renderable.hasUserProperty(SELECTABLE)
override fun canMoveRenderable(renderable: Renderable) = renderable === selectedObject && renderable.hasUserProperty(MOVABLE)
override fun onRenderablePicked(renderable: Renderable, position: Position) = toggleSelection(renderable)
override fun onRenderableContext(renderable: Renderable, position: Position) = contextMenu(renderable)
override fun onTerrainContext(position: Position) = contextMenu()
override fun onRenderableDoubleTap(renderable: Renderable, position: Position) {
// Note that double-tapping should not toggle a "selected" object's selected state
if (renderable !== selectedObject) toggleSelection(renderable) // deselects a previously selected item
}
override fun onRenderableMoved(renderable: Renderable, fromPosition: Position, toPosition: Position)
{
val placemark = (renderable as? Placemark)
placemark?.moveTo(wwd.engine.globe, toPosition)
var textureQuad = renderable.getUserProperty<TextureQuad>(TEXTURE_QUAD_REF)
val vertexIndex = renderable.getUserProperty<Int>(VERTEX_INDEX)
vertexIndex?.let { textureQuad?.setLocation(it, Location(toPosition.latitude, toPosition.longitude)) }
}


/**
* Toggles the selected state of the picked renderable.
*/
private fun toggleSelection(renderable: Renderable) {
// Test if last picked object is "selectable". If not, retain the
// currently selected object. To discard the current selection,
// the user must pick another selectable object or the current object.
if (renderable.hasUserProperty(SELECTABLE)) {
val isNewSelection = renderable !== selectedObject

// Only one object can be selected at time, deselect any previously selected object
if (isNewSelection) (selectedObject as? Highlightable)?.isHighlighted = false

// Display the highlight or normal attributes to indicate the
// selected or unselected state respectively.
(renderable as? Highlightable)?.isHighlighted = isNewSelection

// Track the selected object
selectedObject = if (isNewSelection) renderable else null
} else {
val textureQuad = (renderable as? TextureQuad)
textureQuad?.let {
val arr = it.getAllLocations()

Toast.makeText(applicationContext, "BL:{%.6f, %.6f}\nBR:{%.6f, %.6f}\nTR:{%.6f, %.6f}\nTL:{%.6f, %.6f}".format(
arr[0].latitude.inDegrees, arr[0].longitude.inDegrees,
arr[1].latitude.inDegrees, arr[1].longitude.inDegrees,
arr[2].latitude.inDegrees, arr[2].longitude.inDegrees,
arr[3].latitude.inDegrees, arr[3].longitude.inDegrees), Toast.LENGTH_SHORT).show()
}
}
}

/**
* Shows the context information for the WorldWindow.
*/
private fun contextMenu(renderable: Renderable? = null) {
val so = selectedObject
Toast.makeText(
applicationContext,
"${renderable?.displayName ?: "Nothing"} picked and ${so?.displayName ?: "nothing"} selected.",
Toast.LENGTH_LONG
).show()
}
}
// Add a layer for texture quads to the WorldWindow
wwd.engine.layers.addLayer(
RenderableLayer("Texture quad example").apply {

addAllRenderables(
createStretchableTextureQuad(
Location(51.26891660167462.degrees, 30.0096671570868.degrees),
Location(51.27062637593827.degrees, 30.01240117718469.degrees),
Location(51.271804026840556.degrees, 30.01029779181104.degrees),
Location(51.270125460836965.degrees, 30.00779959572076.degrees),
ImageSource.fromResource(R.drawable.korogode_image), true
)
)
}
)

// And finally, for this demo, position the viewer to look at the placemarks
val lookAt = LookAt(
position = Position(51.265140.degrees, 30.020303.degrees, 4.0e3), altitudeMode = AltitudeMode.ABSOLUTE,
range = 0.0, heading = Angle.ZERO, tilt = Angle.ZERO, roll = Angle.ZERO
)
wwd.engine.cameraFromLookAt(lookAt)
}

companion object {
/**
* The EDITABLE capability, if it exists in a Placemark's user properties, allows editing with a double-tap
*/
const val EDITABLE = "editable"
/**
* The MOVABLE capability, if it exists in a Placemark's user properties, allows dragging (after being selected)
*/
const val MOVABLE = "movable"
/**
* The SELECTABLE capability, if it exists in a Placemark's user properties, allows selection with single-tap
*/
const val SELECTABLE = "selectable"

const val VERTEX_INDEX = "vertex_index"
const val TEXTURE_QUAD_REF = "texture_quad_ref"
/**
* Placemark user property vehicleKey for the type of vehicle
*/
const val AUTOMOTIVE_TYPE = "auotomotive_type"

// Vehicle vehicleTypes used in the Placemark editing dialog
private val automotiveTypes = arrayOf(
"Car", "SUV", "4x4", "Truck", "Jeep", "Tank"
)

// Resource IDs for vehicle icons
private val automotiveIcons = intArrayOf(
R.drawable.vehicle_car,
R.drawable.vehicle_suv,
R.drawable.vehicle_4x4,
R.drawable.vehicle_truck,
R.drawable.vehicle_jeep,
R.drawable.vehicle_tank
)
private const val NORMAL_IMAGE_SCALE = 3.0
private const val HIGHLIGHTED_IMAGE_SCALE = 4.0
private val automotiveIconMap = mutableMapOf<String, Int>()


/**
* Helper method to create vehicle placemarks.
*/
private fun createAutomobilePlacemark(location: Location, automotiveType: String, textureQuad : TextureQuad, vertexIndex : Int) =
automotiveIconMap[automotiveType]?.let { resId ->
createWithImage(Position(location.latitude, location.longitude, 0.0), fromResource(resId)).apply {
attributes.apply {
imageOffset = bottomCenter()
imageScale = NORMAL_IMAGE_SCALE
}
highlightAttributes = PlacemarkAttributes(attributes).apply {
imageScale = HIGHLIGHTED_IMAGE_SCALE
imageColor = Color(android.graphics.Color.YELLOW)
}

altitudeMode = AltitudeMode.CLAMP_TO_GROUND
// The AUTOMOTIVE_TYPE property is used to exchange the vehicle type with the VehicleTypeDialog
putUserProperty(AUTOMOTIVE_TYPE, automotiveType)
// The select/drag controller will examine a placemark's "capabilities" to determine what operations are applicable:
putUserProperty(SELECTABLE, true)
putUserProperty(EDITABLE, true)
putUserProperty(MOVABLE, true)
putUserProperty(TEXTURE_QUAD_REF, textureQuad)
putUserProperty(VERTEX_INDEX, vertexIndex)
}
} ?: throw IllegalArgumentException("$automotiveType is not valid.")

private fun createStretchableTextureQuad(bottomLeft : Location,
bottomRight: Location,
topRight : Location,
topLeft : Location,
imageSource: ImageSource,
drawOutline: Boolean = true) : List<Renderable>
{
val textureQuad = TextureQuad(bottomLeft, bottomRight, topRight, topLeft,
ShapeAttributes().apply {
interiorImageSource = imageSource
isDrawOutline = drawOutline
outlineWidth = 3.0f
outlineColor = Color(1.0f, 0.0f, 0.0f, 1f)
})
return listOf(
createAutomobilePlacemark(bottomLeft, automotiveTypes[1], textureQuad, 0),
createAutomobilePlacemark(bottomRight, automotiveTypes[1], textureQuad, 1),
createAutomobilePlacemark(topRight, automotiveTypes[1], textureQuad, 2),
createAutomobilePlacemark(topLeft, automotiveTypes[1], textureQuad, 3),
textureQuad
)
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
android:id="@+id/nav_placemarks_select_drag_activity"
android:icon="@android:drawable/ic_menu_myplaces"
android:title="@string/title_placemarks_select_drag"/>
<item
android:id="@+id/nav_texture_quad_example_activity"
android:icon="@android:drawable/ic_menu_myplaces"
android:title="@string/title_texture_quad_example"/>
<item
android:id="@+id/nav_placemarks_milstd2525_activity"
android:icon="@android:drawable/ic_menu_myplaces"
Expand Down
1 change: 1 addition & 0 deletions worldwind-examples-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<string name="title_placemarks_milstd2525_demo">MIL-STD-2525 Demo</string>
<string name="title_placemarks_milstd2525_stress_test">MIL-STD-2525 Stress Test</string>
<string name="title_placemarks_select_drag">Placemark Select and Drag</string>
<string name="title_texture_quad_example">Texture quad example</string>
<string name="title_kml_demo">KML Demonstration</string>
<string name="title_geo_json_demo">GeoJSON Demonstration</string>
<string name="title_placemarks_stress_test">Placemarks Stress Test</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package earth.worldwind.tutorials

import dev.icerock.moko.resources.ImageResource
import dev.icerock.moko.resources.ResourceContainer
import dev.icerock.moko.resources.ResourcePlatformDetails
import earth.worldwind.tutorials.R
import kotlin.String
import kotlin.collections.List

public actual object MR {
private val contentHash: String = "2bb561c9822e7f4b4cdac81a28004d21"

public actual object images : ResourceContainer<ImageResource> {
public actual override val __platformDetails: ResourcePlatformDetails =
ResourcePlatformDetails()

public actual val aircraft_fighter: ImageResource = ImageResource(R.drawable.aircraft_fighter)

public actual val aircraft_fixwing: ImageResource = ImageResource(R.drawable.aircraft_fixwing)

public actual val airport_terminal: ImageResource = ImageResource(R.drawable.airport_terminal)

public actual val aladdin_carpet: ImageResource = ImageResource(R.drawable.aladdin_carpet)

public actual val ehipcc: ImageResource = ImageResource(R.drawable.ehipcc)

public actual val korogode_image: ImageResource = ImageResource(R.drawable.korogode_image)

public actual val manhole: ImageResource = ImageResource(R.drawable.manhole)

public actual val pattern_sample_houndstooth: ImageResource =
ImageResource(R.drawable.pattern_sample_houndstooth)

public actual val worldwind_logo: ImageResource = ImageResource(R.drawable.worldwind_logo)

public actual override fun values(): List<ImageResource> = listOf(aircraft_fighter,
aircraft_fixwing, airport_terminal, aladdin_carpet, ehipcc, korogode_image, manhole,
pattern_sample_houndstooth, worldwind_logo)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package earth.worldwind.tutorials

import dev.icerock.moko.resources.ImageResource
import dev.icerock.moko.resources.ResourceContainer
import dev.icerock.moko.resources.ResourcePlatformDetails
import kotlin.collections.List

public expect object MR {
public object images : ResourceContainer<ImageResource> {
public override val __platformDetails: ResourcePlatformDetails

public val aircraft_fighter: ImageResource

public val aircraft_fixwing: ImageResource

public val airport_terminal: ImageResource

public val aladdin_carpet: ImageResource

public val ehipcc: ImageResource

public val korogode_image: ImageResource

public val manhole: ImageResource

public val pattern_sample_houndstooth: ImageResource

public val worldwind_logo: ImageResource

public override fun values(): List<ImageResource>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package earth.worldwind.tutorials

import dev.icerock.moko.graphics.Color
import dev.icerock.moko.resources.ImageResource
import dev.icerock.moko.resources.ResourceContainer
import dev.icerock.moko.resources.ResourcePlatformDetails
import kotlin.String
import kotlin.collections.List

public actual object MR {
private val contentHash: String = "2bb561c9822e7f4b4cdac81a28004d21"

public actual object images : ResourceContainer<ImageResource> {
public actual override val __platformDetails: ResourcePlatformDetails =
ResourcePlatformDetails()

public actual val aircraft_fighter: ImageResource = ImageResource(fileUrl =
js("require(\"./images/aircraft_fighter.png\")") as String, fileName =
"aircraft_fighter.png")

public actual val aircraft_fixwing: ImageResource = ImageResource(fileUrl =
js("require(\"./images/aircraft_fixwing.png\")") as String, fileName =
"aircraft_fixwing.png")

public actual val airport_terminal: ImageResource = ImageResource(fileUrl =
js("require(\"./images/airport_terminal.png\")") as String, fileName =
"airport_terminal.png")

public actual val aladdin_carpet: ImageResource = ImageResource(fileUrl =
js("require(\"./images/aladdin_carpet.jpg\")") as String, fileName = "aladdin_carpet.jpg")

public actual val ehipcc: ImageResource = ImageResource(fileUrl =
js("require(\"./images/ehipcc.png\")") as String, fileName = "ehipcc.png")

public actual val korogode_image: ImageResource = ImageResource(fileUrl =
js("require(\"./images/korogode_image.jpg\")") as String, fileName = "korogode_image.jpg")

public actual val manhole: ImageResource = ImageResource(fileUrl =
js("require(\"./images/manhole.png\")") as String, fileName = "manhole.png")

public actual val pattern_sample_houndstooth: ImageResource = ImageResource(fileUrl =
js("require(\"./images/pattern_sample_houndstooth.png\")") as String, fileName =
"pattern_sample_houndstooth.png")

public actual val worldwind_logo: ImageResource = ImageResource(fileUrl =
js("require(\"./images/worldwind_logo.png\")") as String, fileName = "worldwind_logo.png")

public actual override fun values(): List<ImageResource> = listOf(aircraft_fighter,
aircraft_fixwing, airport_terminal, aladdin_carpet, ehipcc, korogode_image, manhole,
pattern_sample_houndstooth, worldwind_logo)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading