Skip to content

Commit 86ae5cc

Browse files
RD-971: Add camera helper object (#14)
1 parent c8e5552 commit 86ae5cc

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2025, MapTiler
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD 3-Clause
5+
*/
6+
7+
package com.maptiler.maptilersdk.map
8+
9+
/**
10+
* A geographical location which contains a latitude, longitude pair.
11+
*/
12+
data class LatLng(val latitude: Double, val longitude: Double)
13+
14+
/**
15+
* Sets combination of center, bearing and pitch, as well as roll and elevation.
16+
*/
17+
class MTMapCameraHelper private constructor(
18+
val centerCoordinate: LatLng? = null,
19+
val bearing: Double? = null,
20+
val pitch: Double? = null,
21+
val roll: Double? = null,
22+
val elevation: Double? = null,
23+
) {
24+
companion object {
25+
/**
26+
* Returns camera object with all properties set to 0.
27+
*/
28+
fun getCamera(): MTMapCameraHelper {
29+
return MTMapCameraHelper(
30+
centerCoordinate = LatLng(0.0, 0.0),
31+
bearing = 0.0,
32+
pitch = 0.0,
33+
roll = 0.0,
34+
elevation = 0.0,
35+
)
36+
}
37+
38+
/**
39+
* Returns camera object initialized from map style options.
40+
*
41+
* If any of the properties is not set within the style, it will default to 0.
42+
*/
43+
fun getCameraFromMapStyle(): MTMapCameraHelper {
44+
return MTMapCameraHelper()
45+
}
46+
47+
/**
48+
* Returns camera object with the given center coordinate, bearing, pitch, roll and elevation.
49+
*/
50+
fun cameraLookingAtCenterCoordinate(
51+
centerCoordinate: LatLng,
52+
bearing: Double,
53+
pitch: Double,
54+
roll: Double,
55+
elevation: Double,
56+
): MTMapCameraHelper {
57+
return MTMapCameraHelper(
58+
centerCoordinate = centerCoordinate,
59+
bearing = bearing,
60+
pitch = pitch,
61+
roll = roll,
62+
elevation = elevation,
63+
)
64+
}
65+
66+
/**
67+
* Returns camera object with the given center coordinate, bearing and pitch.
68+
*
69+
* Looks for roll and elevation in the map's style object.
70+
* If they are not specified in the style, they will default to 0.
71+
*/
72+
fun cameraLookingAtCenterCoordinate(
73+
centerCoordinate: LatLng,
74+
bearing: Double,
75+
pitch: Double,
76+
): MTMapCameraHelper {
77+
return MTMapCameraHelper(
78+
centerCoordinate = centerCoordinate,
79+
bearing = bearing,
80+
pitch = pitch,
81+
)
82+
}
83+
}
84+
85+
/**
86+
* Returns boolean indicating whether camera object is equal to the receiver.
87+
*
88+
* @param otherCamera MTMapCameraHelper to compare with.
89+
*/
90+
fun isEqualTo(otherCamera: MTMapCameraHelper): Boolean {
91+
val centerIsEqual = centerCoordinate == otherCamera.centerCoordinate
92+
val bearingIsEqual = bearing == otherCamera.bearing
93+
val pitchIsEqual = pitch == otherCamera.pitch
94+
val rollIsEqual = roll == otherCamera.roll
95+
val elevationIsEqual = elevation == otherCamera.elevation
96+
97+
return centerIsEqual && bearingIsEqual && pitchIsEqual && rollIsEqual && elevationIsEqual
98+
}
99+
}

0 commit comments

Comments
 (0)