Move ol.replay into ol.render namespace

This commit is contained in:
Tom Payne
2013-11-10 12:15:09 +01:00
parent 65fffd9b1c
commit 4183d9cdb8
5 changed files with 121 additions and 120 deletions

View File

@@ -0,0 +1,630 @@
goog.provide('ol.render.canvas.BatchGroup');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.object');
goog.require('ol.extent');
goog.require('ol.render');
goog.require('ol.render.IReplayBatch');
goog.require('ol.render.IReplayBatchGroup');
goog.require('ol.style.fill');
goog.require('ol.style.stroke');
/**
* @enum {number}
*/
ol.render.canvas.Instruction = {
BEGIN_PATH: 0,
CLOSE_PATH: 1,
DRAW_IMAGE: 2,
FILL: 3,
MOVE_TO_LINE_TO: 4,
SET_FILL_STYLE: 5,
SET_STROKE_STYLE: 6,
STROKE: 7
};
/**
* @constructor
* @implements {ol.render.IReplayBatch}
* @protected
*/
ol.render.canvas.Batch = function() {
/**
* @protected
* @type {Array}
*/
this.instructions = [];
/**
* @protected
* @type {Array.<number>}
*/
this.coordinates = [];
/**
* @private
* @type {Array.<number>}
*/
this.pixelCoordinates_ = [];
/**
* @private
* @type {ol.Extent}
*/
this.extent_ = ol.extent.createEmpty();
};
/**
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset.
* @param {number} end End.
* @param {number} stride Stride.
* @param {boolean} close Close.
* @protected
* @return {number} My end.
*/
ol.render.canvas.Batch.prototype.appendFlatCoordinates =
function(flatCoordinates, offset, end, stride, close) {
var myEnd = this.coordinates.length;
var i;
for (i = offset; i < end; i += stride) {
this.coordinates[myEnd++] = flatCoordinates[i];
this.coordinates[myEnd++] = flatCoordinates[i + 1];
}
if (close) {
this.coordinates[myEnd++] = flatCoordinates[offset];
this.coordinates[myEnd++] = flatCoordinates[offset + 1];
}
return myEnd;
};
/**
* @param {CanvasRenderingContext2D} context Context.
* @param {goog.vec.Mat4.AnyType} transform Transform.
*/
ol.render.canvas.Batch.prototype.draw = function(context, transform) {
var pixelCoordinates = ol.render.transformCoordinates(
this.coordinates, transform, this.pixelCoordinates_);
this.pixelCoordinates_ = pixelCoordinates; // FIXME ?
var instructions = this.instructions;
var i = 0;
var end, j, jj;
for (j = 0, jj = instructions.length; j < jj; ++j) {
var instruction = instructions[j];
var type = /** @type {ol.render.canvas.Instruction} */ (instruction[0]);
if (type == ol.render.canvas.Instruction.BEGIN_PATH) {
context.beginPath();
} else if (type == ol.render.canvas.Instruction.CLOSE_PATH) {
context.closePath();
} else if (type == ol.render.canvas.Instruction.DRAW_IMAGE) {
end = /** @type {number} */ (instruction[1]);
var imageStyle = /** @type {ol.style.Image} */ (instruction[2]);
for (; i < end; i += 2) {
context.drawImage(
imageStyle.image,
pixelCoordinates[i] - imageStyle.anchor[0],
pixelCoordinates[i + 1] - imageStyle.anchor[1]);
}
} else if (type == ol.render.canvas.Instruction.FILL) {
context.fill();
} else if (type == ol.render.canvas.Instruction.MOVE_TO_LINE_TO) {
context.moveTo(pixelCoordinates[i], pixelCoordinates[i + 1]);
goog.asserts.assert(goog.isNumber(instruction[1]));
end = /** @type {number} */ (instruction[1]);
for (i += 2; i < end; i += 2) {
context.lineTo(pixelCoordinates[i], pixelCoordinates[i + 1]);
}
} else if (type == ol.render.canvas.Instruction.SET_FILL_STYLE) {
goog.asserts.assert(goog.isObject(instruction[1]));
var fillStyle = /** @type {ol.style.Fill} */ (instruction[1]);
context.fillStyle = fillStyle.color;
} else if (type == ol.render.canvas.Instruction.SET_STROKE_STYLE) {
goog.asserts.assert(goog.isObject(instruction[1]));
var strokeStyle = /** @type {ol.style.Stroke} */ (instruction[1]);
context.strokeStyle = strokeStyle.color;
context.lineWidth = strokeStyle.width;
} else if (type == ol.render.canvas.Instruction.STROKE) {
context.stroke();
}
}
goog.asserts.assert(i == pixelCoordinates.length);
};
/**
* @inheritDoc
*/
ol.render.canvas.Batch.prototype.drawLineStringGeometry = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.render.canvas.Batch.prototype.drawMultiLineStringGeometry =
goog.abstractMethod;
/**
* @inheritDoc
*/
ol.render.canvas.Batch.prototype.drawPointGeometry = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.render.canvas.Batch.prototype.drawMultiPointGeometry = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.render.canvas.Batch.prototype.drawPolygonGeometry = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.render.canvas.Batch.prototype.drawMultiPolygonGeometry = goog.abstractMethod;
/**
* FIXME empty description for jsdoc
*/
ol.render.canvas.Batch.prototype.finish = goog.nullFunction;
/**
* @return {ol.Extent} Extent.
*/
ol.render.canvas.Batch.prototype.getExtent = function() {
return this.extent_;
};
/**
* @inheritDoc
*/
ol.render.canvas.Batch.prototype.setFillStrokeStyle = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.render.canvas.Batch.prototype.setImageStyle = goog.abstractMethod;
/**
* @constructor
* @extends {ol.render.canvas.Batch}
* @protected
*/
ol.render.canvas.ImageBatch = function() {
goog.base(this);
/**
* @private
* @type {?ol.style.Image}
*/
this.imageStyle_ = null;
};
goog.inherits(ol.render.canvas.ImageBatch, ol.render.canvas.Batch);
/**
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset.
* @param {number} end End.
* @param {number} stride Stride.
* @private
* @return {number} My end.
*/
ol.render.canvas.ImageBatch.prototype.drawCoordinates_ =
function(flatCoordinates, offset, end, stride) {
return this.appendFlatCoordinates(
flatCoordinates, offset, end, stride, false);
};
/**
* @inheritDoc
*/
ol.render.canvas.ImageBatch.prototype.drawPointGeometry =
function(pointGeometry) {
goog.asserts.assert(!goog.isNull(this.imageStyle_));
ol.extent.extend(this.extent_, pointGeometry.getExtent());
var flatCoordinates = pointGeometry.getFlatCoordinates();
var stride = pointGeometry.getStride();
var myEnd = this.drawCoordinates_(
flatCoordinates, 0, flatCoordinates.length, stride);
this.instructions.push(
[ol.render.canvas.Instruction.DRAW_IMAGE, myEnd, this.imageStyle_]);
};
/**
* @inheritDoc
*/
ol.render.canvas.ImageBatch.prototype.drawMultiPointGeometry =
function(multiPointGeometry) {
goog.asserts.assert(!goog.isNull(this.imageStyle_));
ol.extent.extend(this.extent_, multiPointGeometry.getExtent());
var flatCoordinates = multiPointGeometry.getFlatCoordinates();
var stride = multiPointGeometry.getStride();
var myEnd = this.drawCoordinates_(
flatCoordinates, 0, flatCoordinates.length, stride);
this.instructions.push(
[ol.render.canvas.Instruction.DRAW_IMAGE, myEnd, this.imageStyle_]);
};
/**
* @inheritDoc
*/
ol.render.canvas.ImageBatch.prototype.finish = function() {
// FIXME this doesn't really protect us against further calls to draw*Geometry
this.imageStyle_ = null;
};
/**
* @inheritDoc
*/
ol.render.canvas.ImageBatch.prototype.setImageStyle = function(imageStyle) {
this.imageStyle_ = imageStyle;
};
/**
* @constructor
* @extends {ol.render.canvas.Batch}
* @protected
*/
ol.render.canvas.LineStringBatch = function() {
goog.base(this);
/**
* @private
* @type {{currentStrokeStyle: ?ol.style.Stroke,
* lastDraw: number,
* strokeStyle: ?ol.style.Stroke}|null}
*/
this.state_ = {
currentStrokeStyle: null,
lastDraw: 0,
strokeStyle: null
};
};
goog.inherits(ol.render.canvas.LineStringBatch, ol.render.canvas.Batch);
/**
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset.
* @param {number} end End.
* @param {number} stride Stride.
* @private
*/
ol.render.canvas.LineStringBatch.prototype.drawFlatCoordinates_ =
function(flatCoordinates, offset, end, stride) {
var state = this.state_;
if (!ol.style.stroke.equals(state.currentStrokeStyle, state.strokeStyle)) {
if (state.lastDraw != this.coordinates.length) {
this.instructions.push([ol.render.canvas.Instruction.STROKE]);
}
this.instructions.push(
[ol.render.canvas.Instruction.SET_STROKE_STYLE, state.strokeStyle],
[ol.render.canvas.Instruction.BEGIN_PATH]);
state.currentStrokeStyle = state.strokeStyle;
}
var myEnd = this.appendFlatCoordinates(
flatCoordinates, offset, end, stride, false);
this.instructions.push([ol.render.canvas.Instruction.MOVE_TO_LINE_TO, myEnd]);
};
/**
* @inheritDoc
*/
ol.render.canvas.LineStringBatch.prototype.drawLineStringGeometry =
function(lineStringGeometry) {
goog.asserts.assert(!goog.isNull(this.state_));
ol.extent.extend(this.extent_, lineStringGeometry.getExtent());
var flatCoordinates = lineStringGeometry.getFlatCoordinates();
var stride = lineStringGeometry.getStride();
this.drawFlatCoordinates_(
flatCoordinates, 0, flatCoordinates.length, stride);
};
/**
* @inheritDoc
*/
ol.render.canvas.LineStringBatch.prototype.drawMultiLineStringGeometry =
function(multiLineStringGeometry) {
goog.asserts.assert(!goog.isNull(this.state_));
ol.extent.extend(this.extent_, multiLineStringGeometry.getExtent());
var ends = multiLineStringGeometry.getEnds();
var flatCoordinates = multiLineStringGeometry.getFlatCoordinates();
var stride = multiLineStringGeometry.getStride();
var offset = 0;
var i, ii;
for (i = 0, ii = ends.length; i < ii; ++i) {
var end = ends[i];
this.drawFlatCoordinates_(flatCoordinates, offset, end, stride);
offset = end;
}
};
/**
* @inheritDoc
*/
ol.render.canvas.LineStringBatch.prototype.finish = function() {
var state = this.state_;
goog.asserts.assert(!goog.isNull(state));
if (state.lastDraw != this.coordinates.length) {
this.instructions.push([ol.render.canvas.Instruction.STROKE]);
}
this.state_ = null;
};
/**
* @inheritDoc
*/
ol.render.canvas.LineStringBatch.prototype.setFillStrokeStyle =
function(fillStyle, strokeStyle) {
goog.asserts.assert(!goog.isNull(this.state_));
goog.asserts.assert(goog.isNull(fillStyle));
goog.asserts.assert(!goog.isNull(strokeStyle));
this.state_.strokeStyle = strokeStyle;
};
/**
* @constructor
* @extends {ol.render.canvas.Batch}
* @protected
*/
ol.render.canvas.PolygonBatch = function() {
goog.base(this);
/**
* @private
* @type {{currentFillStyle: ?ol.style.Fill,
* currentStrokeStyle: ?ol.style.Stroke,
* fillStyle: ?ol.style.Fill,
* strokeStyle: ?ol.style.Stroke}|null}
*/
this.state_ = {
currentFillStyle: null,
currentStrokeStyle: null,
fillStyle: null,
strokeStyle: null
};
};
goog.inherits(ol.render.canvas.PolygonBatch, ol.render.canvas.Batch);
/**
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset.
* @param {Array.<number>} ends Ends.
* @param {number} stride Stride.
* @private
*/
ol.render.canvas.PolygonBatch.prototype.drawFlatCoordinatess_ =
function(flatCoordinates, offset, ends, stride) {
var state = this.state_;
this.instructions.push([ol.render.canvas.Instruction.BEGIN_PATH]);
var i, ii;
for (i = 0, ii = ends.length; i < ii; ++i) {
var end = ends[i];
var myEnd =
this.appendFlatCoordinates(flatCoordinates, offset, end, stride, true);
this.instructions.push(
[ol.render.canvas.Instruction.MOVE_TO_LINE_TO, myEnd],
[ol.render.canvas.Instruction.CLOSE_PATH]);
offset = end;
}
// FIXME is it quicker to fill and stroke each polygon individually,
// FIXME or all polygons together?
if (!goog.isNull(state.fillStyle)) {
this.instructions.push([ol.render.canvas.Instruction.FILL]);
}
if (!goog.isNull(state.strokeStyle)) {
this.instructions.push([ol.render.canvas.Instruction.STROKE]);
}
};
/**
* @inheritDoc
*/
ol.render.canvas.PolygonBatch.prototype.drawPolygonGeometry =
function(polygonGeometry) {
goog.asserts.assert(!goog.isNull(this.state_));
ol.extent.extend(this.extent_, polygonGeometry.getExtent());
this.setFillStrokeStyles_();
var ends = polygonGeometry.getEnds();
var flatCoordinates = polygonGeometry.getFlatCoordinates();
var stride = polygonGeometry.getStride();
this.drawFlatCoordinatess_(flatCoordinates, 0, ends, stride);
};
/**
* @inheritDoc
*/
ol.render.canvas.PolygonBatch.prototype.drawMultiPolygonGeometry =
function(multiPolygonGeometry) {
goog.asserts.assert(!goog.isNull(this.state_));
ol.extent.extend(this.extent_, multiPolygonGeometry.getExtent());
this.setFillStrokeStyles_();
var endss = multiPolygonGeometry.getEndss();
var flatCoordinates = multiPolygonGeometry.getFlatCoordinates();
var stride = multiPolygonGeometry.getStride();
var offset = 0;
var i, ii;
for (i = 0, ii = endss.length; i < ii; ++i) {
var ends = endss[i];
this.drawFlatCoordinatess_(flatCoordinates, offset, ends, stride);
offset = ends[ends.length - 1];
}
};
/**
* @inheritDoc
*/
ol.render.canvas.PolygonBatch.prototype.finish = function() {
goog.asserts.assert(!goog.isNull(this.state_));
this.state_ = null;
};
/**
* @inheritDoc
*/
ol.render.canvas.PolygonBatch.prototype.setFillStrokeStyle =
function(fillStyle, strokeStyle) {
goog.asserts.assert(!goog.isNull(this.state_));
goog.asserts.assert(!goog.isNull(fillStyle) || !goog.isNull(strokeStyle));
this.state_.fillStyle = fillStyle;
this.state_.strokeStyle = strokeStyle;
};
/**
* @private
*/
ol.render.canvas.PolygonBatch.prototype.setFillStrokeStyles_ = function() {
var state = this.state_;
if (!goog.isNull(state.fillStyle) &&
!ol.style.fill.equals(state.currentFillStyle, state.fillStyle)) {
this.instructions.push(
[ol.render.canvas.Instruction.SET_FILL_STYLE, state.fillStyle]);
state.currentFillStyle = state.fillStyle;
}
if (!goog.isNull(state.strokeStyle) &&
!ol.style.stroke.equals(state.currentStrokeStyle, state.strokeStyle)) {
this.instructions.push(
[ol.render.canvas.Instruction.SET_STROKE_STYLE, state.strokeStyle]);
state.currentStrokeStyle = state.strokeStyle;
}
};
/**
* @constructor
* @implements {ol.render.IReplayBatchGroup}
*/
ol.render.canvas.BatchGroup = function() {
/**
* @private
* @type {Object.<string,
* Object.<ol.render.BatchType, ol.render.canvas.Batch>>}
*/
this.batchesByZIndex_ = {};
};
/**
* @param {CanvasRenderingContext2D} context Context.
* @param {ol.Extent} extent Extent.
* @param {goog.vec.Mat4.AnyType} transform Transform.
*/
ol.render.canvas.BatchGroup.prototype.draw =
function(context, extent, transform) {
/** @type {Array.<number>} */
var zs = goog.array.map(goog.object.getKeys(this.batchesByZIndex_), Number);
goog.array.sort(zs);
var i, ii;
for (i = 0, ii = zs.length; i < ii; ++i) {
var batches = this.batchesByZIndex_[zs[i].toString()];
var batchType;
for (batchType in batches) {
var batch = batches[batchType];
if (ol.extent.intersects(extent, batch.getExtent())) {
batch.draw(context, transform);
}
}
}
};
/**
* @inheritDoc
*/
ol.render.canvas.BatchGroup.prototype.finish = function() {
var zKey;
for (zKey in this.batchesByZIndex_) {
var batches = this.batchesByZIndex_[zKey];
var batchKey;
for (batchKey in batches) {
batches[batchKey].finish();
}
}
};
/**
* @inheritDoc
*/
ol.render.canvas.BatchGroup.prototype.getBatch = function(zIndex, batchType) {
var zIndexKey = goog.isDef(zIndex) ? zIndex.toString() : '0';
var batches = this.batchesByZIndex_[zIndexKey];
if (!goog.isDef(batches)) {
batches = {};
this.batchesByZIndex_[zIndexKey] = batches;
}
var batch = batches[batchType];
if (!goog.isDef(batch)) {
var constructor = ol.render.canvas.BATCH_CONSTRUCTORS_[batchType];
goog.asserts.assert(goog.isDef(constructor));
batch = new constructor();
batches[batchType] = batch;
}
return batch;
};
/**
* @inheritDoc
*/
ol.render.canvas.BatchGroup.prototype.isEmpty = function() {
return goog.object.isEmpty(this.batchesByZIndex_);
};
/**
* @const
* @private
* @type {Object.<ol.render.BatchType, function(new: ol.render.canvas.Batch)>}
*/
ol.render.canvas.BATCH_CONSTRUCTORS_ = {
'Image': ol.render.canvas.ImageBatch,
'LineString': ol.render.canvas.LineStringBatch,
'Polygon': ol.render.canvas.PolygonBatch
};

117
src/ol/render/ireplay.js Normal file
View File

@@ -0,0 +1,117 @@
goog.provide('ol.render.IReplayBatch');
goog.provide('ol.render.IReplayBatchGroup');
goog.require('goog.functions');
/**
* @enum {string}
*/
ol.render.BatchType = {
IMAGE: 'Image',
LINE_STRING: 'LineString',
POLYGON: 'Polygon'
};
/**
* @interface
*/
ol.render.IReplayBatch = function() {
};
/**
* @param {ol.geom.Point} pointGeometry Point geometry.
*/
ol.render.IReplayBatch.prototype.drawPointGeometry = function(pointGeometry) {
};
/**
* @param {ol.geom.LineString} lineStringGeometry Line string geometry.
*/
ol.render.IReplayBatch.prototype.drawLineStringGeometry =
function(lineStringGeometry) {
};
/**
* @param {ol.geom.MultiLineString} multiLineStringGeometry
* Multi line string geometry.
*/
ol.render.IReplayBatch.prototype.drawMultiLineStringGeometry =
function(multiLineStringGeometry) {
};
/**
* @param {ol.geom.MultiPoint} multiPointGeometry MultiPoint geometry.
*/
ol.render.IReplayBatch.prototype.drawMultiPointGeometry =
function(multiPointGeometry) {
};
/**
* @param {ol.geom.MultiPolygon} multiPolygonGeometry Multi polygon geometry.
*/
ol.render.IReplayBatch.prototype.drawMultiPolygonGeometry =
function(multiPolygonGeometry) {
};
/**
* @param {ol.geom.Polygon} polygonGeometry Polygon geometry.
*/
ol.render.IReplayBatch.prototype.drawPolygonGeometry =
function(polygonGeometry) {
};
/**
* @param {?ol.style.Fill} fillStyle Fill style.
* @param {?ol.style.Stroke} strokeStyle Stroke style.
*/
ol.render.IReplayBatch.prototype.setFillStrokeStyle =
function(fillStyle, strokeStyle) {
};
/**
* @param {?ol.style.Image} imageStyle Image style.
*/
ol.render.IReplayBatch.prototype.setImageStyle = function(imageStyle) {
};
/**
* @interface
*/
ol.render.IReplayBatchGroup = function() {
};
/**
* FIXME empty description for jsdoc
*/
ol.render.IReplayBatchGroup.prototype.finish = function() {
};
/**
* @param {number|undefined} zIndex Z index.
* @param {ol.render.BatchType} batchType Batch type.
* @return {ol.render.IReplayBatch} Batch.
*/
ol.render.IReplayBatchGroup.prototype.getBatch = function(zIndex, batchType) {
};
/**
* @return {boolean} Is empty.
*/
ol.render.IReplayBatchGroup.prototype.isEmpty = function() {
};

38
src/ol/render/render.js Normal file
View File

@@ -0,0 +1,38 @@
goog.provide('ol.render');
goog.require('goog.vec.Mat4');
/**
* @param {Array.<number>} coordinates Coordinates.
* @param {goog.vec.Mat4.AnyType} transform Transform.
* @param {Array.<number>=} opt_dest Destination.
* @return {Array.<number>} Transformed coordinates.
*/
ol.render.transformCoordinates = function(coordinates, transform, opt_dest) {
var m00 = goog.vec.Mat4.getElement(transform, 0, 0);
var m10 = goog.vec.Mat4.getElement(transform, 1, 0);
var m01 = goog.vec.Mat4.getElement(transform, 0, 1);
var m11 = goog.vec.Mat4.getElement(transform, 1, 1);
var m03 = goog.vec.Mat4.getElement(transform, 0, 3);
var m13 = goog.vec.Mat4.getElement(transform, 1, 3);
var n = coordinates.length;
var result;
if (goog.isDef(opt_dest)) {
result = opt_dest;
} else {
result = [];
}
var j = 0;
var i, x, y;
for (i = 0; i < n; ) {
x = coordinates[i++];
y = coordinates[i++];
result[j++] = m00 * x + m01 * y + m03;
result[j++] = m10 * x + m11 * y + m13;
}
if (goog.isDef(opt_dest) && result.length != j) {
result.length = j;
}
return result;
};

160
src/ol/render/vector.js Normal file
View File

@@ -0,0 +1,160 @@
goog.provide('ol.renderer.vector');
goog.require('goog.asserts');
goog.require('ol.geom.LineString');
goog.require('ol.geom.MultiLineString');
goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.MultiPolygon');
goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon');
goog.require('ol.render.IReplayBatchGroup');
goog.require('ol.style.Style');
/**
* @param {ol.render.IReplayBatchGroup} batchGroup Batch group.
* @param {ol.Feature} feature Feature.
* @param {ol.style.Style} style Style.
*/
ol.renderer.vector.renderFeature = function(batchGroup, feature, style) {
var geometry = feature.getGeometry();
var geometryRenderer =
ol.renderer.vector.GEOMETRY_RENDERERS_[geometry.getType()];
goog.asserts.assert(goog.isDef(geometryRenderer));
geometryRenderer(batchGroup, geometry, style);
};
/**
* @param {ol.render.IReplayBatchGroup} batchGroup Batch group.
* @param {ol.geom.Geometry} geometry Geometry.
* @param {ol.style.Style} style Style.
* @private
*/
ol.renderer.vector.renderLineStringGeometry_ =
function(batchGroup, geometry, style) {
if (goog.isNull(style.stroke)) {
return;
}
goog.asserts.assert(geometry instanceof ol.geom.LineString);
var lineStringGeometry = /** @type {ol.geom.LineString} */ (geometry);
var batch = batchGroup.getBatch(
style.zIndex, ol.render.BatchType.LINE_STRING);
batch.setFillStrokeStyle(null, style.stroke);
batch.drawLineStringGeometry(lineStringGeometry);
};
/**
* @param {ol.render.IReplayBatchGroup} batchGroup Batch group.
* @param {ol.geom.Geometry} geometry Geometry.
* @param {ol.style.Style} style Style.
* @private
*/
ol.renderer.vector.renderMultiLineStringGeometry_ =
function(batchGroup, geometry, style) {
if (goog.isNull(style.stroke)) {
return;
}
goog.asserts.assert(geometry instanceof ol.geom.MultiLineString);
var multiLineStringGeometry = /** @type {ol.geom.MultiLineString} */
(geometry);
var batch = batchGroup.getBatch(
style.zIndex, ol.render.BatchType.LINE_STRING);
batch.setFillStrokeStyle(null, style.stroke);
batch.drawMultiLineStringGeometry(multiLineStringGeometry);
};
/**
* @param {ol.render.IReplayBatchGroup} batchGroup Batch group.
* @param {ol.geom.Geometry} geometry Geometry.
* @param {ol.style.Style} style Style.
* @private
*/
ol.renderer.vector.renderMultiPolygonGeometry_ =
function(batchGroup, geometry, style) {
if (goog.isNull(style.stroke) && goog.isNull(style.fill)) {
return;
}
goog.asserts.assert(geometry instanceof ol.geom.MultiPolygon);
var multiPolygonGeometry = /** @type {ol.geom.MultiPolygon} */
(geometry);
var batch = batchGroup.getBatch(
style.zIndex, ol.render.BatchType.POLYGON);
batch.setFillStrokeStyle(style.fill, style.stroke);
batch.drawMultiPolygonGeometry(multiPolygonGeometry);
};
/**
* @param {ol.render.IReplayBatchGroup} batchGroup Batch group.
* @param {ol.geom.Geometry} geometry Geometry.
* @param {ol.style.Style} style Style.
* @private
*/
ol.renderer.vector.renderPointGeometry_ =
function(batchGroup, geometry, style) {
if (goog.isNull(style.image)) {
return;
}
goog.asserts.assert(geometry instanceof ol.geom.Point);
var pointGeometry = /** @type {ol.geom.Point} */ (geometry);
var batch = batchGroup.getBatch(style.zIndex, ol.render.BatchType.IMAGE);
batch.setImageStyle(style.image);
batch.drawPointGeometry(pointGeometry);
};
/**
* @param {ol.render.IReplayBatchGroup} batchGroup Batch group.
* @param {ol.geom.Geometry} geometry Geometry.
* @param {ol.style.Style} style Style.
* @private
*/
ol.renderer.vector.renderMultiPointGeometry_ =
function(batchGroup, geometry, style) {
if (goog.isNull(style.image)) {
return;
}
goog.asserts.assert(geometry instanceof ol.geom.MultiPoint);
var multiPointGeometry = /** @type {ol.geom.MultiPoint} */ (geometry);
var batch = batchGroup.getBatch(style.zIndex, ol.render.BatchType.IMAGE);
batch.setImageStyle(style.image);
batch.drawMultiPointGeometry(multiPointGeometry);
};
/**
* @param {ol.render.IReplayBatchGroup} batchGroup Batch group.
* @param {ol.geom.Geometry} geometry Geometry.
* @param {ol.style.Style} style Style.
* @private
*/
ol.renderer.vector.renderPolygonGeometry_ =
function(batchGroup, geometry, style) {
if (goog.isNull(style.fill) && goog.isNull(style.stroke)) {
return;
}
goog.asserts.assert(geometry instanceof ol.geom.Polygon);
var polygonGeometry = /** @type {ol.geom.Polygon} */ (geometry);
var batch = batchGroup.getBatch(style.zIndex, ol.render.BatchType.POLYGON);
batch.setFillStrokeStyle(style.fill, style.stroke);
batch.drawPolygonGeometry(polygonGeometry);
};
/**
* @const
* @private
* @type {Object.<ol.geom.GeometryType,
* function(ol.render.IReplayBatchGroup, ol.geom.Geometry,
* ol.style.Style)>}
*/
ol.renderer.vector.GEOMETRY_RENDERERS_ = {
'Point': ol.renderer.vector.renderPointGeometry_,
'LineString': ol.renderer.vector.renderLineStringGeometry_,
'Polygon': ol.renderer.vector.renderPolygonGeometry_,
'MultiLineString': ol.renderer.vector.renderMultiLineStringGeometry_,
'MultiPolygon': ol.renderer.vector.renderMultiPolygonGeometry_
};