Skip to content

Commit

Permalink
Support external GL context (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored Sep 26, 2018
1 parent c670f09 commit 7f0909f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/components/static-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ An object that specifies bounds for viewport props with `min*`, `max*` keys. If

Default: `{ minZoom: 0, maxZoom: 20, minPitch: 0, maxPitch: 60 }`

##### `gl` {WebGLContext} ==EXPERIMENTAL==

Use an existing WebGLContext instead of creating a new one. This allows multiple libraries to render into a shared buffer. Use with caution.


## Callbacks

Expand Down
13 changes: 12 additions & 1 deletion src/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

/* global window, document, process */
/* global window, document, process, HTMLCanvasElement */
import PropTypes from 'prop-types';

function noop() {}
Expand Down Expand Up @@ -182,6 +182,17 @@ export default class Mapbox {
// TODO - need to call onload again, need to track with Promise?
props.onLoad();
} else {
if (props.gl) {
const getContext = HTMLCanvasElement.prototype.getContext;
// Hijack canvas.getContext to return our own WebGLContext
// This will be called inside the mapboxgl.Map constructor
HTMLCanvasElement.prototype.getContext = () => {
// Unhijack immediately
HTMLCanvasElement.prototype.getContext = getContext;
return props.gl;
};
}

const mapOptions = {
container: props.container || document.body,
center: [0, 0],
Expand Down

0 comments on commit 7f0909f

Please sign in to comment.