Skip to content

Commit

Permalink
[not ready] create fullscreen example and control (#3977)
Browse files Browse the repository at this point in the history
* create fullscreen example and control

* add fullscreen control

* toggle fullscreen

* clean up code

* set height and width

* change icon on esc

* add fullscreen to debug

* address merp comments

* remove _onKeyDown and _isFullscreen

* address johns comments

* move file to src folder and add case for IE11

* add newline to debug page

* add second argument
  • Loading branch information
colleenmcginnis authored Feb 25, 2017
1 parent 3a07c35 commit 78fc9c4
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dist/mapbox-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@
.mapboxgl-ctrl-icon.mapboxgl-ctrl-geolocate.watching {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20viewBox%3D%270%200%2020%2020%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%3E%0D%0A%20%20%3Cpath%20style%3D%27fill%3A%2300f%3B%27%20d%3D%27M10%204C9%204%209%205%209%205L9%205.1A5%205%200%200%200%205.1%209L5%209C5%209%204%209%204%2010%204%2011%205%2011%205%2011L5.1%2011A5%205%200%200%200%209%2014.9L9%2015C9%2015%209%2016%2010%2016%2011%2016%2011%2015%2011%2015L11%2014.9A5%205%200%200%200%2014.9%2011L15%2011C15%2011%2016%2011%2016%2010%2016%209%2015%209%2015%209L14.9%209A5%205%200%200%200%2011%205.1L11%205C11%205%2011%204%2010%204zM10%206.5A3.5%203.5%200%200%201%2013.5%2010%203.5%203.5%200%200%201%2010%2013.5%203.5%203.5%200%200%201%206.5%2010%203.5%203.5%200%200%201%2010%206.5zM10%208.3A1.8%201.8%200%200%200%208.3%2010%201.8%201.8%200%200%200%2010%2011.8%201.8%201.8%200%200%200%2011.8%2010%201.8%201.8%200%200%200%2010%208.3z%27%20%2F%3E%0D%0A%3C%2Fsvg%3E");
}

.mapboxgl-ctrl-icon.mapboxgl-ctrl-fullscreen {
background-image: url("data:image/svg+xml;base64,PD94b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> span.arrow {
width: 20px;
height: 20px;
Expand Down
23 changes: 23 additions & 0 deletions docs/_posts/examples/3400-01-28-fullscreen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
layout: example
category: example
title: View a fullscreen map
description: Toggle between current view and fullscreen mode
tags:
- controls-and-overlays
---

<div id='map'></div>

<script>

var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/outdoors-v9', //stylesheet location
center: [11.255, 43.77], // starting position
zoom: 13 // starting zoom
});

map.addControl(new mapboxgl.FullscreenControl());

</script>
1 change: 1 addition & 0 deletions documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ toc:
- GeolocateControl
- AttributionControl
- ScaleControl
- FullscreenControl
- name: Handlers
description: |
Handlers add different kinds of interactivity to the map -
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mapboxgl.NavigationControl = require('./ui/control/navigation_control');
mapboxgl.GeolocateControl = require('./ui/control/geolocate_control');
mapboxgl.AttributionControl = require('./ui/control/attribution_control');
mapboxgl.ScaleControl = require('./ui/control/scale_control');
mapboxgl.FullscreenControl = require('./ui/control/fullscreen_control');
mapboxgl.Popup = require('./ui/popup');
mapboxgl.Marker = require('./ui/marker');

Expand Down
88 changes: 88 additions & 0 deletions src/ui/control/fullscreen_control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use strict';

const DOM = require('../../util/dom');
const util = require('../../util/util');
const window = require('../../util/window');

/**
* A `FullscreenControl` control contains a button for toggling the map in and out of fullscreen mode.
*
* @implements {IControl}
* @example
* map.addControl(new mapboxgl.FullscreenControl());
* @see [View a fullscreen map](https://www.mapbox.com/mapbox-gl-js/example/fullscreen/)
*/

class FullscreenControl {

constructor() {
this._fullscreen = false;
util.bindAll([
'_onClickFullscreen',
'_changeIcon'
], this);
if ('onfullscreenchange' in document) {
this._fullscreenchange = 'fullscreenchange';
} else if ('onmozfullscreenchange' in document) {
this._fullscreenchange = 'mozfullscreenchange';
} else if ('onwebkitfullscreenchange' in document) {
this._fullscreenchange = 'webkitfullscreenchange';
} else if ('onmsfullscreenchange' in document) {
this._fullscreenchange = 'MSFullscreenChange';
}
}

onAdd(map) {
const className = 'mapboxgl-ctrl';
const container = this._container = DOM.create('div', `${className} mapboxgl-ctrl-group`);
const button = this._fullscreenButton = DOM.create('button', (`${className}-icon ${className}-fullscreen`), this._container);
button.setAttribute("aria-label", "Toggle fullscreen");
this._fullscreenButton.addEventListener('click', this._onClickFullscreen);
this._mapContainer = map.getContainer();
window.document.addEventListener(this._fullscreenchange, this._changeIcon);
return container;
}

onRemove() {
this._container.parentNode.removeChild(this._container);
this._map = null;
window.document.removeEventListener(this._fullscreenchange, this._changeIcon);
}

_isFullscreen() {
return this._fullscreen;
}

_changeIcon(e) {
if (e.target === this._mapContainer) {
this._fullscreen = !this._fullscreen;
const className = 'mapboxgl-ctrl';
this._fullscreenButton.classList.toggle(`${className}-shrink`);
this._fullscreenButton.classList.toggle(`${className}-fullscreen`);
}
}

_onClickFullscreen() {
if (this._isFullscreen()) {
if (window.document.exitFullscreen) {
window.document.exitFullscreen();
} else if (window.document.mozCancelFullScreen) {
window.document.mozCancelFullScreen();
} else if (window.document.msExitFullscreen) {
window.document.msExitFullscreen();
} else if (window.document.webkitCancelFullScreen) {
window.document.webkitCancelFullScreen();
}
} else if (this._mapContainer.requestFullscreen) {
this._mapContainer.requestFullscreen();
} else if (this._mapContainer.mozRequestFullScreen) {
this._mapContainer.mozRequestFullScreen();
} else if (this._mapContainer.msRequestFullscreen) {
this._mapContainer.msRequestFullscreen();
} else if (this._mapContainer.webkitRequestFullscreen) {
this._mapContainer.webkitRequestFullscreen();
}
}
}

module.exports = FullscreenControl;

0 comments on commit 78fc9c4

Please sign in to comment.