Handle case of one segment lines with identical coordinates + quality improvements

This commit is contained in:
GaborFarkas
2016-06-14 20:34:11 +02:00
parent fb71860a03
commit c13d09ba23
+41 -30
View File
@@ -21,8 +21,8 @@ goog.require('ol.render.webgl.linestringreplay.shader.DefaultFragment');
goog.require('ol.render.webgl.linestringreplay.shader.DefaultVertex'); goog.require('ol.render.webgl.linestringreplay.shader.DefaultVertex');
goog.require('ol.render.webgl.polygonreplay.shader.Default'); goog.require('ol.render.webgl.polygonreplay.shader.Default');
goog.require('ol.render.webgl.polygonreplay.shader.Default.Locations'); goog.require('ol.render.webgl.polygonreplay.shader.Default.Locations');
goog.require('ol.render.webgl.polygonreplay.shader.DefaultFragment'); //goog.require('ol.render.webgl.polygonreplay.shader.DefaultFragment');
goog.require('ol.render.webgl.polygonreplay.shader.DefaultVertex'); //goog.require('ol.render.webgl.polygonreplay.shader.DefaultVertex');
goog.require('ol.vec.Mat4'); goog.require('ol.vec.Mat4');
goog.require('ol.webgl'); goog.require('ol.webgl');
goog.require('ol.webgl.Buffer'); goog.require('ol.webgl.Buffer');
@@ -705,10 +705,11 @@ ol.render.webgl.ImageReplay.prototype.setUpProgram_ = function(gl, context, size
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
* to skip. * to skip.
* @param {boolean} hitDetection Hit detection mode.
*/ */
ol.render.webgl.ImageReplay.prototype.drawReplay_ = function(gl, context, skippedFeaturesHash) { ol.render.webgl.ImageReplay.prototype.drawReplay_ = function(gl, context, skippedFeaturesHash, hitDetection) {
var textures = this.textures_; var textures = hitDetection ? this.hitDetectionTextures_ : this.textures_;
var groupIndices = this.groupIndices_; var groupIndices = hitDetection ? this.hitDetectionGroupIndices_ : this.groupIndices_;
ol.DEBUG && console.assert(textures.length === groupIndices.length, ol.DEBUG && console.assert(textures.length === groupIndices.length,
'number of textures and groupIndeces match'); 'number of textures and groupIndeces match');
var elementType = context.hasOESElementIndexUint ? var elementType = context.hasOESElementIndexUint ?
@@ -841,8 +842,7 @@ ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplay_ = function(gl, con
*/ */
ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplayAll_ = function(gl, context, skippedFeaturesHash, featureCallback) { ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplayAll_ = function(gl, context, skippedFeaturesHash, featureCallback) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
this.drawReplay_(gl, context, skippedFeaturesHash, this.drawReplay_(gl, context, skippedFeaturesHash, true);
this.hitDetectionTextures_, this.hitDetectionGroupIndices_);
var result = featureCallback(null); var result = featureCallback(null);
if (result) { if (result) {
@@ -1003,13 +1003,13 @@ ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
/** /**
* @private * @private
* @type {ol.render.webgl.polygonreplay.shader.Default.Locations} * @type {ol.render.webgl.linestringreplay.shader.Default.Locations}
*/ */
this.defaultLocations_ = null; this.defaultLocations_ = null;
/** /**
* @private * @private
* @type {{strokeColor: (Array.<number>|undefined), * @type {{strokeColor: (Array.<number>|null),
* lineCap: (string|undefined), * lineCap: (string|undefined),
* lineDash: Array.<number>, * lineDash: Array.<number>,
* lineJoin: (string|undefined), * lineJoin: (string|undefined),
@@ -1017,7 +1017,7 @@ ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
* miterLimit: (number|undefined)}|null} * miterLimit: (number|undefined)}|null}
*/ */
this.state_ = { this.state_ = {
strokeColor: undefined, strokeColor: null,
lineCap: undefined, lineCap: undefined,
lineDash: null, lineDash: null,
lineJoin: undefined, lineJoin: undefined,
@@ -1045,7 +1045,7 @@ ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoord
var lineJoin = this.state_.lineJoin === 'bevel' ? false : true; var lineJoin = this.state_.lineJoin === 'bevel' ? false : true;
var lineCap = this.state_.lineCap === 'butt' ? false : true; var lineCap = this.state_.lineCap === 'butt' ? false : true;
var closed = this.isClosed_(flatCoordinates, offset, end, stride); var closed = this.isClosed_(flatCoordinates, offset, end, stride);
var lastIndex; var lastIndex = numIndices;
var lastSign = 1; var lastSign = 1;
//We need the adjacent vertices to define normals in joins. p0 = last, p1 = current, p2 = next. //We need the adjacent vertices to define normals in joins. p0 = last, p1 = current, p2 = next.
//We rotate those points, thus every point is RTE corrected only once. //We rotate those points, thus every point is RTE corrected only once.
@@ -1060,6 +1060,9 @@ ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoord
//First vertex. //First vertex.
if (i === offset) { if (i === offset) {
p2 = [flatCoordinates[i + stride] - this.origin_[0], flatCoordinates[i + stride + 1] - this.origin_[1]]; p2 = [flatCoordinates[i + stride] - this.origin_[0], flatCoordinates[i + stride + 1] - this.origin_[1]];
if (flatCoordinates.length === stride * 2 && ol.array.equals(p1, p2)) {
break;
}
if (closed) { if (closed) {
//A closed line! Complete the circle. //A closed line! Complete the circle.
tempP = [flatCoordinates[end - stride] - this.origin_[0], flatCoordinates[end - stride + 1] - this.origin_[1]]; tempP = [flatCoordinates[end - stride] - this.origin_[0], flatCoordinates[end - stride + 1] - this.origin_[1]];
@@ -1298,7 +1301,14 @@ ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = function(multiL
var lineStringGeometries = multiLineStringGeometry.getLineStrings(); var lineStringGeometries = multiLineStringGeometry.getLineStrings();
var i, ii; var i, ii;
for (i = 0, ii = lineStringGeometries.length; i < ii; ++i) { for (i = 0, ii = lineStringGeometries.length; i < ii; ++i) {
this.drawLineString(lineStringGeometries[i], feature); var flatCoordinates = lineStringGeometries[i].getFlatCoordinates();
var stride = lineStringGeometries[i].getStride();
if (flatCoordinates.length > stride) {
this.startIndices_.push(this.indices_.length);
this.startIndicesFeature_.push(feature);
this.drawCoordinates_(
flatCoordinates, 0, flatCoordinates.length, stride);
}
} }
}; };
@@ -1396,10 +1406,14 @@ ol.render.webgl.LineStringReplay.prototype.setUpProgram_ = function(gl, context,
ol.render.webgl.LineStringInstruction.ROUND_JOIN : this.state_.lineCap === 'round' ? ol.render.webgl.LineStringInstruction.ROUND_JOIN : this.state_.lineCap === 'round' ?
ol.render.webgl.LineStringInstruction.ROUND_CAP : 0; ol.render.webgl.LineStringInstruction.ROUND_CAP : 0;
// enable renderer specific uniforms // Enable renderer specific uniforms. If clauses needed, as otherwise the compiler complains.
gl.uniform4fv(locations.u_color, this.state_.strokeColor); gl.uniform4fv(locations.u_color, this.state_.strokeColor);
gl.uniform1f(locations.u_lineWidth, this.state_.lineWidth); if (this.state_.lineWidth) {
gl.uniform1f(locations.u_miterLimit, this.state_.miterLimit); gl.uniform1f(locations.u_lineWidth, this.state_.lineWidth);
}
if (this.state_.miterLimit) {
gl.uniform1f(locations.u_miterLimit, this.state_.miterLimit);
}
gl.uniform2fv(locations.u_size, size); gl.uniform2fv(locations.u_size, size);
gl.uniform1f(locations.u_round, round); gl.uniform1f(locations.u_round, round);
@@ -1412,8 +1426,9 @@ ol.render.webgl.LineStringReplay.prototype.setUpProgram_ = function(gl, context,
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {Object} skippedFeaturesHash Ids of features to skip. * @param {Object} skippedFeaturesHash Ids of features to skip.
* @param {boolean} hitDetection Hit detection mode.
*/ */
ol.render.webgl.LineStringReplay.prototype.drawReplay_ = function(gl, context, skippedFeaturesHash) { ol.render.webgl.LineStringReplay.prototype.drawReplay_ = function(gl, context, skippedFeaturesHash, hitDetection) {
var elementType = context.hasOESElementIndexUint ? var elementType = context.hasOESElementIndexUint ?
goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT; goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT;
var elementSize = context.hasOESElementIndexUint ? 4 : 2; var elementSize = context.hasOESElementIndexUint ? 4 : 2;
@@ -1421,12 +1436,8 @@ ol.render.webgl.LineStringReplay.prototype.drawReplay_ = function(gl, context, s
if (!goog.object.isEmpty(skippedFeaturesHash)) { if (!goog.object.isEmpty(skippedFeaturesHash)) {
// TODO: draw by blocks to skip features // TODO: draw by blocks to skip features
} else { } else {
var i, ii; var end = this.startIndices_[this.startIndices_.length - 1];
for (i = 0, ii = this.startIndices_.length - 1; i < ii; ++i) { this.drawElements_(gl, 0, end, elementType, elementSize);
var start = this.startIndices_[i];
var end = this.startIndices_[i + 1];
this.drawElements_(gl, start, end, elementType, elementSize);
}
} }
}; };
@@ -1466,10 +1477,9 @@ ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = function(fillSty
goog.asserts.assert(!fillStyle, 'fillStyle should be null'); goog.asserts.assert(!fillStyle, 'fillStyle should be null');
goog.asserts.assert(strokeStyle, 'strokeStyle should not be null'); goog.asserts.assert(strokeStyle, 'strokeStyle should not be null');
var strokeStyleColor = strokeStyle.getColor(); var strokeStyleColor = strokeStyle.getColor();
this.state_.strokeColor = !goog.isNull(strokeStyleColor) ? this.state_.strokeColor = ol.color.asArray(strokeStyleColor).map(function(c, i) {
ol.color.asArray(strokeStyleColor).map(function(c, i) { return i != 3 ? c / 255 : c;
return i != 3 ? c / 255 : c; }) || ol.render.webgl.defaultStrokeStyle;
}) : ol.render.webgl.defaultStrokeStyle;
var strokeStyleLineCap = strokeStyle.getLineCap(); var strokeStyleLineCap = strokeStyle.getLineCap();
this.state_.lineCap = strokeStyleLineCap !== undefined ? this.state_.lineCap = strokeStyleLineCap !== undefined ?
strokeStyleLineCap : ol.render.webgl.defaultLineCap; strokeStyleLineCap : ol.render.webgl.defaultLineCap;
@@ -1490,7 +1500,7 @@ ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = function(fillSty
/** /**
* @constructor * @constructor
* @extends {ol.render.VectorContext} * @extends {ol.render.webgl.Replay}
* @param {number} tolerance Tolerance. * @param {number} tolerance Tolerance.
* @param {ol.Extent} maxExtent Max extent. * @param {ol.Extent} maxExtent Max extent.
* @protected * @protected
@@ -1642,7 +1652,8 @@ ol.render.webgl.PolygonReplay.prototype.drawPolygon = function(polygonGeometry,
var linearRings = polygonGeometry.getLinearRings(); var linearRings = polygonGeometry.getLinearRings();
var i, ii; var i, ii;
for (i = 0, ii = linearRings.length; i < ii; i++) { for (i = 0, ii = linearRings.length; i < ii; i++) {
this.lineStringReplay_.drawCoordinates_(linearRings[i].getCoordinates()); //FIXME: Substitute zeros with appropriate values when implementing.
this.lineStringReplay_.drawCoordinates_(linearRings[i].getFlatCoordinates(), 0, 0, 0);
} }
} }
}; };
@@ -1713,7 +1724,7 @@ ol.render.webgl.PolygonReplay.prototype.getDeleteResourcesFunction = function(co
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
ol.render.webgl.PolygonReplay.prototype.replay = function(context, /*ol.render.webgl.PolygonReplay.prototype.replay = function(context,
center, resolution, rotation, size, pixelRatio, center, resolution, rotation, size, pixelRatio,
opacity, brightness, contrast, hue, saturation, skippedFeaturesHash, opacity, brightness, contrast, hue, saturation, skippedFeaturesHash,
featureCallback, oneByOne, opt_hitExtent) { featureCallback, oneByOne, opt_hitExtent) {
@@ -1788,7 +1799,7 @@ ol.render.webgl.PolygonReplay.prototype.replay = function(context,
featureCallback, oneByOne, opt_hitExtent); featureCallback, oneByOne, opt_hitExtent);
// FIXME get result // FIXME get result
return result; return result;
}; };*/
/** /**