From 5132761afced0212908b282521597329251c405f Mon Sep 17 00:00:00 2001 From: Eugene Maksymenko Date: Tue, 15 Oct 2024 22:11:10 +0300 Subject: [PATCH] Fix screen coordinates calculation on JS version when density factor is not equal 1.0. --- README.md | 2 +- build.gradle.kts | 2 +- .../assets/omnidirectional_sightline_tutorial.html | 2 +- .../kotlin/earth.worldwind.tutorials/SightlineTutorial.kt | 3 ++- .../src/commonMain/kotlin/earth/worldwind/shape/Placemark.kt | 4 ++-- worldwind/src/jsMain/kotlin/earth/worldwind/WorldWindow.kt | 4 ++-- .../kotlin/earth/worldwind/gesture/SelectDragDetector.kt | 4 ++-- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 37d5ea1c1..d679531f7 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ repositories { } dependencies { - implementation 'earth.worldwind:worldwind:1.5.25' + implementation 'earth.worldwind:worldwind:1.5.26' } ``` diff --git a/build.gradle.kts b/build.gradle.kts index fbb12235d..f21af5608 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ buildscript { allprojects { group = "earth.worldwind" - version = "1.5.25" + version = "1.5.26" extra.apply { set("minSdk", 21) diff --git a/worldwind-tutorials/src/androidMain/assets/omnidirectional_sightline_tutorial.html b/worldwind-tutorials/src/androidMain/assets/omnidirectional_sightline_tutorial.html index af7ddd30b..84494aec9 100644 --- a/worldwind-tutorials/src/androidMain/assets/omnidirectional_sightline_tutorial.html +++ b/worldwind-tutorials/src/androidMain/assets/omnidirectional_sightline_tutorial.html @@ -59,7 +59,7 @@

OmnidirectionalSightlineFragment.kt

addRenderable( Placemark(position).apply { attributes.apply { - imageSource = earth.worldwind.render.image.ImageSource.fromResource(MR.images.aircraft_fixwing) + imageSource = ImageSource.fromResource(MR.images.aircraft_fixwing) imageScale = 2.0 isDrawLeader = true } diff --git a/worldwind-tutorials/src/commonMain/kotlin/earth.worldwind.tutorials/SightlineTutorial.kt b/worldwind-tutorials/src/commonMain/kotlin/earth.worldwind.tutorials/SightlineTutorial.kt index c40e75f4e..54abf0edb 100644 --- a/worldwind-tutorials/src/commonMain/kotlin/earth.worldwind.tutorials/SightlineTutorial.kt +++ b/worldwind-tutorials/src/commonMain/kotlin/earth.worldwind.tutorials/SightlineTutorial.kt @@ -8,6 +8,7 @@ import earth.worldwind.geom.Offset import earth.worldwind.geom.Position import earth.worldwind.layer.RenderableLayer import earth.worldwind.render.Color +import earth.worldwind.render.image.ImageSource import earth.worldwind.shape.OmnidirectionalSightline import earth.worldwind.shape.Placemark @@ -29,7 +30,7 @@ class SightlineTutorial(private val engine: WorldWind) : AbstractTutorial() { addRenderable( Placemark(position).apply { attributes.apply { - imageSource = earth.worldwind.render.image.ImageSource.fromResource(MR.images.aircraft_fixwing) + imageSource = ImageSource.fromResource(MR.images.aircraft_fixwing) imageOffset = Offset.bottomCenter() imageScale = 2.0 isDrawLeader = true diff --git a/worldwind/src/commonMain/kotlin/earth/worldwind/shape/Placemark.kt b/worldwind/src/commonMain/kotlin/earth/worldwind/shape/Placemark.kt index c92b83aea..52f6e8fc9 100644 --- a/worldwind/src/commonMain/kotlin/earth/worldwind/shape/Placemark.kt +++ b/worldwind/src/commonMain/kotlin/earth/worldwind/shape/Placemark.kt @@ -236,7 +236,7 @@ open class Placemark @JvmOverloads constructor( if (activeTexture != null) { val w = activeTexture.width.toDouble() val h = activeTexture.height.toDouble() - val s = activeAttributes.imageScale * visibilityScale + val s = activeAttributes.imageScale * visibilityScale // * rc.densityFactor activeAttributes.imageOffset.offsetForSize(w, h, offset) offsetX = offset.x * s offsetY = offset.y * s @@ -246,7 +246,7 @@ open class Placemark @JvmOverloads constructor( // This branch serves both non-textured attributes and also textures that haven't been loaded yet. // We set the size for non-loaded textures to the typical size of a contemporary "small" icon (24px) var size = if (activeAttributes.imageSource != null) 24.0 else activeAttributes.imageScale - size *= visibilityScale + size *= visibilityScale // * rc.densityFactor activeAttributes.imageOffset.offsetForSize(size, size, offset) offsetX = offset.x offsetY = offset.y diff --git a/worldwind/src/jsMain/kotlin/earth/worldwind/WorldWindow.kt b/worldwind/src/jsMain/kotlin/earth/worldwind/WorldWindow.kt index 8c4eb18b0..08067ed38 100644 --- a/worldwind/src/jsMain/kotlin/earth/worldwind/WorldWindow.kt +++ b/worldwind/src/jsMain/kotlin/earth/worldwind/WorldWindow.kt @@ -191,8 +191,8 @@ open class WorldWindow( */ fun canvasCoordinates(x: Number, y: Number): Vec2 { val bbox = canvas.getBoundingClientRect() - val xc = x.toDouble() - (bbox.left + canvas.clientLeft) // * canvas.width / bbox.width - val yc = y.toDouble() - (bbox.top + canvas.clientTop) // * canvas.height / bbox.height + val xc = (x.toDouble() - (bbox.left + canvas.clientLeft)) * canvas.width / bbox.width + val yc = (y.toDouble() - (bbox.top + canvas.clientTop)) * canvas.height / bbox.height return Vec2(xc, yc) } diff --git a/worldwind/src/jsMain/kotlin/earth/worldwind/gesture/SelectDragDetector.kt b/worldwind/src/jsMain/kotlin/earth/worldwind/gesture/SelectDragDetector.kt index 423f9ba93..0900ff00e 100644 --- a/worldwind/src/jsMain/kotlin/earth/worldwind/gesture/SelectDragDetector.kt +++ b/worldwind/src/jsMain/kotlin/earth/worldwind/gesture/SelectDragDetector.kt @@ -159,8 +159,8 @@ open class SelectDragDetector(protected val wwd: WorldWindow) { if (clapToGround && wwd.engine.pickTerrainPosition(movePoint.x, movePoint.y, toPosition) || !clapToGround && wwd.engine.geographicToScreenPoint(fromPosition.latitude, fromPosition.longitude, 0.0, dragRefPt) && wwd.engine.screenPointToGroundPosition( - dragRefPt.x + recognizer.translationX - lastTranslation.x, - dragRefPt.y + recognizer.translationY - lastTranslation.y, + dragRefPt.x + (recognizer.translationX - lastTranslation.x) * wwd.engine.densityFactor, + dragRefPt.y + (recognizer.translationY - lastTranslation.y) * wwd.engine.densityFactor, toPosition )) { // Backup last translation