Skip to content

Commit 64f2a8a

Browse files
committed
Adds rotation settings
Signed-off-by: Daniel Kastl <[email protected]>
1 parent 5ec972d commit 64f2a8a

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

app/views/projects/settings/_gtt.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</p>
1515
<p>
1616
<%= content_tag(:label, l(:gtt_map_rotate_label)) %>
17-
<%= number_field_tag('gtt_configuration[map_rotation]', @project.map_rotation, min: 1, max: 360, size: 10 ) %>
17+
<%= number_field_tag('gtt_configuration[map_rotation]', @project.map_rotation, min: 0, max: 359, size: 10, readonly: true ) %>
1818
<br /><em><%= t :gtt_map_rotate_info_html %></em>
1919
</p>
2020
</div>

config/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ en:
5353
gtt_tile_sources_load_example: "Load example configuration."
5454

5555
gtt_map_rotate_label: "Map rotation"
56-
gtt_map_rotate_info_html: "Hold down <code>Shift+Alt</code> and drag to rotate."
56+
gtt_map_rotate_info_html: "Hold down <code>Shift+Alt</code> and drag the map to rotate."
5757

5858
gtt_settings_general_center_lon: "Default map center longitude"
5959
gtt_settings_general_center_lat: "Default map center latitude"

src/components/gtt-client.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,24 +335,19 @@ export class GttClient {
335335
this.toolbar.addControl(maximizeCtrl)
336336

337337
// Map rotation
338-
function radiansToDegrees(radians:number) {
339-
let degrees = radians * (180 / Math.PI)
340-
degrees = (degrees % 360 + 360) % 360
341-
return degrees
342-
}
343-
344-
function degreesToRadians(degrees:number) {
345-
return degrees * (Math.PI / 180)
346-
}
347-
348-
const rotation_field = document.querySelector('#gtt_configuration_map_rotation')
338+
const rotation_field = document.querySelector('#gtt_configuration_map_rotation') as HTMLElement
349339
if (rotation_field !== null) {
350340
this.map.getView().on('change:rotation', (evt) => {
351341
rotation_field.setAttribute(
352342
'value',
353343
String(Math.round(radiansToDegrees(evt.target.getRotation())))
354344
)
355345
})
346+
347+
// TODO: remove readonly flag from field and update map on input
348+
// rotation_field.addEventListener("oninput", (evt) => {
349+
// console.log(evt)
350+
// })
356351
}
357352

358353
if (this.contents.edit) {
@@ -849,7 +844,8 @@ export class GttClient {
849844
// Avoid flicker (map move)
850845
center: center,
851846
zoom: parseInt(this.defaults.zoom),
852-
maxZoom: parseInt(this.defaults.maxzoom) // applies for Mierune Tiles
847+
maxZoom: parseInt(this.defaults.maxzoom), // applies for Mierune Tiles
848+
rotation: degreesToRadians(parseInt(this.map.getTargetElement().getAttribute("data-rotation")))
853849
})
854850
this.map.setView(view)
855851
}
@@ -1382,6 +1378,16 @@ const getCookie = (cname:string):string => {
13821378
return ''
13831379
}
13841380

1381+
const radiansToDegrees = (radians: number) => {
1382+
let degrees = radians * (180 / Math.PI)
1383+
degrees = (degrees % 360 + 360) % 360
1384+
return degrees
1385+
}
1386+
1387+
const degreesToRadians = (degrees: number) => {
1388+
return degrees * (Math.PI / 180)
1389+
}
1390+
13851391
const getMapSize = (map: Map) => {
13861392
let size = map.getSize()
13871393
if (size.length === 2 && size[0] <= 0 && size[1] <= 0) {

0 commit comments

Comments
 (0)