Inspect linestring validity before drawing

This commit is contained in:
GaborFarkas
2016-06-17 12:58:32 +02:00
parent 99e4009b19
commit 8c561a45b9

View File

@@ -1052,6 +1052,8 @@ ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoord
//We rotate those points, thus every point is RTE corrected only once.
var p0, p1, p2, tempP;
if (this.isValid_(flatCoordinates, offset, end, stride, closed)) {
for (i = offset, ii = end; i < ii; i += stride) {
var n = numVertices / 7;
@@ -1208,6 +1210,7 @@ ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoord
this.indices_[numIndices++] = lastIndex - 1;
this.indices_[numIndices++] = lastIndex;
}
}
};
/**
@@ -1249,6 +1252,39 @@ ol.render.webgl.LineStringReplay.prototype.isClosed_ = function(flatCoordinates,
return false;
};
/**
* Check if the linestring can be drawn (i. e. valid).
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset.
* @param {number} end End.
* @param {number} stride Stride.
* @param {boolean} closed The linestring is a boundary.
* @return {boolean} The linestring can be drawn.
* @private
*/
ol.render.webgl.LineStringReplay.prototype.isValid_ = function(flatCoordinates, offset, end, stride,
closed) {
var uniqueCoords = [[flatCoordinates[offset], flatCoordinates[offset + 1]]];
var minUnique = closed ? 3 : 2;
var i, ii, j;
for (i = offset + stride, ii = end; i < ii; i += stride) {
var currentCoords = [flatCoordinates[i], flatCoordinates[i + 1]];
for (j = 0; j < uniqueCoords.length; ++j) {
if (ol.array.equals(currentCoords, uniqueCoords[j])) {
j = -1;
break;
}
}
if (j > -1) {
uniqueCoords.push(currentCoords);
}
if (uniqueCoords.length >= minUnique) {
return true;
}
}
return false;
};
/**
* @inheritDoc