Adressed review.
Reusing transform Changing either size of the canvas or clearing it adding unit of hitTolerance to jsdoc
This commit is contained in:
@@ -323,7 +323,7 @@ olx.AtPixelOptions.prototype.layerFilter;
|
||||
|
||||
|
||||
/**
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* Hit-detection tolerance in pixels. Pixels inside the radius around the given position
|
||||
* will be checked for features. This only works for the canvas renderer and
|
||||
* not for WebGL.
|
||||
* @type {number|undefined}
|
||||
|
||||
@@ -168,7 +168,7 @@ ol.interaction.Select.prototype.getFeatures = function() {
|
||||
|
||||
/**
|
||||
* Returns the Hit-detection tolerance.
|
||||
* @returns {number} Hit tolerance.
|
||||
* @returns {number} Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.prototype.getHitTolerance = function() {
|
||||
@@ -291,7 +291,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* will be checked for features. This only works for the canvas renderer and
|
||||
* not for WebGL.
|
||||
* @param {number} hitTolerance Hit tolerance.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.prototype.setHitTolerance = function(hitTolerance) {
|
||||
|
||||
@@ -212,7 +212,7 @@ ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) {
|
||||
|
||||
/**
|
||||
* Returns the Hit-detection tolerance.
|
||||
* @returns {number} Hit tolerance.
|
||||
* @returns {number} Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Translate.prototype.getHitTolerance = function() {
|
||||
@@ -224,7 +224,7 @@ ol.interaction.Translate.prototype.getHitTolerance = function() {
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* will be checked for features. This only works for the canvas renderer and
|
||||
* not for WebGL.
|
||||
* @param {number} hitTolerance Hit tolerance.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Translate.prototype.setHitTolerance = function(hitTolerance) {
|
||||
|
||||
@@ -71,6 +71,12 @@ ol.render.canvas.ReplayGroup = function(
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
this.hitDetectionContext_ = ol.dom.createCanvasContext2D(1, 1);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Transform}
|
||||
*/
|
||||
this.hitDetectionTransform_ = ol.transform.create();
|
||||
};
|
||||
ol.inherits(ol.render.canvas.ReplayGroup, ol.render.ReplayGroup);
|
||||
|
||||
@@ -174,7 +180,7 @@ ol.render.canvas.ReplayGroup.prototype.finish = function() {
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {number} hitTolerance Hit tolerance.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {function((ol.Feature|ol.render.Feature)): T} callback Feature
|
||||
@@ -187,15 +193,19 @@ ol.render.canvas.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
|
||||
|
||||
hitTolerance = Math.round(hitTolerance);
|
||||
var contextSize = hitTolerance * 2 + 1;
|
||||
var transform = ol.transform.compose(ol.transform.create(),
|
||||
var transform = ol.transform.compose(this.hitDetectionTransform_,
|
||||
hitTolerance + 0.5, hitTolerance + 0.5,
|
||||
1 / resolution, -1 / resolution,
|
||||
-rotation,
|
||||
-coordinate[0], -coordinate[1]);
|
||||
var context = this.hitDetectionContext_;
|
||||
context.canvas.width = contextSize;
|
||||
context.canvas.height = contextSize;
|
||||
context.clearRect(0, 0, contextSize, contextSize);
|
||||
|
||||
if (context.canvas.width !== contextSize || context.canvas.height !== contextSize) {
|
||||
context.canvas.width = contextSize;
|
||||
context.canvas.height = contextSize;
|
||||
} else {
|
||||
context.clearRect(0, 0, contextSize, contextSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {ol.Extent}
|
||||
|
||||
@@ -35,7 +35,7 @@ ol.inherits(ol.renderer.Layer, ol.Observable);
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {olx.FrameState} frameState Frame state.
|
||||
* @param {number} hitTolerance Hit tolerance.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @param {function(this: S, (ol.Feature|ol.render.Feature), ol.layer.Layer): T}
|
||||
* callback Feature callback.
|
||||
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||
|
||||
@@ -100,7 +100,7 @@ ol.renderer.Map.expireIconCache_ = function(map, frameState) {
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {olx.FrameState} frameState FrameState.
|
||||
* @param {number} hitTolerance Hit tolerance.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @param {function(this: S, (ol.Feature|ol.render.Feature),
|
||||
* ol.layer.Layer): T} callback Feature callback.
|
||||
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||
@@ -189,7 +189,7 @@ ol.renderer.Map.prototype.forEachLayerAtPixel = function(pixel, frameState, call
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {olx.FrameState} frameState FrameState.
|
||||
* @param {number} hitTolerance Hit tolerance.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
|
||||
* function, only layers which are visible and for which this function
|
||||
* returns `true` will be tested for features. By default, all visible
|
||||
|
||||
@@ -94,7 +94,7 @@ ol.source.Source.toAttributionsArray_ = function(attributionLike) {
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {number} hitTolerance Hit tolerance.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @param {Object.<string, boolean>} skippedFeatureUids Skipped feature uids.
|
||||
* @param {function((ol.Feature|ol.render.Feature)): T} callback Feature
|
||||
* callback.
|
||||
|
||||
Reference in New Issue
Block a user