Skip to content

Commit

Permalink
Adressed review.
Browse files Browse the repository at this point in the history
Reusing transform
Changing either size of the canvas or clearing it
adding unit of hitTolerance to jsdoc
  • Loading branch information
simonseyock committed Dec 8, 2016
1 parent 55ec0af commit f10ae6c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion externs/olx.js
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions src/ol/interaction/select.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ol/interaction/translate.js
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
20 changes: 15 additions & 5 deletions src/ol/render/canvas/replaygroup.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/ol/renderer/layer.js
Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions src/ol/renderer/map.js
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ol/source/source.js
Expand Up @@ -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.
Expand Down

0 comments on commit f10ae6c

Please sign in to comment.