Merge pull request #1522 from twpayne/vector-api-clean-ups

[vector-api] Miscellaneous clean-ups
This commit is contained in:
Tom Payne
2014-01-14 03:26:29 -08:00
3 changed files with 132 additions and 141 deletions

View File

@@ -185,110 +185,122 @@ ol.render.canvas.Replay.prototype.replay_ =
var instruction = instructions[i];
var type = /** @type {ol.render.canvas.Instruction} */ (instruction[0]);
var geometry;
if (type == ol.render.canvas.Instruction.BEGIN_GEOMETRY) {
geometry = /** @type {ol.geom.Geometry} */ (instruction[1]);
if (renderGeometryFunction(geometry)) {
++i;
} else {
i = /** @type {number} */ (instruction[2]);
}
} else if (type == ol.render.canvas.Instruction.BEGIN_PATH) {
context.beginPath();
++i;
} else if (type == ol.render.canvas.Instruction.CLOSE_PATH) {
context.closePath();
++i;
} else if (type == ol.render.canvas.Instruction.DRAW_IMAGE) {
goog.asserts.assert(goog.isNumber(instruction[1]));
d = /** @type {number} */ (instruction[1]);
goog.asserts.assert(goog.isNumber(instruction[2]));
dd = /** @type {number} */ (instruction[2]);
var image = /** @type {HTMLCanvasElement|HTMLVideoElement|Image} */
(instruction[3]);
// Remaining arguments in DRAW_IMAGE are in alphabetical order
var anchorX = /** @type {number} */ (instruction[4]) * pixelRatio;
var anchorY = /** @type {number} */ (instruction[5]) * pixelRatio;
var height = /** @type {number} */ (instruction[6]) * pixelRatio;
var rotation = /** @type {number} */ (instruction[7]);
var scale = /** @type {number} */ (instruction[8]);
var snapToPixel = /** @type {boolean|undefined} */ (instruction[9]);
var width = /** @type {number} */ (instruction[10]) * pixelRatio;
for (; d < dd; d += 2) {
var x = pixelCoordinates[d] - anchorX;
var y = pixelCoordinates[d + 1] - anchorY;
if (snapToPixel) {
x = (x + 0.5) | 0;
y = (y + 0.5) | 0;
}
if (scale != 1 || rotation !== 0) {
var centerX = x + anchorX;
var centerY = y + anchorY;
ol.vec.Mat4.makeTransform2D(
localTransform, centerX, centerY, scale, scale,
rotation, -centerX, -centerY);
context.setTransform(
goog.vec.Mat4.getElement(localTransform, 0, 0),
goog.vec.Mat4.getElement(localTransform, 1, 0),
goog.vec.Mat4.getElement(localTransform, 0, 1),
goog.vec.Mat4.getElement(localTransform, 1, 1),
goog.vec.Mat4.getElement(localTransform, 0, 3),
goog.vec.Mat4.getElement(localTransform, 1, 3));
}
context.drawImage(image, x, y, width, height);
if (scale != 1 || rotation !== 0) {
context.setTransform(1, 0, 0, 1, 0, 0);
}
}
++i;
} else if (type == ol.render.canvas.Instruction.END_GEOMETRY) {
if (goog.isDef(geometryCallback)) {
switch (type) {
case ol.render.canvas.Instruction.BEGIN_GEOMETRY:
geometry = /** @type {ol.geom.Geometry} */ (instruction[1]);
var data = /** @type {Object} */ (instruction[2]);
var result = geometryCallback(geometry, data);
if (result) {
return result;
if (renderGeometryFunction(geometry)) {
++i;
} else {
i = /** @type {number} */ (instruction[2]);
}
}
++i;
} else if (type == ol.render.canvas.Instruction.FILL) {
context.fill();
++i;
} else if (type == ol.render.canvas.Instruction.MOVE_TO_LINE_TO) {
goog.asserts.assert(goog.isNumber(instruction[1]));
d = /** @type {number} */ (instruction[1]);
goog.asserts.assert(goog.isNumber(instruction[2]));
dd = /** @type {number} */ (instruction[2]);
context.moveTo(pixelCoordinates[d], pixelCoordinates[d + 1]);
for (d += 2; d < dd; d += 2) {
context.lineTo(pixelCoordinates[d], pixelCoordinates[d + 1]);
}
++i;
} else if (type == ol.render.canvas.Instruction.SET_FILL_STYLE) {
goog.asserts.assert(goog.isString(instruction[1]));
context.fillStyle = /** @type {string} */ (instruction[1]);
++i;
} else if (type == ol.render.canvas.Instruction.SET_STROKE_STYLE) {
goog.asserts.assert(goog.isString(instruction[1]));
goog.asserts.assert(goog.isNumber(instruction[2]));
goog.asserts.assert(goog.isString(instruction[3]));
goog.asserts.assert(goog.isString(instruction[4]));
goog.asserts.assert(goog.isNumber(instruction[5]));
goog.asserts.assert(!goog.isNull(instruction[6]));
context.strokeStyle = /** @type {string} */ (instruction[1]);
context.lineWidth = /** @type {number} */ (instruction[2]) * pixelRatio;
context.lineCap = /** @type {string} */ (instruction[3]);
context.lineJoin = /** @type {string} */ (instruction[4]);
context.miterLimit = /** @type {number} */ (instruction[5]);
if (goog.isDef(context.setLineDash)) {
context.setLineDash(/** @type {Array.<number>} */ (instruction[6]));
}
++i;
} else if (type == ol.render.canvas.Instruction.STROKE) {
context.stroke();
++i;
} else {
goog.asserts.fail();
++i; // consume the instruction anyway, to avoid an infinite loop
break;
case ol.render.canvas.Instruction.BEGIN_PATH:
context.beginPath();
++i;
break;
case ol.render.canvas.Instruction.CLOSE_PATH:
context.closePath();
++i;
break;
case ol.render.canvas.Instruction.DRAW_IMAGE:
goog.asserts.assert(goog.isNumber(instruction[1]));
d = /** @type {number} */ (instruction[1]);
goog.asserts.assert(goog.isNumber(instruction[2]));
dd = /** @type {number} */ (instruction[2]);
var image = /** @type {HTMLCanvasElement|HTMLVideoElement|Image} */
(instruction[3]);
// Remaining arguments in DRAW_IMAGE are in alphabetical order
var anchorX = /** @type {number} */ (instruction[4]) * pixelRatio;
var anchorY = /** @type {number} */ (instruction[5]) * pixelRatio;
var height = /** @type {number} */ (instruction[6]) * pixelRatio;
var rotation = /** @type {number} */ (instruction[7]);
var scale = /** @type {number} */ (instruction[8]);
var snapToPixel = /** @type {boolean|undefined} */ (instruction[9]);
var width = /** @type {number} */ (instruction[10]) * pixelRatio;
for (; d < dd; d += 2) {
var x = pixelCoordinates[d] - anchorX;
var y = pixelCoordinates[d + 1] - anchorY;
if (snapToPixel) {
x = (x + 0.5) | 0;
y = (y + 0.5) | 0;
}
if (scale != 1 || rotation !== 0) {
var centerX = x + anchorX;
var centerY = y + anchorY;
ol.vec.Mat4.makeTransform2D(
localTransform, centerX, centerY, scale, scale,
rotation, -centerX, -centerY);
context.setTransform(
goog.vec.Mat4.getElement(localTransform, 0, 0),
goog.vec.Mat4.getElement(localTransform, 1, 0),
goog.vec.Mat4.getElement(localTransform, 0, 1),
goog.vec.Mat4.getElement(localTransform, 1, 1),
goog.vec.Mat4.getElement(localTransform, 0, 3),
goog.vec.Mat4.getElement(localTransform, 1, 3));
}
context.drawImage(image, x, y, width, height);
if (scale != 1 || rotation !== 0) {
context.setTransform(1, 0, 0, 1, 0, 0);
}
}
++i;
break;
case ol.render.canvas.Instruction.END_GEOMETRY:
if (goog.isDef(geometryCallback)) {
geometry = /** @type {ol.geom.Geometry} */ (instruction[1]);
var data = /** @type {Object} */ (instruction[2]);
var result = geometryCallback(geometry, data);
if (result) {
return result;
}
}
++i;
break;
case ol.render.canvas.Instruction.FILL:
context.fill();
++i;
break;
case ol.render.canvas.Instruction.MOVE_TO_LINE_TO:
goog.asserts.assert(goog.isNumber(instruction[1]));
d = /** @type {number} */ (instruction[1]);
goog.asserts.assert(goog.isNumber(instruction[2]));
dd = /** @type {number} */ (instruction[2]);
context.moveTo(pixelCoordinates[d], pixelCoordinates[d + 1]);
for (d += 2; d < dd; d += 2) {
context.lineTo(pixelCoordinates[d], pixelCoordinates[d + 1]);
}
++i;
break;
case ol.render.canvas.Instruction.SET_FILL_STYLE:
goog.asserts.assert(goog.isString(instruction[1]));
context.fillStyle = /** @type {string} */ (instruction[1]);
++i;
break;
case ol.render.canvas.Instruction.SET_STROKE_STYLE:
goog.asserts.assert(goog.isString(instruction[1]));
goog.asserts.assert(goog.isNumber(instruction[2]));
goog.asserts.assert(goog.isString(instruction[3]));
goog.asserts.assert(goog.isString(instruction[4]));
goog.asserts.assert(goog.isNumber(instruction[5]));
goog.asserts.assert(!goog.isNull(instruction[6]));
context.strokeStyle = /** @type {string} */ (instruction[1]);
context.lineWidth = /** @type {number} */ (instruction[2]) * pixelRatio;
context.lineCap = /** @type {string} */ (instruction[3]);
context.lineJoin = /** @type {string} */ (instruction[4]);
context.miterLimit = /** @type {number} */ (instruction[5]);
if (goog.isDef(context.setLineDash)) {
context.setLineDash(/** @type {Array.<number>} */ (instruction[6]));
}
++i;
break;
case ol.render.canvas.Instruction.STROKE:
context.stroke();
++i;
break;
default:
goog.asserts.fail();
++i; // consume the instruction anyway, to avoid an infinite loop
break;
}
}
// assert that all instructions were consumed

View File

@@ -43,9 +43,7 @@ ol.renderer.vector.renderFeature = function(
ol.renderer.vector.renderGeometryCollectionGeometry_ =
function(replayGroup, geometry, style, data) {
goog.asserts.assertInstanceof(geometry, ol.geom.GeometryCollection);
var geometryCollectionGeometry = /** @type {ol.geom.GeometryCollection} */ (
geometry);
var geometries = geometryCollectionGeometry.getGeometriesArray();
var geometries = geometry.getGeometriesArray();
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
var geometryRenderer =
@@ -70,11 +68,10 @@ ol.renderer.vector.renderLineStringGeometry_ =
return;
}
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
var lineStringGeometry = /** @type {ol.geom.LineString} */ (geometry);
var replay = replayGroup.getReplay(
style.getZIndex(), ol.render.ReplayType.LINE_STRING);
replay.setFillStrokeStyle(null, strokeStyle);
replay.drawLineStringGeometry(lineStringGeometry, data);
replay.drawLineStringGeometry(geometry, data);
};
@@ -92,12 +89,10 @@ ol.renderer.vector.renderMultiLineStringGeometry_ =
return;
}
goog.asserts.assertInstanceof(geometry, ol.geom.MultiLineString);
var multiLineStringGeometry = /** @type {ol.geom.MultiLineString} */
(geometry);
var replay = replayGroup.getReplay(
style.getZIndex(), ol.render.ReplayType.LINE_STRING);
replay.setFillStrokeStyle(null, strokeStyle);
replay.drawMultiLineStringGeometry(multiLineStringGeometry, data);
replay.drawMultiLineStringGeometry(geometry, data);
};
@@ -116,12 +111,10 @@ ol.renderer.vector.renderMultiPolygonGeometry_ =
return;
}
goog.asserts.assertInstanceof(geometry, ol.geom.MultiPolygon);
var multiPolygonGeometry = /** @type {ol.geom.MultiPolygon} */
(geometry);
var replay = replayGroup.getReplay(
style.getZIndex(), ol.render.ReplayType.POLYGON);
replay.setFillStrokeStyle(fillStyle, strokeStyle);
replay.drawMultiPolygonGeometry(multiPolygonGeometry, data);
replay.drawMultiPolygonGeometry(geometry, data);
};
@@ -139,11 +132,10 @@ ol.renderer.vector.renderPointGeometry_ =
return;
}
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
var pointGeometry = /** @type {ol.geom.Point} */ (geometry);
var replay = replayGroup.getReplay(
style.getZIndex(), ol.render.ReplayType.IMAGE);
replay.setImageStyle(imageStyle);
replay.drawPointGeometry(pointGeometry, data);
replay.drawPointGeometry(geometry, data);
};
@@ -161,11 +153,10 @@ ol.renderer.vector.renderMultiPointGeometry_ =
return;
}
goog.asserts.assertInstanceof(geometry, ol.geom.MultiPoint);
var multiPointGeometry = /** @type {ol.geom.MultiPoint} */ (geometry);
var replay = replayGroup.getReplay(
style.getZIndex(), ol.render.ReplayType.IMAGE);
replay.setImageStyle(imageStyle);
replay.drawMultiPointGeometry(multiPointGeometry, data);
replay.drawMultiPointGeometry(geometry, data);
};
@@ -184,11 +175,10 @@ ol.renderer.vector.renderPolygonGeometry_ =
return;
}
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon);
var polygonGeometry = /** @type {ol.geom.Polygon} */ (geometry);
var replay = replayGroup.getReplay(
style.getZIndex(), ol.render.ReplayType.POLYGON);
replay.setFillStrokeStyle(fillStyle, strokeStyle);
replay.drawPolygonGeometry(polygonGeometry, data);
replay.drawPolygonGeometry(geometry, data);
};

View File

@@ -21,17 +21,14 @@ ol.render.webgl.Immediate.prototype.drawAsync = function(zIndex, callback) {
/**
* @param {ol.Feature} feature Feature.
* @param {ol.style.Style} style Style.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.drawFeature = function(feature, style) {
};
/**
* @param {ol.geom.GeometryCollection} geometryCollectionGeometry Geometry
* collection.
* @param {Object} data Opaque data object.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.drawGeometryCollectionGeometry =
function(geometryCollectionGeometry, data) {
@@ -39,8 +36,7 @@ ol.render.webgl.Immediate.prototype.drawGeometryCollectionGeometry =
/**
* @param {ol.geom.Point} pointGeometry Point geometry.
* @param {Object} data Opaque data object.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.drawPointGeometry =
function(pointGeometry, data) {
@@ -48,8 +44,7 @@ ol.render.webgl.Immediate.prototype.drawPointGeometry =
/**
* @param {ol.geom.LineString} lineStringGeometry Line string geometry.
* @param {Object} data Opaque data object.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.drawLineStringGeometry =
function(lineStringGeometry, data) {
@@ -57,9 +52,7 @@ ol.render.webgl.Immediate.prototype.drawLineStringGeometry =
/**
* @param {ol.geom.MultiLineString} multiLineStringGeometry
* MultiLineString geometry.
* @param {Object} data Opaque data object.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.drawMultiLineStringGeometry =
function(multiLineStringGeometry, data) {
@@ -67,8 +60,7 @@ ol.render.webgl.Immediate.prototype.drawMultiLineStringGeometry =
/**
* @param {ol.geom.MultiPoint} multiPointGeometry MultiPoint geometry.
* @param {Object} data Opaque data object.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.drawMultiPointGeometry =
function(multiPointGeometry, data) {
@@ -76,8 +68,7 @@ ol.render.webgl.Immediate.prototype.drawMultiPointGeometry =
/**
* @param {ol.geom.MultiPolygon} multiPolygonGeometry MultiPolygon geometry.
* @param {Object} data Opaque data object.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.drawMultiPolygonGeometry =
function(multiPolygonGeometry, data) {
@@ -85,8 +76,7 @@ ol.render.webgl.Immediate.prototype.drawMultiPolygonGeometry =
/**
* @param {ol.geom.Polygon} polygonGeometry Polygon geometry.
* @param {Object} data Opaque data object.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.drawPolygonGeometry =
function(polygonGeometry, data) {
@@ -94,8 +84,7 @@ ol.render.webgl.Immediate.prototype.drawPolygonGeometry =
/**
* @param {ol.style.Fill} fillStyle Fill style.
* @param {ol.style.Stroke} strokeStyle Stroke style.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.setFillStrokeStyle =
function(fillStyle, strokeStyle) {
@@ -103,14 +92,14 @@ ol.render.webgl.Immediate.prototype.setFillStrokeStyle =
/**
* @param {ol.style.Image} imageStyle Image style.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.setImageStyle = function(imageStyle) {
};
/**
* @param {ol.style.Text} textStyle Text style.
* @inheritDoc
*/
ol.render.webgl.Immediate.prototype.setTextStyle = function(textStyle) {
};