How to exit full screen mode in Google maps API - google-maps

I am programming web page with Google map on it and some markers (points). Markers have some InfoWindows, in InfoWindow is a link to a <div> tag on the same page. Something like
var infowindow = new google.maps.InfoWindow({
content: 'See info'
});
In this way, the user can display InfoWindow on the map, and then the user can display additional information below on the web page.
It works fine. BUT if the map is in FullScreen mode, the link does not work.
If user clicks on the link in the full screen mode, I would like to
Exit full screen mode, and
Scroll to the anchored <div
id="info">
Can somebody help?
I have tested, that if the link goes to another web page, then it works fine even in the FullScreen mode. The problem is only in linking the same page (via #id).

I tweaked my original solution:
I muset set onClick listener to link ant this listener has to handle the two steps: 1) exit full screen mode and 2) scroll to given tag
Exiting full screen mode is done by i) Checking if document is in full screen mode and if yes, then ii) Exit full screen mode.
This must be done for different webkits
function onClickListener(id) {
// Exit Full Screen Mode
if (document.fullscreenElement ) {
document.exitFullscreen();
} else if (document.mozFullScreenElement ) {
document.mozCancelFullScreen();
} else if (document.webkitFullscreenElement ) {
document.webkitExitFullscreen();
} else if (document.msFullscreenElement ) {
document.msExitFullscreen();
}
// Scroll to #id - using jQuery
$('html,body').animate({scrollTop:$('#'+id).offset().top}, 700);
return false;
}

Related

Google Maps AutoComplete dropdown hidden when Google Maps Full Screen is true

I've implemented a google maps with autocomplete onverlayed on the map and I've set the FullScreenControl option to "true" (You can see the FullScreenControl on the right in the image below)
My problem is that when I switch to FullScreen mode by clicking the FullScreenControl, the dropdown is hidden behind the google map.
It seems that the ZIndex is too low but setting it to a very large number does not seem to fix the issue. You can see from the image below that the dropdown exists, but only behind the fullscreen google map.
I did find a similar question with answer where someone used a normal dropdown and not the google map autocomplete.
Similar Question and answer
However the solution didn't work for me.
Setting the ZIndex doesn't seem to work.
I'm using TypeScript with Angular2.
Thank you.
]4
For anyone struggling with this, if the z-index solution is not working:
The Google maps generated div ("pac-container") with the autocomplete options is appended to the body child elements. But when in full screen, only elements inside the target element (the map div) will be shown, so z-index is ignored.
A quick workaround is to move the pac-container div inside the map div when entering full screen, and move it back on exit.
document.onfullscreenchange = function ( event ) {
let target = event.target;
let pacContainerElements = document.getElementsByClassName("pac-container");
if (pacContainerElements.length > 0) {
let pacContainer = document.getElementsByClassName("pac-container")[0];
if (pacContainer.parentElement === target) {
console.log("Exiting FULL SCREEN - moving pacContainer to body");
document.getElementsByTagName("body")[0].appendChild(pacContainer);
} else {
console.log("Entering FULL SCREEN - moving pacContainer to target element");
target.appendChild(pacContainer);
}
} else {
console.log("FULL SCREEN change - no pacContainer found");
}};
i was fix it with add z-index to .pac-container
see here
.pac-container, .pac-item{
z-index: 2147483647 !important;
}
Thank you #vladhorby! I ended up with your solution due to updating z-index not working on my case. I got 1 little bug, somehow that options position not in the right place when on the fullscreen mode. I add little code to fix this thing. The idea is to add a class when in fullscreen mode, and delete that after leave the fullscreen. Hope this can help anyone with the same case.
document.onfullscreenchange = function ( event ) {
let target = event.target;
let pacContainerElements = document.getElementsByClassName("pac-container");
if (pacContainerElements.length > 0) {
let pacContainer = document.getElementsByClassName("pac-container")[0];
if (pacContainer.parentElement === target) {
document.getElementsByTagName("body")[0].appendChild(pacContainer);
pacContainer.className += pacContainer.className.replace("fullscreen-pac-container", "");
} else {
target.appendChild(pacContainer);
pacContainer.className += " fullscreen-pac-container";
}
}
};
and the last thing add this to the your css file:
.fullscreen-pac-container[style]{
z-index: 2547483647 !important;
top:50px !important;
}

Leaving fullscreen in IE11

Using IE11, if I enter fullscreen mode from the button on the toolbar, then leave full screen mode by pressing F11, the viewer continues to fill the browser window until you press the leave fullscreen button.
I am looking to implement a custom UI, which doesn't have a leave fullscreen button, so want to fix the MSFullscreen event handler.
I think the problem is that when leaving full screen mode, ScreenModeDelegate.prototype.fullscreenEventListener() calls inFullscreen() which returns true.
if ("webkitIsFullScreen" in document) return document.webkitIsFullScreen;
return !!(document.mozFullScreenElement ||
document.msFullscreenElement ||
document.fullscreenElement ||
document.querySelector(".viewer-fill-browser")); // Fallback for iPad
IE11, so no webkitIsFullScreen. msFullscreenElement is null, but the document.querySelector fallback for iPad is true, because .viewer-fill-browser hasn't been removed yet. '.viewer-fill-browser' then isn't removed, we appear to still be in full screen mode.
On Chrome it just returns webkitIsFullScreen, which is false.
Is there a workaround for IE11?
As a workaround it should be possible to patch the default implementation with a fixed version (code below is not tested, it might contain errors)
<script src="path/to/viewer3D.min.js?v=2.12"></script>
<script type="text/javascript">
Autodesk.Viewing.inFullscreen = function() {
if ("fullscreenElement" in document) return document.fullscreenElement;
if ("webkitIsFullScreen" in document) return document.webkitIsFullScreen;
if ("mozFullScreenElement " in document) return document.mozFullScreenElement;
if ("msFullscreenElement" in document) return document.msFullscreenElement;
return !!(document.querySelector(".viewer-fill-browser")); // Fallback for iPad
}
</script>
<script type="text/javascript">
// your code
</script>
I guess you could use a tool for the viewer which doesn't require patching the viewer3D.js source yourself.
In the handleKeyDown handler you check for F11 being pressed and remove the .viewer-fill-browser selector from the DOM ...
this.handleKeyDown = function(event, keyCode) {
console.log('-------------------');
console.log('Tool:handleKeyDown(event, keyCode)');
console.log(event);
console.log(keyCode);
return false;
};
Hope that helps
FYI, this issue is fixed in v2.15.

Cordova Admob causing google map rendering "grey" screen in Ionic tabs

Running ionic tabs. My maps works fine until I click to another tab and then click back to the map. When returning to the map tab, most of the map is greyed out with a little bit of the map still appearing in the upper left corner. If I grab the visible section of the map and drag into the center view I see the visible maps is about 2/3rd of the screen - but the moment I let go the visible part shoots back up to upper left corner - and now all the previously greyed out section is just a blank white.
In addition, if I simply rotate my device from portrait to landscape - the map completely redraws itself correctly. And then from landscape back to portrait mode and the full maps is showing again.
For the life of me though, I can't get the 'grey' out from happening.
In my apps.js:
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
globalGPS() ;
});
})
.config(function($stateProvider,$urlRouterProvider) {
'$compileProvider',
function( $compileProvider )
{
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?||tel):/);
// Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)
}
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html",
controller: 'TabsCtrl'
})
// Each tab has its own nav history stack:
.state('tab.map', {
url: '/map',
views: {
'tab-map': {
templateUrl: 'templates/tab-map.html',
controller: 'MapCtrl'
}
}
})
The gps functions take place outside of the state/controllers loaded from a standard javascript file, and when all the gps that same external function sets the map as a global var:
setMap = new google.maps.Map(document.getElementById("mapBody"), myOptions);
In my controller is defined:
.controller('MapCtrl', function($scope,$rootScope,constants) {
// runs this code on EVERY return to map tab
$scope.$on('$ionicView.beforeEnter', function(){
if (setMap) {
google.maps.event.addListener(setMap, "idle", function(){
google.maps.event.trigger(setMap, "resize");
}) ;
// $scope.refreshMap() ; // see note below
}
});
$scope.refreshMap = function() {
setTimeout(function () {
$scope.refreshMap_();
}, 1);
};
$scope.refreshMap_ = function() {
var div = document.getElementById("mapBody");
reattachMap(setMap,div);
};
reattachMap() is an external function:
function reattachMap(map,div) {
if (!isDom(div)) {
return map;
} else {
map.set("div", div);
while(div.parentNode) {
div.style.backgroundColor = 'rgba(0,0,0,0)';
div = div.parentNode;
}
return map;
}
}
In place of the google.maps.event.trigger(setMap, "resize"), I tried using reattaching the map div thinking it had been removed from the DOM. Neither method works or even indicates I am onto the correct fix. In my div's that hold the maps I even hard set width/heigh css values as I had read that fixed some ppl's issues (whereas width/height percentages was causing the problem):
<div id="mapWrapper" style="position:absolute;width:100%;height:100%">
<div id="mapBody" data-tap-disabled="false"></div>
</div>
</div>
and
#mapBody {
border:2px solid #4e8cf9;
text-align:center;
height:700px;
width:400px;*/
flex: 1;
}
Well, I solved the issue. Turns out when moving away from the map tab to another tab, those other tabs are loading ads by AdMob. AdMob ads are not a part of the main DOM, they are a sub-view and thus they are persistent. If you navigate to another tab, the ad stays in the same place on the new tab. When navigating back to the map tab, the ad follows and somehow interferes with google maps ability to properly display itself.
In my app, the first default view is the map tab which doesn't show ads, so no map issues until user returns to the map tab (...and the persistent AdMob ad followed)
Sooo...i now used the above function to remove the ad from the map view completely.
.controller('MapCtrl', function($scope,$rootScope,constants) {
$scope.$on('$ionicView.beforeEnter', function(){
// this function will run EVERY time user goes back to this tab
if (setMap) { // only attempt to remove ad if 'map' is defined
removeAd() ; // global external function
});

[FireFox][HTML5 FullScreen API] How can I detect whether user clicked 'allow' button and allow full-screen mode

I'm researching and using html5 full-screen API with FireFox, I have a local html file, name 'SamplePlayer.html'. If I launched this file and clicked 'Full' button to make one element in to fullscreen mode like:
function launchFullScreen (element) {
if (typeof(element) == "undefined")
element = document.documentElement;
if (element.requestFullScreen) {
element.requestFullScreen();
}
else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
}
else if(element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
return true;
}
FireFox shows a dialog(maybe something else)'Press ESC to exit fullscreen, allow fullscreen, allow, reject', my question is , How can I detect user click 'allow' button and this dialog disappear? not merely element come into full mode and the dialog still exist.
I' ve test with:
document.addEventListener('webkitfullscreenchange', adjustElement, false);
document.addEventListener('mozfullscreenchange', adjustElement, false);
document.addEventListener('fullscreenchange', adjustElement, false);
function adjustElement() {
//alert("change");
//var tmp = fullscreenElement();
var tmp = fullscreen();
alert(tmp);
}
function fullscreenElement() {
return document.fullscreenElement ||
document.webkitCurrentFullScreenElement ||
document.mozFullScreenElement ||
null;
}
function fullscreen() {
return document.fullscreen ||
document.webkitIsFullScreen ||
document.mozFullScreen ||
false;
}
But while user request fullscreen, whether user clicked 'allow' button or not, all those function return true, how can I detect whether user clicked 'allow' button and allow full-screen mode with FireFox?
You cannot detect if the "Allow" button was clicked, and you're not supposed to detect it or be able to detect it either. It is a user decision and implementation detail.
Should there be some "hack" to detect it, it would be an implementation detail that is subject to change at any time, and there is a good chance it will change simply to close this information leak.
What you are able to detect and supposed to work with is entering/existing full screen mode state changes, via the mozfullscreenchange event. See the Using fullscreen mode documentation.

Disable zooming in for photo swipe

I'm using Photo Swipe to display my images. The default behavior when using it is that once the images are clicked, I'll be able to bring me to a "zoom-in page" where the photos are enlarged and i can view them one by one by swiping.
I'm trying to overwrite this behavior because I want to do something else after the user clicks on the image.
All solutions described here did not work for me. Here is a complete solution that turns off zooming.
Settings:
var options = {
// Gallery options
maxSpreadZoom: 1,
getDoubleTapZoom: function (isMouseClick, item) {
return item.initialZoomLevel;
},
// UI options
zoomEl: false
};
Gallery init:
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
// ...
And finally add this CSS snippet to disable zoom cursor:
.pswp--zoom-allowed .pswp__img {
cursor: default !important
}
The option allowUserZoom doesn't exist in the documentation
You can disable the double tap zoom by returning item.initialZoomLevel and reduce the spread (zoom) gesture by setting maxSpreadZoom to the same initialZoom :
gallery.init();
gallery.options.maxSpreadZoom = gallery.getZoomLevel();
gallery.options.getDoubleTapZoom = function(isMouseClick, item) {
return item.initialZoomLevel;
}
to disable zooming you must set
allowUserZoom = false