Skip to content

Commit

Permalink
Finish fully reverting #5155
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Oct 11, 2017
1 parent 13a4749 commit 6fbc1b4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
24 changes: 23 additions & 1 deletion src/source/canvas_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,34 @@ class CanvasSource extends ImageSource {
this.pause();
}

/**
* Sets the canvas's coordinates and re-renders the map.
*
* @method setCoordinates
* @param {Array<Array<number>>} coordinates Four geographical coordinates,
* represented as arrays of longitude and latitude numbers, which define the corners of the canvas.
* The coordinates start at the top left corner of the canvas and proceed in clockwise order.
* They do not have to represent a rectangle.
* @returns {CanvasSource} this
*/
// setCoordinates inherited from ImageSource

prepare() {
let resize = false;
if (this.canvas.width !== this.width) {
this.width = this.canvas.width;
resize = true;
}
if (this.canvas.height !== this.height) {
this.height = this.canvas.height;
resize = true;
}

if (this._hasInvalidDimensions()) return;

if (Object.keys(this.tiles).length === 0) return; // not enough data for current position

this._prepareImage(this.map.painter.gl, this.canvas, true);
this._prepareImage(this.map.painter.gl, this.canvas, resize);
}

serialize(): Object {
Expand Down
2 changes: 1 addition & 1 deletion src/source/image_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class ImageSource extends Evented implements Source {
this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
} else if (resize) {
this.texture.update(image);
} else if (image instanceof window.HTMLVideoElement || image instanceof window.ImageData) {
} else if (image instanceof window.HTMLVideoElement || image instanceof window.ImageData || image instanceof window.HTMLCanvasElement) {
this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
Expand Down
19 changes: 0 additions & 19 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,25 +302,6 @@
"type": "string",
"required": true,
"doc": "HTML ID of the canvas from which to read pixels."
},
"contextType": {
"required": true,
"type": "enum",
"values": {
"2d": {
"doc" : "Source canvas is associated with a `2d` drawing context."
},
"webgl": {
"doc": "Source canvas is associated with a `webgl` drawing context."
},
"experimental-webgl": {
"doc": "Source canvas is associated with an `experimental-webgl` drawing context."
},
"webgl2": {
"doc": "Source canvas is associated with a `webgl2` drawing context."
}
},
"doc": "The context identifier defining the drawing context associated to the source canvas (see HTMLCanvasElement.getContext() documentation)."
}
},
"layer": {
Expand Down

0 comments on commit 6fbc1b4

Please sign in to comment.