Maps not loading in 2nd, 3rd, et.c tabs
Permalink Browser Info Environment
Hi, I am using the Location Map and Magic Tabs. In some pages I have multiple maps on the same page under different Tabs, but the maps are not loading in another tab. I contacted the maker of the Magic Tabs and he indicated a timer/check needed to be added. This has been added in the core Google Map package, but not yet in Location Map.
Can you add this as an update to the app - don't want any changes I make overwritten when they make sense for the core product.
This is the info he communicated:
JavaScript that creates complex display elements often takes information from the visibility or dimensions of their containing DOM element. A consequence is that if they are first rendered inside a DOM element that is hidden they get the wrong information and have glitches in their display. A typical example is Google Maps, where a map will not render if its canvas area is hidden, such as on a tab that is initially closed.
The following solution is one that developers can use to unilaterally improve the rendering of a problematic JavaScript. The solution has been implemented in the core Google Maps block and some marketplace blocks since c5.6.1 and the same solution is carried through all the way to current core versions. However, not all affected third party blocks implement this, so you may need to create a block template (or remind the third party block developer that they need to update their block).
$(document).ready(function(){
var t;
var startWhenVisible = function (){
if ($('#id').is(':visible')){
window.clearInterval(t);
initialiseWhatever();
return true;
}
return false;
};
if (!startWhenVisible()){
t = window.setInterval(function(){startWhenVisible();},100);
}
});
In this example, initialiseWhatever() is the method that starts the JavaScript or JQuery plugin before this modification, such as initialising Google Maps. You can see this in action in the view.php for the core Google Maps block.
If the containing DOM is visible ('#id'), it is run straight away. There is no appreciable overhead or change to the way the plugin works.
If not, a polling event is started to run every 100ms (a reasonable value that many users won't even notice), and the JavaScript or jQuery started when its container becomes visible. An important part to never forget is to clear the timer when the plugin is started window.clearInterval(t).
If the script is not using jQuery, the equivalent in pure JavaScript is:
window.onload = function() {
var t;
var elem;
var startWhenVisible = function (){
elem = document.getElementById('id');
if (elem.offsetWidth > 0 || elem.offsetHeight > 0){
window.clearInterval(t);
initialiseWhatever();
return true;
}
return false;
};
if (!startWhenVisible()){
t = window.setInterval(function(){startWhenVisible();},100);
}
}
Can you add this as an update to the app - don't want any changes I make overwritten when they make sense for the core product.
This is the info he communicated:
JavaScript that creates complex display elements often takes information from the visibility or dimensions of their containing DOM element. A consequence is that if they are first rendered inside a DOM element that is hidden they get the wrong information and have glitches in their display. A typical example is Google Maps, where a map will not render if its canvas area is hidden, such as on a tab that is initially closed.
The following solution is one that developers can use to unilaterally improve the rendering of a problematic JavaScript. The solution has been implemented in the core Google Maps block and some marketplace blocks since c5.6.1 and the same solution is carried through all the way to current core versions. However, not all affected third party blocks implement this, so you may need to create a block template (or remind the third party block developer that they need to update their block).
$(document).ready(function(){
var t;
var startWhenVisible = function (){
if ($('#id').is(':visible')){
window.clearInterval(t);
initialiseWhatever();
return true;
}
return false;
};
if (!startWhenVisible()){
t = window.setInterval(function(){startWhenVisible();},100);
}
});
In this example, initialiseWhatever() is the method that starts the JavaScript or JQuery plugin before this modification, such as initialising Google Maps. You can see this in action in the view.php for the core Google Maps block.
If the containing DOM is visible ('#id'), it is run straight away. There is no appreciable overhead or change to the way the plugin works.
If not, a polling event is started to run every 100ms (a reasonable value that many users won't even notice), and the JavaScript or jQuery started when its container becomes visible. An important part to never forget is to clear the timer when the plugin is started window.clearInterval(t).
If the script is not using jQuery, the equivalent in pure JavaScript is:
window.onload = function() {
var t;
var elem;
var startWhenVisible = function (){
elem = document.getElementById('id');
if (elem.offsetWidth > 0 || elem.offsetHeight > 0){
window.clearInterval(t);
initialiseWhatever();
return true;
}
return false;
};
if (!startWhenVisible()){
t = window.setInterval(function(){startWhenVisible();},100);
}
}
Type: | Ticket |
---|---|
Status: | Archived |
Awesome thanks!
-----Original Message-----
From: concrete5 Community [mailto:discussions@concretecms.com]
Sent: Sunday, October 1, 2017 6:26 PM
To: pauls@studio5d.com
Subject: Maps not loading in 2nd, 3rd, et.c tabs : Support
-----Original Message-----
From: concrete5 Community [mailto:discussions@concretecms.com]
Sent: Sunday, October 1, 2017 6:26 PM
To: pauls@studio5d.com
Subject: Maps not loading in 2nd, 3rd, et.c tabs : Support
Hi, was just getting back to this and saw that there hasn't been an update yet, so tried this on my own, but don't seem to have the right spot.
I was looking at view.php and it appears that the map is initialized around line 151
var map = new google.maps.Map(document.getElementById('map_<?php
It would seem that the first part of the code would be add there
and then the closing part around 350ish
after
being this
and then ending with the line }); (which is already there)
but something isn't quite right. Any suggestions?
I was looking at view.php and it appears that the map is initialized around line 151
var map = new google.maps.Map(document.getElementById('map_<?php
It would seem that the first part of the code would be add there
$(document).ready(function(){ var t; var startWhenVisible = function (){ if ($('#id').is(':visible')){ window.clearInterval(t);
and then the closing part around 350ish
after
$('#msv-location-map-<?php echo $unique_identifier;?> .showall a').click(function(e){ infoWindow.close(); map.fitBounds(bounds); e.preventDefault(); });
being this
} return false; }; if (!startWhenVisible()){ t = window.setInterval(function(){startWhenVisible();},100); }
and then ending with the line }); (which is already there)
but something isn't quite right. Any suggestions?
I just got a notification that I'd missed this message - did you end up resolving it, or are you still needing help here?
Hi,
Yes definitely still need some help. (For some reason my reply into this didn't register).
Thanks much!!!!
Yes definitely still need some help. (For some reason my reply into this didn't register).
Thanks much!!!!
Can you please try the attached code within your view.php file? Replace the whole file with the contents.
This is what JohnTheFirst kindly sent me, and it appears to be working for me, but I'd like to confirm that it's working within the context of your problem before pushing up a package update.
This is what JohnTheFirst kindly sent me, and it appears to be working for me, but I'd like to confirm that it's working within the context of your problem before pushing up a package update.
Working great!
Great, I've updated the package - version 1.0.7
Attention: Since there has been no activity on this issue for two weeks, this issue has been automatically archived.
To re-open this issue, reply to this message.
To re-open this issue, reply to this message.
Attention: Since there has been no activity on this issue for two weeks, this issue has been automatically archived.
To re-open this issue, reply to this message.
To re-open this issue, reply to this message.
Attention: Since there has been no activity on this issue for two weeks, this issue has been automatically archived.
To re-open this issue, reply to this message.
To re-open this issue, reply to this message.
Attention: Since there has been no activity on this issue for two weeks, this issue has been automatically archived.
To re-open this issue, reply to this message.
To re-open this issue, reply to this message.
Attention: Since there has been no activity on this issue for two weeks, this issue has been automatically archived.
To re-open this issue, reply to this message.
To re-open this issue, reply to this message.
Attention: Since there has been no activity on this issue for two weeks, this issue has been automatically archived.
To re-open this issue, reply to this message.
To re-open this issue, reply to this message.
thanks for this, John did make contact with me earlier regarding this and also supplied the solution/code. I will look to include this in the next version - in the meantime I won't be pushing up any updates that won't include this so you don't have to worry about code being overwritten.
Cheers
-Ryan