-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[not ready] create fullscreen example and control #3977
Merged
+119
−1
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
31c4468
create fullscreen example and control
colleenmcginnis 610970c
add fullscreen control
colleenmcginnis 4205505
toggle fullscreen
colleenmcginnis f242685
clean up code
colleenmcginnis 367662f
set height and width
colleenmcginnis 6fefdbe
change icon on esc
colleenmcginnis 2e79e81
add fullscreen to debug
colleenmcginnis b205de0
address merp comments
colleenmcginnis 36c17db
remove _onKeyDown and _isFullscreen
colleenmcginnis b64e67d
address johns comments
colleenmcginnis 945b047
move file to src folder and add case for IE11
colleenmcginnis 8d785fc
add newline to debug page
colleenmcginnis 1b0fecc
add second argument
colleenmcginnis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
_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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A second argument is needed here --
removeEventListener(this._fullscreenchange, this._changeIcon)
.