Skip to content

Commit ef90947

Browse files
committed
Adds map rotation computation
Signed-off-by: Daniel Kastl <[email protected]>
1 parent 50d9b98 commit ef90947

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

app/controllers/.keep

Whitespace-only changes.

app/helpers/.keep

Whitespace-only changes.

app/models/.keep

Whitespace-only changes.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
{}, { multiple: true, size: 5 } %>
1313
<br /><em><%= t :gtt_tile_sources_info %></em>
1414
</p>
15+
<p>
16+
<%= content_tag(:label, "Map rotation") %>
17+
<%= number_field_tag('settings[project_map_rotation]', 0, min: 1, max: 360, size: 10, readonly: true ) %>
18+
<br /><em><%= t :gtt_map_rotate_info %></em>
19+
</p>
1520
</div>
1621

1722
<div class="box">
1823
<%= map_form_field f, @form.map, bounds: nil, edit_mode: 'Polygon' %>
1924
</div>
2025

21-
2226
<%= submit_tag l(:button_save) %>
2327

2428
<% end %>

config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ en:
5050
gtt_tile_sources_select_xyz: "XYZ Tiles"
5151
gtt_tile_sources_load_example: "Load example configuration"
5252

53+
gtt_map_rotate_info: "Hold down <code>Shift+Alt</code> and drag to rotate."
54+
5355
gtt_settings_general_center_lon: "Default map center longitude"
5456
gtt_settings_general_center_lat: "Default map center latitude"
5557
gtt_settings_general_zoom_level: "Default map zoom level"

src/components/gtt-client.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export class GttClient {
120120
this.defaults.geocoder = JSON.stringify(quick_hack.geocoder)
121121
}
122122

123-
124123
this.contents = options.target.dataset
125124

126125
// create map at first
@@ -134,6 +133,7 @@ export class GttClient {
134133
})
135134
]),
136135
controls: control_defaults({
136+
rotateOptions: {},
137137
attributionOptions: {
138138
collapsible: false
139139
}
@@ -212,8 +212,8 @@ export class GttClient {
212212
this.layerArray.forEach( (l:Layer) => {
213213
if( l.get("baseLayer") ) {
214214
this.map.addLayer(l)
215-
}
216-
}
215+
}
216+
}
217217
)
218218

219219
var containsOverlay = false;
@@ -222,8 +222,8 @@ export class GttClient {
222222
if( !l.get("baseLayer") ) {
223223
this.map.addLayer(l)
224224
containsOverlay = true
225-
}
226-
}
225+
}
226+
}
227227
)
228228
}
229229

@@ -287,8 +287,6 @@ export class GttClient {
287287
})
288288
}
289289

290-
291-
292290
// For map div focus settings
293291
if (options.target) {
294292
if (options.target.getAttribute('tabindex') == null) {
@@ -320,6 +318,15 @@ export class GttClient {
320318
})
321319
this.toolbar.addControl(maximizeCtrl)
322320

321+
// Map rotation
322+
this.map.getView().on('change:rotation', (evt) => {
323+
const degrees = evt.target.getRotation() * 180 / Math.PI
324+
document.querySelector('#settings_project_map_rotation').setAttribute(
325+
'value',
326+
String(Math.round(degrees % 360))
327+
)
328+
})
329+
323330
if (this.contents.edit) {
324331
this.setControls(this.contents.edit.split(' '))
325332
} else if (this.contents.popup) {
@@ -398,7 +405,6 @@ export class GttClient {
398405
else {
399406
this.map.addControl(new LayerPopup())
400407
}
401-
402408

403409
// Because Redmine filter functions are applied later, the Window onload
404410
// event provides a workaround to have filters loaded before executing

0 commit comments

Comments
 (0)