简体   繁体   English

如何触发OpenLayers 3全屏事件?

[英]How can I trigger the OpenLayers 3 full screen event?

I'm attempting to trigger my OpenLayers 3 map to become full screen within the code but I'm not having much luck. 我试图触发我的OpenLayers 3地图,使其在代码内变为全屏显示,但运气不佳。

I have something along the lines of: 我有一些类似的东西:

var fullScreenControl = new ol.control.FullScreen()

// Create map in between using fullScreenControl

fullScreenControl.changed();

The code accomplishes nothing though. 该代码什么也没有完成。 I tried fullScreenControl.dispatchEvent('change'); 我尝试了fullScreenControl.dispatchEvent('change'); also without luck. 也没有运气。 I'm guessing it's not too tricky, but all the other questions seem to revolve around detecting the event rather than triggering it. 我猜这不太棘手,但是所有其他问题似乎都围绕着检测事件而不是触发事件。

ol3 uses the "HTML5" Fullscreen API to toggle the map in full screen mode. ol3使用“ HTML5”全屏API在全屏模式下切换地图。 I am not sure what are you trying to accomplish, but there are different ways to toggle the fullscreen. 我不确定您要完成什么,但是有多种方法可以切换全屏。

Here is a pure js method to set your map on full screen: 这是一个纯js方法,可在全屏模式下设置地图:

function setMapToFullScreen(){
  //if your map element id is other than 'map' change it here
        var elem = document.getElementById('map');
        if (elem.requestFullscreen) {
          elem.requestFullscreen();
        } else if (elem.msRequestFullscreen) {
          elem.msRequestFullscreen();
        } else if (elem.mozRequestFullScreen) {
          elem.mozRequestFullScreen();
        } else if (elem.webkitRequestFullscreen) {
          elem.webkitRequestFullscreen();
        }   
}

Here is a fiddle to see it in action. 这是一个摆弄的小玩意儿

If you plan to attach the fullscreen functionality in a DOM element outside the map you can always use target option during fullscreen initialisation. 如果您打算在地图外部的DOM元素中附加全屏功能,则可以在全屏初始化期间始终使用target选项。 If you just want to do it programmatically, then use the function above. 如果您只是想以编程方式进行操作,请使用上面的功能。 It depends on what you want to achieve. 这取决于您要实现的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM