Skip to content
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
merged 13 commits into from
Feb 25, 2017
Merged

Conversation

colleenmcginnis
Copy link
Contributor

@colleenmcginnis colleenmcginnis commented Jan 14, 2017

Creates a fullscreen control and an example using the fullscreen control to address #1824.

Hoping @mollymerp and @lucaswoj can help with some things that still need to be resolved:

  • Do the control and the example need to be in two different PRs (master and mb-pages)?
  • The current control works in example, but not in the debug page. @mollymerp looked at this earlier - do you remember what the issue was?
  • In addition to changing the icon when the button is clicked, it also needs to change when the ESC key is pressed. Not sure what the best way is to do that as a part of the control.
  • There are several errors in the js/ui/control/fullscreen.js file that I'm not sure how to interpret or resolve.

@mollymerp
Copy link
Contributor

awesome work @colleenmcginnis !!

  • no need to separate the master and mb-pages PRs bc we wouldn't want the example to show up before the control is released. master is merged into mb-pages on every release
  • I do remember the thing with the debug page. I'll take a look into it on Monday
  • I think you'll need to add a case in https://github.com/mapbox/mapbox-gl-js/blob/master/js/ui/handler/keyboard.js to handle the esc key functionality
  • I'll go through and see if I can help w the errors you're seeing.

var container = this._container = DOM.create('div', className + '-group', map.getContainer());
var button = this._fullscreenButton = DOM.create('button', (className + '-icon ' + className + '-fullscreen'), this._container);
button.id = 'fullscreen-button';
this._fullscreenButton.type = 'button';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colleenmcginnis Could you include an aria-label attribute on the button with value of say "Fullscreen" for accessibility?

Similar to how it's done for the navigation buttons https://github.com/mapbox/mapbox-gl-js/blob/master/js/ui/control/navigation_control.js#L95

util.setOptions(this, options);
}

Fullscreen.prototype = util.inherit(Control, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We deprecated the Control class, and now controls don't need to inherit from anything, but they do need to follow the implementation of IControl (i.e. need onAdd, onRemove functions. You can also add a getDefaultPosition function to replace the options object passed to the Control).

if (window.innerHeight === screen.height) {
button.classList.remove(className + '-shrink');
button.classList.add(className + '-fullscreen');
if (document.exitFullscreen) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may need to require the window util and use window.document.exitFullscreen etc to get past the linting errors.

@@ -267,3 +274,11 @@
display:none;
}
}
.pseudo-fullscreen {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used (and we shouldn't need to support "pseudo-fullscreen" mode, as all browsers supported by gl-js should support the HTML5 fullscreen API).


_onClickFullscreen: function() {
var mapContainer = map.getContainer();
var button = document.getElementById('fullscreen-button');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this._fullscreenButton rather than looking up the element by ID.

var className = 'mapboxgl-ctrl';
var container = this._container = DOM.create('div', className + '-group', map.getContainer());
var button = this._fullscreenButton = DOM.create('button', (className + '-icon ' + className + '-fullscreen'), this._container);
button.id = 'fullscreen-button';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid assigning an ID -- IDs are required to be unique, and there may be more than one map with fullscreen control on a page.

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @colleenmcginnis -- just a couple small changes. In order to add the documentation you write to the website, you'll also need to add it in the documentation.yml file with the other controls.

debug/index.html Outdated
map.addControl(new mapboxgl.NavigationControl());
map.addControl(new mapboxgl.GeolocateControl());
map.addControl(new mapboxgl.ScaleControl());
map.addControl(new mapboxgl.FullscreenControl());
Copy link
Contributor

@mollymerp mollymerp Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you revert the changes on this file so it matches the debug/index.html file on master? you can add a new debug page for controls instead if you want to.

@@ -85,7 +85,14 @@
.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 {
padding: 5px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the padding here because its included here

background-image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxOS4wLjEsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4KCjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIg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E4OCA3LjMwNDY4NzUgNS43NzE0ODQ0IEwgOSA0LjUgTCA5IDQgTCA2IDQgTCA1IDQgeiAiCiAgICAgaWQ9InBhdGg0MTY5IiAvPjwvc3ZnPg==");
}
.mapboxgl-ctrl-icon.mapboxgl-ctrl-shrink {
padding: 5px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as L89

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

class FullscreenControl {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add documentation markup here? here is an example from the NavigationControl

/**
 * A `NavigationControl` control contains zoom buttons and a compass.
 *
 * @implements {IControl}
 * @example
 * var nav = new mapboxgl.NavigationControl();
 * map.addControl(nav, 'top-left');
 * @see [Display map navigation controls](https://www.mapbox.com/mapbox-gl-js/example/navigation/)
 * @see [Add a third party vector tile source](https://www.mapbox.com/mapbox-gl-js/example/third-party/)
 */

package.json Outdated
@@ -117,7 +117,7 @@
"build-docs": "documentation build --github --format html --config documentation.yml --theme ./docs/_theme --output docs/api/",
"build": "npm run build-docs # invoked by publisher when publishing docs on the mb-pages branch",
"start-docs": "npm run build-min && npm run build-docs && jekyll serve --watch",
"lint": "eslint --ignore-path .gitignore js test bench docs/_posts/examples/*.html debug/*.html",
"lint": "eslint --fix --ignore-path .gitignore js test bench docs/_posts/examples/*.html debug/*.html",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this as well 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently learned that you can do this with npm:

npm run lint -- --fix

.. and it'll pass the --fix flag down to the eslint command 😄

util.bindAll([
'_isFullscreen',
'_onClickFullscreen',
'_onKeyDown',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of _onKeyDown here -- I think you deleted that function from a previous iteration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I don't think you need to bind _isFullscreen bc its not used as an event listener.

button.setAttribute("aria-label", "Toggle fullscreen");
this._fullscreenButton.addEventListener('click', this._onClickFullscreen);
this._mapContainer = map.getContainer();
window.document.addEventListener('webkitfullscreenchange', this._changeIcon);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webkitfullscreenchange is specific to WebKit -- you'll need to do feature detection to determine the appropriate event name for other browsers. Here's how the Leaflet equivalent does it.

}

onRemove() {
this._container.parentNode.removeChild(this._container);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onRemove should unbind the fullscreenchange event handler, using window.document.removeEventListener.

return this._fullscreen;
}

_changeIcon() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_changeIcon, as the event handler bound to fullscreenchange event, needs to check if the event corresponds to the appropriate page element. There might be more than one map on the page, or other elements that go fullscreen. Here's the equivalent code in the Leaflet plugin.

}

_onClickFullscreen() {
if (this._isFullscreen()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be a case in this function for IE11 (msRequestFullscreen / msExitFullscreen).

@colleenmcginnis
Copy link
Contributor Author

@jfirebaugh - @mollymerp and I worked on addressing your comments the other day. Can you take another look when you get the chance? Thanks!

Copy link
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just one last thing I noticed.

onRemove() {
this._container.parentNode.removeChild(this._container);
this._map = null;
window.document.removeEventListener(this._fullscreenchange);
Copy link
Contributor

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).

@colleenmcginnis colleenmcginnis merged commit 78fc9c4 into master Feb 25, 2017
@colleenmcginnis colleenmcginnis deleted the ex-fullscreen branch February 25, 2017 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants