Merge pull request #521 from openlayers/full-screen-control
Full screen control
This commit is contained in:
47
css/ol.css
47
css/ol.css
@@ -24,6 +24,50 @@
|
||||
position: absolute;
|
||||
border: 2px solid red;
|
||||
}
|
||||
.ol-full-screen {
|
||||
background: rgba(255,255,255,0.4);
|
||||
border-radius: 4px;
|
||||
padding: 2px;
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
top: 8px;
|
||||
}
|
||||
@media print {
|
||||
.ol-full-screen {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.ol-full-screen a {
|
||||
background: rgba(0,60,136,0.5);
|
||||
color: white;
|
||||
display: block;
|
||||
font-family: 'Lucida Grande',Verdana,Geneva,Lucida,Arial,Helvetica,sans-serif;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
height: 22px;
|
||||
line-height: 19px;
|
||||
margin: 1px;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
width: 22px;
|
||||
}
|
||||
a.ol-full-screen-false:after {
|
||||
content: "\2194";
|
||||
}
|
||||
a.ol-full-screen-true:after {
|
||||
content: "\00d7";
|
||||
}
|
||||
|
||||
.ol-full-screen div {
|
||||
border-radius: 2px;
|
||||
}
|
||||
.ol-full-screen div a {
|
||||
border-radius: 2px;
|
||||
}
|
||||
.ol-full-screen a:hover {
|
||||
background: rgba(0,60,136,0.7);
|
||||
}
|
||||
.ol-logo {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
@@ -55,6 +99,9 @@
|
||||
margin: 1px;
|
||||
padding: 0px 2px;
|
||||
}
|
||||
.ol-unsupported {
|
||||
display: none;
|
||||
}
|
||||
.ol-viewport .ol-unselectable {
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
|
||||
@@ -4,24 +4,64 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<title>Full-Screen example</title>
|
||||
<style type="text/css">
|
||||
html, body, .map {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
|
||||
<style>
|
||||
.map:-moz-full-screen {
|
||||
height: 100%;
|
||||
}
|
||||
.map:-webkit-full-screen {
|
||||
height: 100%;
|
||||
}
|
||||
.map:full-screen {
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
<title>Full screen control example</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" class="map"></div>
|
||||
<script src="loader.js?id=full-screen" type="text/javascript"></script>
|
||||
|
||||
<div style="display: none;">
|
||||
<div id="title">Full-screen example</div>
|
||||
<div id="shortdesc">Example of a full-screen map.</div>
|
||||
<div id="tags">fullscreen, mapquest, openaerial, tile, tilelayer</div>
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="./">OpenLayers 3 Examples</a>
|
||||
<ul class="nav pull-right">
|
||||
<li><iframe class="github-watch-button" src="http://ghbtns.com/github-btn.html?user=openlayers&repo=ol3&type=watch&count=true"
|
||||
allowtransparency="true" frameborder="0" scrolling="0" height="20" width="90"></iframe></li>
|
||||
<li><a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-hashtags="openlayers"> </a></li>
|
||||
<li><div class="g-plusone-wrapper"><div class="g-plusone" data-size="medium" data-annotation="none"></div></div></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div id="map" class="map"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
|
||||
<div class="span4">
|
||||
<h4 id="title">Full screen control example</h4>
|
||||
<p id="shortdesc">Example of a full screen control. Click the control in the top right corner to go full screen. Click it again to exit full screen.</p>
|
||||
<p>If there is no button on the map, your browser does not support the <a href="http://caniuse.com/#feat=fullscreen">Full Screen API</a>.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="full-screen.js" target="_blank">full-screen.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">full-screen, bing, bing-maps</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="loader.js?id=full-screen" type="text/javascript"></script>
|
||||
<script src="../resources/social-links.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHints');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.control.FullScreen');
|
||||
goog.require('ol.control.defaults');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.source.MapQuestOpenAerial');
|
||||
goog.require('ol.source.BingMaps');
|
||||
|
||||
|
||||
var layer = new ol.layer.TileLayer({
|
||||
source: new ol.source.MapQuestOpenAerial()
|
||||
var view = new ol.View2D({
|
||||
center: [-9101767, 2822912],
|
||||
zoom: 14
|
||||
});
|
||||
|
||||
var view = new ol.View2D();
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [layer],
|
||||
controls: ol.control.defaults({}, [
|
||||
new ol.control.FullScreen()
|
||||
]),
|
||||
layers: [
|
||||
new ol.layer.TileLayer({
|
||||
source: new ol.source.BingMaps({
|
||||
key: 'AgtFlPYDnymLEe9zJ5PCkghbNiFZE9aAtTy3mPaEnEBXqLHtFuTcKoZ-miMC3w7R',
|
||||
style: 'Aerial'
|
||||
})
|
||||
})
|
||||
],
|
||||
renderers: ol.RendererHints.createFromQueryData(),
|
||||
target: 'map',
|
||||
view: view
|
||||
});
|
||||
|
||||
var mapSize = map.getSize();
|
||||
if (mapSize) {
|
||||
view.fitExtent(view.getProjection().getExtent(), mapSize);
|
||||
}
|
||||
|
||||
@@ -112,6 +112,13 @@
|
||||
* @property {ol.control.ZoomOptions|undefined} zoomOptions Zoom options.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.FullScreenOptions
|
||||
* @property {boolean|undefined} keys Full keyboard access.
|
||||
* @property {ol.Map|undefined} map Map.
|
||||
* @property {Element|undefined} target Target.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.LogoOptions
|
||||
* @property {ol.Map|undefined} map Map.
|
||||
|
||||
1
src/ol/control/fullscreencontrol.exports
Normal file
1
src/ol/control/fullscreencontrol.exports
Normal file
@@ -0,0 +1 @@
|
||||
@exportClass ol.control.FullScreen ol.control.FullScreenOptions
|
||||
103
src/ol/control/fullscreencontrol.js
Normal file
103
src/ol/control/fullscreencontrol.js
Normal file
@@ -0,0 +1,103 @@
|
||||
goog.provide('ol.control.FullScreen');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.dom.classes');
|
||||
goog.require('goog.dom.fullscreen');
|
||||
goog.require('goog.dom.fullscreen.EventType');
|
||||
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 : {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.cssClassName_ = 'ol-full-screen';
|
||||
|
||||
var aElement = goog.dom.createDom(goog.dom.TagName.A, {
|
||||
'href': '#fullScreen',
|
||||
'class': this.cssClassName_ + '-' + goog.dom.fullscreen.isFullScreen()
|
||||
});
|
||||
goog.events.listen(aElement, [
|
||||
goog.events.EventType.CLICK,
|
||||
goog.events.EventType.TOUCHEND
|
||||
], this.handleClick_, false, this);
|
||||
|
||||
goog.events.listen(goog.global.document, goog.dom.fullscreen.EventType.CHANGE,
|
||||
this.handleFullScreenChange_, false, this);
|
||||
|
||||
var element = goog.dom.createDom(goog.dom.TagName.DIV, {
|
||||
'class': this.cssClassName_ + ' ' + ol.css.CLASS_UNSELECTABLE +
|
||||
(!goog.dom.fullscreen.isSupported() ? ol.css.CLASS_UNSUPPORTED : '')
|
||||
}, 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) {
|
||||
if (!goog.dom.fullscreen.isSupported()) {
|
||||
return;
|
||||
}
|
||||
browserEvent.preventDefault();
|
||||
var map = this.getMap();
|
||||
if (goog.isNull(map)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.control.FullScreen.prototype.handleFullScreenChange_ = function() {
|
||||
var opened = this.cssClassName_ + '-true';
|
||||
var closed = this.cssClassName_ + '-false';
|
||||
var anchor = goog.dom.getFirstElementChild(this.element);
|
||||
if (goog.dom.fullscreen.isFullScreen()) {
|
||||
goog.dom.classes.swap(anchor, closed, opened);
|
||||
} else {
|
||||
goog.dom.classes.swap(anchor, opened, closed);
|
||||
}
|
||||
};
|
||||
@@ -7,3 +7,11 @@ goog.provide('ol.css');
|
||||
* @const {string}
|
||||
*/
|
||||
ol.css.CLASS_UNSELECTABLE = 'ol-unselectable';
|
||||
|
||||
|
||||
/**
|
||||
* The CSS class for unsupported feature.
|
||||
*
|
||||
* @const {string}
|
||||
*/
|
||||
ol.css.CLASS_UNSUPPORTED = 'ol-unsupported';
|
||||
|
||||
Reference in New Issue
Block a user