Untitled

mail@pastecode.io avatar
unknown
kotlin
2 years ago
2.2 kB
2
Indexable
Never
  override fun onCastCellClicked(
        cell: MapCellEntity,
        verticalPosition: Int,
        horizontalPosition: Int
    ) {
        val mapCenter = myMap.currentDegree
        val currentVerticalPosition = mainList.size - verticalPosition + 1
        var currentHorizontalPosition = -1
        if (horizontalPosition + 1 > mainList.size) {
            currentHorizontalPosition = mainList.size - horizontalPosition + 1
        } else {
            currentHorizontalPosition = (mainList.size / 2) - horizontalPosition + 1
        }

        val distance = sqrt(
            (Math.pow(
                currentHorizontalPosition.toDouble(),
                2.0
            ) + Math.pow(
                currentVerticalPosition.toDouble(),
                2.0
            ))
        )

        val a = currentVerticalPosition.toDouble()
        val b = currentHorizontalPosition.toDouble()

        val aDegrees = Math.toDegrees(atan(a / b))
        val bDegrees = Math.toDegrees(atan(b / a))


        var azimuth = -1
        if (horizontalPosition + 1 > mainList.size) {
            azimuth = mapCenter + bDegrees.toInt()
        } else {
            azimuth = mapCenter - bDegrees.toInt()
        }

        Log.d("TestAzimuth", "$azimuth")
        var pole = ""
        if (azimuth in 157..202) {
            pole = "S"
        } else if (azimuth in 203..247) {
            pole = "SW"
        } else if (azimuth in 248..292) {
            pole = "W"
        } else if (azimuth in 293..337) {
            pole = "NW"
        } else if (azimuth > 337 || azimuth < 23) {
            pole = "N"
        } else if (azimuth in 23..67) {
            pole = "NE"
        } else if (azimuth in 68..112) {
            pole = "E"
        } else if (azimuth in 113..166) {
            pole = "SE"
        }

        val dialog = CertainSpotDialog(
            requireContext(),
            requireFragmentManager(),
            (context as MapperActivity),
            cell,
            mapID,
            viewLifecycleOwner,
            distance.toInt(),
            azimuth,
            pole,
            verticalPosition,
            horizontalPosition
        )
        dialog.initDialog()
    }