Skip to content

Commit 0d700a0

Browse files
committed
fixes #50 enable to run zoomToExtent in window.onload event
Signed-off-by: Taro Matsuzawa <[email protected]>
1 parent 7cbb0ea commit 0d700a0

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

app/helpers/gtt_map_helper.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ def map_tag(map: nil, layers: map&.layers,
3333
safe_join [
3434
content_tag(:div, "", data: data, id: uid, class: 'ol-map'),
3535
javascript_tag("
36-
$(document).ready(function(){
37-
/*
38-
App.init({
39-
target: $('##{uid}')[0]
40-
});
41-
*/
36+
document.addEventListener('DOMContentLoaded', function(){
4237
var target = document.getElementById('#{uid}');
4338
window.createGttClient(target);
4439
});

src/components/gtt-client.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ export class GttClient {
193193
this.vector.set('displayInLayerSwitcher', false)
194194
this.layerArray.push(this.vector)
195195
this.map.addLayer(this.vector)
196-
console.log(this.layerArray)
197196

198197
// Render project boundary if bounds are available
199198
if (this.contents.bounds && this.contents.bounds !== null) {
@@ -298,21 +297,23 @@ export class GttClient {
298297
// Because Redmine filter functions are applied later, the Window onload
299298
// event provides a workaround to have filters loaded before executing
300299
// the following code
301-
if (document.querySelectorAll('tr#tr_bbox').length > 0) {
302-
this.filters.location = true
303-
}
304-
if (document.querySelectorAll('tr#tr_distance').length > 0) {
305-
this.filters.distance = true
306-
}
307-
const legend = document.querySelector('fieldset#location legend') as HTMLLegendElement
308-
if (legend) {
309-
legend.addEventListener('click', (evt) => {
310-
const element = evt.currentTarget as HTMLLegendElement
311-
this.toggleAndLoadMap(element)
312-
})
313-
}
314-
this.zoomToExtent()
315-
this.map.on('moveend', this.updateFilter.bind(this))
300+
window.addEventListener('load', () => {
301+
if (document.querySelectorAll('tr#tr_bbox').length > 0) {
302+
this.filters.location = true
303+
}
304+
if (document.querySelectorAll('tr#tr_distance').length > 0) {
305+
this.filters.distance = true
306+
}
307+
const legend = document.querySelector('fieldset#location legend') as HTMLLegendElement
308+
if (legend) {
309+
legend.addEventListener('click', (evt) => {
310+
const element = evt.currentTarget as HTMLLegendElement
311+
this.toggleAndLoadMap(element)
312+
})
313+
}
314+
this.zoomToExtent()
315+
this.map.on('moveend', this.updateFilter.bind(this))
316+
})
316317

317318
// To fix an issue with empty map after changing the tracker type
318319
document.querySelectorAll('select#issue_tracker_id').forEach(element => {

0 commit comments

Comments
 (0)