Merge pull request #1409 from twpayne/vector-api-polygon-quantize
[vector-api] Always quantize polygons
This commit is contained in:
@@ -14,6 +14,7 @@ goog.require('ol.array');
|
|||||||
goog.require('ol.color');
|
goog.require('ol.color');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
|
goog.require('ol.geom.simplify');
|
||||||
goog.require('ol.render.IRender');
|
goog.require('ol.render.IRender');
|
||||||
goog.require('ol.render.IReplayGroup');
|
goog.require('ol.render.IReplayGroup');
|
||||||
goog.require('ol.render.canvas');
|
goog.require('ol.render.canvas');
|
||||||
@@ -42,10 +43,11 @@ ol.render.canvas.Instruction = {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @implements {ol.render.IRender}
|
* @implements {ol.render.IRender}
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
|
* @param {number} tolerance Tolerance.
|
||||||
* @protected
|
* @protected
|
||||||
* @struct
|
* @struct
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.Replay = function(pixelRatio) {
|
ol.render.canvas.Replay = function(pixelRatio, tolerance) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
@@ -53,6 +55,12 @@ ol.render.canvas.Replay = function(pixelRatio) {
|
|||||||
*/
|
*/
|
||||||
this.pixelRatio = pixelRatio;
|
this.pixelRatio = pixelRatio;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.tolerance = tolerance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Array.<*>}
|
* @type {Array.<*>}
|
||||||
@@ -438,12 +446,13 @@ ol.render.canvas.Replay.prototype.setTextStyle = goog.abstractMethod;
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.render.canvas.Replay}
|
* @extends {ol.render.canvas.Replay}
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
|
* @param {number} tolerance Tolerance.
|
||||||
* @protected
|
* @protected
|
||||||
* @struct
|
* @struct
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.ImageReplay = function(pixelRatio) {
|
ol.render.canvas.ImageReplay = function(pixelRatio, tolerance) {
|
||||||
|
|
||||||
goog.base(this, pixelRatio);
|
goog.base(this, pixelRatio, tolerance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -597,12 +606,13 @@ ol.render.canvas.ImageReplay.prototype.setImageStyle = function(imageStyle) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.render.canvas.Replay}
|
* @extends {ol.render.canvas.Replay}
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
|
* @param {number} tolerance Tolerance.
|
||||||
* @protected
|
* @protected
|
||||||
* @struct
|
* @struct
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.LineStringReplay = function(pixelRatio) {
|
ol.render.canvas.LineStringReplay = function(pixelRatio, tolerance) {
|
||||||
|
|
||||||
goog.base(this, pixelRatio);
|
goog.base(this, pixelRatio, tolerance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -800,12 +810,13 @@ ol.render.canvas.LineStringReplay.prototype.setFillStrokeStyle =
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.render.canvas.Replay}
|
* @extends {ol.render.canvas.Replay}
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
|
* @param {number} tolerance Tolerance.
|
||||||
* @protected
|
* @protected
|
||||||
* @struct
|
* @struct
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.PolygonReplay = function(pixelRatio) {
|
ol.render.canvas.PolygonReplay = function(pixelRatio, tolerance) {
|
||||||
|
|
||||||
goog.base(this, pixelRatio);
|
goog.base(this, pixelRatio, tolerance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -974,6 +985,18 @@ ol.render.canvas.PolygonReplay.prototype.finish = function() {
|
|||||||
goog.asserts.assert(!goog.isNull(this.state_));
|
goog.asserts.assert(!goog.isNull(this.state_));
|
||||||
this.reverseHitDetectionInstructions_();
|
this.reverseHitDetectionInstructions_();
|
||||||
this.state_ = null;
|
this.state_ = null;
|
||||||
|
// We want to preserve topology when drawing polygons. Polygons are
|
||||||
|
// simplified using quantization and point elimination. However, we might
|
||||||
|
// have received a mix of quantized and non-quantized geometries, so ensure
|
||||||
|
// that all are quantized by quantizing all coordinates in the batch.
|
||||||
|
var tolerance = this.tolerance;
|
||||||
|
if (tolerance !== 0) {
|
||||||
|
var coordinates = this.coordinates;
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||||
|
coordinates[i] = ol.geom.simplify.snap(coordinates[i], tolerance);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1063,9 +1086,10 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyles_ = function() {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @implements {ol.render.IReplayGroup}
|
* @implements {ol.render.IReplayGroup}
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
|
* @param {number} tolerance Tolerance.
|
||||||
* @struct
|
* @struct
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.ReplayGroup = function(pixelRatio) {
|
ol.render.canvas.ReplayGroup = function(pixelRatio, tolerance) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -1073,6 +1097,12 @@ ol.render.canvas.ReplayGroup = function(pixelRatio) {
|
|||||||
*/
|
*/
|
||||||
this.pixelRatio_ = pixelRatio;
|
this.pixelRatio_ = pixelRatio;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.tolerance_ = tolerance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<string,
|
* @type {Object.<string,
|
||||||
@@ -1265,7 +1295,7 @@ ol.render.canvas.ReplayGroup.prototype.getReplay =
|
|||||||
if (!goog.isDef(replay)) {
|
if (!goog.isDef(replay)) {
|
||||||
var constructor = ol.render.canvas.BATCH_CONSTRUCTORS_[replayType];
|
var constructor = ol.render.canvas.BATCH_CONSTRUCTORS_[replayType];
|
||||||
goog.asserts.assert(goog.isDef(constructor));
|
goog.asserts.assert(goog.isDef(constructor));
|
||||||
replay = new constructor(this.pixelRatio_);
|
replay = new constructor(this.pixelRatio_, this.tolerance_);
|
||||||
replayes[replayType] = replay;
|
replayes[replayType] = replay;
|
||||||
}
|
}
|
||||||
return replay;
|
return replay;
|
||||||
@@ -1284,7 +1314,7 @@ ol.render.canvas.ReplayGroup.prototype.isEmpty = function() {
|
|||||||
* @const
|
* @const
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<ol.render.ReplayType,
|
* @type {Object.<ol.render.ReplayType,
|
||||||
* function(new: ol.render.canvas.Replay, number)>}
|
* function(new: ol.render.canvas.Replay, number, number)>}
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.BATCH_CONSTRUCTORS_ = {
|
ol.render.canvas.BATCH_CONSTRUCTORS_ = {
|
||||||
'Image': ol.render.canvas.ImageReplay,
|
'Image': ol.render.canvas.ImageReplay,
|
||||||
|
|||||||
@@ -199,7 +199,8 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
|||||||
if (!goog.isDef(styleFunction)) {
|
if (!goog.isDef(styleFunction)) {
|
||||||
styleFunction = ol.layer.Vector.defaultStyleFunction;
|
styleFunction = ol.layer.Vector.defaultStyleFunction;
|
||||||
}
|
}
|
||||||
var replayGroup = new ol.render.canvas.ReplayGroup(pixelRatio);
|
var tolerance = frameStateResolution / (2 * pixelRatio);
|
||||||
|
var replayGroup = new ol.render.canvas.ReplayGroup(pixelRatio, tolerance);
|
||||||
vectorSource.forEachFeatureInExtent(extent,
|
vectorSource.forEachFeatureInExtent(extent,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
|
|||||||
Reference in New Issue
Block a user