Skip to content

Commit

Permalink
Fix screen coordinates calculation on JS version when density factor …
Browse files Browse the repository at this point in the history
…is not equal 1.0.
  • Loading branch information
ComBatVision committed Oct 15, 2024
1 parent ff66a3a commit 5132761
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {
}
dependencies {
implementation 'earth.worldwind:worldwind:1.5.25'
implementation 'earth.worldwind:worldwind:1.5.26'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {

allprojects {
group = "earth.worldwind"
version = "1.5.25"
version = "1.5.26"

extra.apply {
set("minSdk", 21)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h3>OmnidirectionalSightlineFragment.kt</h3>
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions worldwind/src/jsMain/kotlin/earth/worldwind/WorldWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5132761

Please sign in to comment.