Add full screen control

This commit is contained in:
Tom Payne
2013-04-09 22:00:43 +02:00
parent 055a4da761
commit cef6fe4930
4 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
goog.provide('ol.control.FullScreen');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.dom.fullscreen');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.control.Control');
goog.require('ol.css');
/**
* @constructor
* @extends {ol.control.Control}
* @param {ol.control.FullScreenOptions=} opt_options Options.
*/
ol.control.FullScreen = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
var aElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#fullScreen'
}, '\u00d7');
goog.events.listen(aElement, [
goog.events.EventType.CLICK,
goog.events.EventType.TOUCHEND
], this.handleClick_, false, this);
var element = goog.dom.createDom(goog.dom.TagName.DIV, {
'class': 'ol-full-screen ' + ol.css.CLASS_UNSELECTABLE
}, aElement);
goog.base(this, {
element: element,
map: options.map,
target: options.target
});
/**
* @private
* @type {boolean}
*/
this.keys_ = goog.isDef(options.keys) ? options.keys : false;
};
goog.inherits(ol.control.FullScreen, ol.control.Control);
/**
* @param {goog.events.BrowserEvent} browserEvent Browser event.
* @private
*/
ol.control.FullScreen.prototype.handleClick_ = function(browserEvent) {
browserEvent.preventDefault();
var map = this.getMap();
if (goog.isNull(map)) {
return;
}
if (!goog.dom.fullscreen.isSupported()) {
return;
}
if (goog.dom.fullscreen.isFullScreen()) {
goog.dom.fullscreen.exitFullScreen();
} else {
var element = map.getTarget();
goog.asserts.assert(!goog.isNull(element));
if (this.keys_) {
goog.dom.fullscreen.requestFullScreenWithKeys(element);
} else {
goog.dom.fullscreen.requestFullScreen(element);
}
}
};