Skip to content

Commit 4135cb4

Browse files
committed
#257 map doesn't be blank
1 parent 0ca8a98 commit 4135cb4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

app/helpers/gtt_map_helper.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,37 @@ def map_tag(map: nil, layers: map&.layers,
3939
content_tag(:div, "", data: data, id: uid, class: 'ol-map',
4040
style: (collapsed ? "display: none" : "display: block")),
4141
javascript_tag("
42+
var contentObserver = () => {
43+
const target = document.getElementById('#{uid}');
44+
const observerCallback = function(mutations) {
45+
mutations.forEach(function(mutation) {
46+
if (mutation.removedNodes.length) {
47+
mutation.removedNodes.forEach(function(node) {
48+
if (node === target) {
49+
observer.disconnect();
50+
let event = new Event('contentUpdated');
51+
document.dispatchEvent(event);
52+
}
53+
});
54+
}
55+
});
56+
};
57+
const observer = new MutationObserver(observerCallback);
58+
const config = {
59+
childList: true,
60+
subtree: true
61+
};
62+
observer.observe(document.body, config);
63+
}
64+
document.addEventListener('contentUpdated', function(){
65+
var target = document.getElementById('#{uid}');
66+
window.createGttClient(target);
67+
contentObserver();
68+
}, { once: true });
4269
document.addEventListener('DOMContentLoaded', function(){
4370
var target = document.getElementById('#{uid}');
4471
window.createGttClient(target);
72+
contentObserver();
4573
});
4674
")
4775
]

0 commit comments

Comments
 (0)