Skip to content

Commit

Permalink
Integrate photo place link to google maps
Browse files Browse the repository at this point in the history
  • Loading branch information
dacr committed May 18, 2024
1 parent 0efcca7 commit f43c90e
Showing 1 changed file with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.janalyse.sotohp.gui

import fr.janalyse.sotohp.model.PhotoPlace
import fr.janalyse.sotohp.store.{PhotoStoreService, PhotoStoreSystemIssue}
import javafx.scene.input.KeyCode
import zio.*
Expand All @@ -9,6 +10,7 @@ import zio.config.typesafe.TypesafeConfigProvider
import scalafx.application.*
import scalafx.scene.Scene
import scalafx.scene.control.Label
import scalafx.scene.control.Hyperlink
import scalafx.scene.control.Button
import scalafx.scene.layout.{HBox, Region, VBox}
import scalafx.application.Platform
Expand All @@ -24,10 +26,21 @@ enum UserAction {

object PhotoViewerApp extends ZIOAppDefault {

def buildGoogleMapsHyperLink(place: PhotoPlace): String = {
val lat = place.latitude
val lon = place.longitude
s"https://www.google.com/maps/search/?api=1&query=$lat,$lon"
}

class FxApp extends JFXApp3 {
lazy val infoHasGPS = Label("")
lazy val infoDateTime = Label("DateTime")
lazy val infoCategory = Label("Category")
private val hasNoGPSText = "?"
private val hasGPSText = ""
private val noCategoryText = "No category"
private val noShootDateTimeText = "No shoot timestamp"

lazy val infoHasGPS = Label(hasNoGPSText)
lazy val infoDateTime = Label(noShootDateTimeText)
lazy val infoCategory = Label(noCategoryText)
lazy val first = Button("") // LEFTWARDS ARROW TO BAR
lazy val previous = Button("") // LEFTWARDS DASHED ARROW
lazy val next = Button("") // RIGHTWARDS DASHED ARROW
Expand All @@ -40,10 +53,10 @@ object PhotoViewerApp extends ZIOAppDefault {
lazy val display = PhotoDisplay()
lazy val displaySFX = jfxRegion2sfx(display)
lazy val buttons = HBox(first, previous, next, last, zoom, faces, rotateLeft, rotateRight)
lazy val infos = HBox(10d, infoHasGPS, infoDateTime, infoCategory)
lazy val infos = HBox(5d, infoHasGPS, infoDateTime, infoCategory)
lazy val controls = VBox(buttons, infos)

override def start(): Unit = {
override def start(): Unit = {
stage = new JFXApp3.PrimaryStage {
title = "SOTOHP Viewer"
scene = new Scene {
Expand Down Expand Up @@ -75,11 +88,20 @@ object PhotoViewerApp extends ZIOAppDefault {
displaySFX.maxWidth <== stage.width
displaySFX.maxHeight <== (stage.height - buttons.height * 2.5) // TODO
}

def show(photo: PhotoToShow): Unit = {
infoDateTime.text = photo.shootDateTime.map(_.toString).getOrElse("Unknown shooting date")
infoHasGPS.text = photo.place.map(_ => "").getOrElse("")
infoCategory.text = photo.description.flatMap(_.category).map(_.text).getOrElse("No category")
infoDateTime.text = photo.shootDateTime.map(_.toString).getOrElse(noShootDateTimeText)
infoHasGPS.text = photo.place.map(_ => hasGPSText).getOrElse(hasNoGPSText)
infoHasGPS.style =
photo
.place
.map(_ => "-fx-text-fill: green")
.getOrElse("-fx-text-fill: red")
infoHasGPS.onMouseClicked = event => {
photo.place.foreach(place =>
hostServices.showDocument(buildGoogleMapsHyperLink(place))
)
}
infoCategory.text = photo.description.flatMap(_.category).map(_.text).getOrElse(noCategoryText)
display.drawImage(photo) // normalized photo are already rotated
}
}
Expand Down

0 comments on commit f43c90e

Please sign in to comment.