Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucas Wojciechowski
committed
Sep 2, 2016
1 parent
c24473f
commit fdd3aeb
Showing
4 changed files
with
50 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,30 +1,43 @@ | ||
'use strict'; | ||
|
||
var gl = require('gl'); | ||
var util = require('./util'); | ||
var isSupported = require('mapbox-gl-supported'); | ||
var window = require('./window'); | ||
|
||
module.exports = Canvas; | ||
|
||
function Canvas(map) { | ||
var requiredContextAttributes = { | ||
antialias: false, | ||
alpha: true, | ||
stencil: true, | ||
depth: true, | ||
preserveDrawingBuffer: true | ||
}; | ||
|
||
this.context = gl( | ||
map.getContainer().offsetWidth * window.devicePixelRatio, | ||
map.getContainer().offsetHeight * window.devicePixelRatio, | ||
requiredContextAttributes | ||
); | ||
function Canvas(map, container) { | ||
this.canvas = window.document.createElement('canvas'); | ||
|
||
if (map && container) { | ||
this.canvas.style.position = 'absolute'; | ||
this.canvas.classList.add('mapboxgl-canvas'); | ||
this.canvas.addEventListener('webglcontextlost', map._contextLost.bind(map), false); | ||
this.canvas.addEventListener('webglcontextrestored', map._contextRestored.bind(map), false); | ||
this.canvas.setAttribute('tabindex', 0); | ||
container.appendChild(this.canvas); | ||
} | ||
} | ||
|
||
Canvas.prototype.resize = function() {}; | ||
Canvas.prototype.resize = function(width, height) { | ||
var pixelRatio = window.devicePixelRatio || 1; | ||
|
||
// Request the required canvas size taking the pixelratio into account. | ||
this.canvas.width = pixelRatio * width; | ||
this.canvas.height = pixelRatio * height; | ||
|
||
// Maintain the same canvas size, potentially downscaling it for HiDPI displays | ||
this.canvas.style.width = width + 'px'; | ||
this.canvas.style.height = height + 'px'; | ||
}; | ||
|
||
Canvas.prototype.getWebGLContext = function(attributes) { | ||
attributes = util.extend({}, attributes, isSupported.webGLContextAttributes); | ||
|
||
Canvas.prototype.getWebGLContext = function() { | ||
return this.context; | ||
return this.canvas.getContext('webgl', attributes) || | ||
this.canvas.getContext('experimental-webgl', attributes); | ||
}; | ||
|
||
Canvas.prototype.getElement = function() {}; | ||
Canvas.prototype.getElement = function() { | ||
return this.canvas; | ||
}; |
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