Satisfying linter, jsdoc & compiler

This commit is contained in:
simonseyock
2016-10-19 18:10:21 +02:00
committed by simonseyock
parent 2493eb2c20
commit 80e392ea52
7 changed files with 82 additions and 53 deletions
+43
View File
@@ -301,6 +301,49 @@ olx.MapOptions.prototype.target;
*/ */
olx.MapOptions.prototype.view; olx.MapOptions.prototype.view;
/**
* The filter function will receive one argument, the
* {@link ol.layer.Layer layer-candidate} and it should return a boolean
* value.
* @typedef {(function(ol.layer.Layer): boolean)}
*/
olx.LayerFilterFunction;
/**
* Object literal with options for the forEachFeatureAtCoordinate methods.
* @typedef {{layerFilter: (olx.LayerFilterFunction|undefined),
* layerFilterThis: (Object|undefined),
* hitTolerance: (number|undefined)}}
*/
olx.ForEachFeatureOptions;
/**
* Layer filter function. Only layers which are visible and for which this function returns
* `true` will be tested for features. By default, all visible layers will
* be tested.
* @type {olx.LayerFilterFunction|undefined}
* @api stable
*/
olx.ForEachFeatureOptions.prototype.layerFilter;
/**
* Value to use as `this` when executing `layerFilter`.
* @type {Object}
* @api stable
*/
olx.ForEachFeatureOptions.prototype.layerFilterThis;
/**
* Value of a radius in whichs area around the given coordinate features are
* called.
* @type {number}
* @api stable
*/
olx.ForEachFeatureOptions.prototype.hitTolerance;
/** /**
* Object literal with config options for the overlay. * Object literal with config options for the overlay.
+4 -8
View File
@@ -200,9 +200,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
// pixel, or clear the selected feature(s) if there is no feature at // pixel, or clear the selected feature(s) if there is no feature at
// the pixel. // the pixel.
ol.obj.clear(this.featureLayerAssociation_); ol.obj.clear(this.featureLayerAssociation_);
map.forEachFeatureAtPixel(mapBrowserEvent.pixel, { map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
layerFilter: this.layerFilter_
},
/** /**
* @param {ol.Feature|ol.render.Feature} feature Feature. * @param {ol.Feature|ol.render.Feature} feature Feature.
* @param {ol.layer.Layer} layer Layer. * @param {ol.layer.Layer} layer Layer.
@@ -214,7 +212,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
this.addFeatureLayerAssociation_(feature, layer); this.addFeatureLayerAssociation_(feature, layer);
return !this.multi_; return !this.multi_;
} }
}, this); }, this, {layerFilter: this.layerFilter_});
var i; var i;
for (i = features.getLength() - 1; i >= 0; --i) { for (i = features.getLength() - 1; i >= 0; --i) {
var feature = features.item(i); var feature = features.item(i);
@@ -232,9 +230,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
} }
} else { } else {
// Modify the currently selected feature(s). // Modify the currently selected feature(s).
map.forEachFeatureAtPixel(mapBrowserEvent.pixel, { map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
layerFilter: this.layerFilter_
},
/** /**
* @param {ol.Feature|ol.render.Feature} feature Feature. * @param {ol.Feature|ol.render.Feature} feature Feature.
* @param {ol.layer.Layer} layer Layer. * @param {ol.layer.Layer} layer Layer.
@@ -253,7 +249,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
} }
return !this.multi_; return !this.multi_;
} }
}, this); }, this, {layerFilter: this.layerFilter_});
var j; var j;
for (j = deselected.length - 1; j >= 0; --j) { for (j = deselected.length - 1; j >= 0; --j) {
features.remove(deselected[j]); features.remove(deselected[j]);
+7 -24
View File
@@ -554,26 +554,11 @@ ol.Map.prototype.disposeInternal = function() {
}; };
/**
* @typedef {object} ol.MapForEachFeatureOptions
* @property {(function(this: U, ol.layer.Layer): boolean)=} layerFilter Layer
* filter function. The filter function will receive one argument, the
* {@link ol.layer.Layer layer-candidate} and it should return a boolean
* value. Only layers which are visible and for which this function returns
* `true` will be tested for features. By default, all visible layers will
* be tested.
* @property {U=} layerFilterThis Value to use as `this` when executing `layerFilter`.
* @property {number=} hitTolerance the hitTolerance in pixels in which features
* get hit.
*/
/** /**
* Detect features that intersect a pixel on the viewport, and execute a * Detect features that intersect a pixel on the viewport, and execute a
* callback with each intersecting feature. Layers included in the detection can * callback with each intersecting feature. Layers included in the detection can
* be configured through `opt_layerFilter`. * be configured through `opt_layerFilter`.
* @param {ol.Pixel} pixel Pixel. * @param {ol.Pixel} pixel Pixel.
* @param {ol.MapForEachFeatureOptions=} opt_options
* @param {function(this: S, (ol.Feature|ol.render.Feature), * @param {function(this: S, (ol.Feature|ol.render.Feature),
* ol.layer.Layer): T} callback Feature callback. The callback will be * ol.layer.Layer): T} callback Feature callback. The callback will be
* called with two arguments. The first argument is one * called with two arguments. The first argument is one
@@ -582,27 +567,25 @@ ol.Map.prototype.disposeInternal = function() {
* the {@link ol.layer.Layer layer} of the feature and will be null for * the {@link ol.layer.Layer layer} of the feature and will be null for
* unmanaged layers. To stop detection, callback functions can return a * unmanaged layers. To stop detection, callback functions can return a
* truthy value. * truthy value.
* @param {S=} opt_this * @param {S=} opt_this Value to use as this when executing callback.
* @param {olx.ForEachFeatureOptions=} opt_options Optional options.
* @return {T|undefined} Callback result, i.e. the return value of last * @return {T|undefined} Callback result, i.e. the return value of last
* callback execution, or the first truthy callback return value. * callback execution, or the first truthy callback return value.
* @template S,T,U * @template S,T
* @api stable * @api stable
*/ */
ol.Map.prototype.forEachFeatureAtPixel = function(pixel, opt_options, callback, opt_this) { ol.Map.prototype.forEachFeatureAtPixel = function(pixel, callback, opt_this, opt_options) {
if (typeof opt_options !== 'object') { opt_options = opt_options !== undefined ? opt_options : {};
opt_this = callback;
callback = opt_options;
opt_options = {};
}
if (!this.frameState_) { if (!this.frameState_) {
return; return;
} }
var coordinate = this.getCoordinateFromPixel(pixel); var coordinate = this.getCoordinateFromPixel(pixel);
var hitTolerance = opt_options.hitTolerance || 0;
var thisArg = opt_this !== undefined ? opt_this : null; var thisArg = opt_this !== undefined ? opt_this : null;
var layerFilter = opt_options.layerFilter || ol.functions.TRUE; var layerFilter = opt_options.layerFilter || ol.functions.TRUE;
var thisArg2 = opt_options.layerFilterThis || null; var thisArg2 = opt_options.layerFilterThis || null;
return this.renderer_.forEachFeatureAtCoordinate( return this.renderer_.forEachFeatureAtCoordinate(
coordinate, this.frameState_, opt_options.hitTolerance || 0, callback, thisArg, coordinate, this.frameState_, hitTolerance, callback, thisArg,
layerFilter, thisArg2); layerFilter, thisArg2);
}; };
+18 -11
View File
@@ -69,29 +69,32 @@ ol.render.canvas.ReplayGroup = function(
ol.inherits(ol.render.canvas.ReplayGroup, ol.render.ReplayGroup); ol.inherits(ol.render.canvas.ReplayGroup, ol.render.ReplayGroup);
/** /**
* This methods creates a circle inside an exactly fitting array. Points inside the circle are marked by true, points * This methods creates a circle inside a fitting array. Points inside the
* on the outside are marked with false. * circle are marked by true, points on the outside are marked with false.
* This method uses the midpoint circle algorithm. * It uses the midpoint circle algorithm.
* @param {Number} radius * @param {number} radius Radius.
* @returns {Boolean[][]} * @returns {Array.<Array.<Boolean>>} an array with marked circel points.
* @private * @private
*/ */
ol.render.canvas.ReplayGroup.createPixelCircle_ = function(radius) { ol.render.canvas.ReplayGroup.createPixelCircle_ = function(radius) {
var arraySize = radius * 2 + 1; var arraySize = radius * 2 + 1;
var arr = new Array(arraySize); var arr = new Array(arraySize);
for (var i = 0; i < arraySize; i++) { for (var i = 0; i < arraySize; i++) {
arr[i] = (new Array(arraySize)).fill(false); arr[i] = new Array(arraySize);
for (var j = 0; j < arraySize; j++) {
arr[i][j] = false;
}
} }
function fillRowToMiddle(x, y) { function fillRowToMiddle(x, y) {
var i; var i;
if (x >= radius) { if (x >= radius) {
for (i = radius; i < x; i++) { for (i = radius; i < x; i++) {
arr[i][y] = true arr[i][y] = true;
} }
} else if (x < radius) { } else if (x < radius) {
for (i = x + 1; i < radius; i++) { for (i = x + 1; i < radius; i++) {
arr[i][y] = true arr[i][y] = true;
} }
} }
} }
@@ -112,8 +115,7 @@ ol.render.canvas.ReplayGroup.createPixelCircle_ = function(radius) {
y++; y++;
error += 1 + 2 * y; error += 1 + 2 * y;
if (2 * (error - x) + 1 > 0) if (2 * (error - x) + 1 > 0) {
{
x -= 1; x -= 1;
error += 1 - 2 * x; error += 1 - 2 * x;
} }
@@ -175,7 +177,12 @@ ol.render.canvas.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
ol.extent.buffer(hitExtent, resolution * this.renderBuffer_, hitExtent); ol.extent.buffer(hitExtent, resolution * this.renderBuffer_, hitExtent);
} }
var mask = ol.render.canvas.ReplayGroup.createPixelCircle_(hitTolerance); var mask;
if (hitTolerance === 0) {
mask = [[true]];
} else {
mask = ol.render.canvas.ReplayGroup.createPixelCircle_(hitTolerance);
}
return this.replayHitDetection_(context, transform, rotation, return this.replayHitDetection_(context, transform, rotation,
skippedFeaturesHash, skippedFeaturesHash,
+1 -1
View File
@@ -199,7 +199,7 @@ ol.renderer.Map.prototype.forEachLayerAtPixel = function(pixel, frameState, call
*/ */
ol.renderer.Map.prototype.hasFeatureAtCoordinate = function(coordinate, frameState, layerFilter, thisArg) { ol.renderer.Map.prototype.hasFeatureAtCoordinate = function(coordinate, frameState, layerFilter, thisArg) {
var hasFeature = this.forEachFeatureAtCoordinate( var hasFeature = this.forEachFeatureAtCoordinate(
coordinate, frameState, ol.functions.TRUE, this, layerFilter, thisArg); coordinate, frameState, 0, ol.functions.TRUE, this, layerFilter, thisArg);
return hasFeature !== undefined; return hasFeature !== undefined;
}; };
+2 -2
View File
@@ -213,7 +213,7 @@ ol.renderer.webgl.ImageLayer.prototype.updateProjectionMatrix_ = function(canvas
*/ */
ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) { ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) {
var hasFeature = this.forEachFeatureAtCoordinate( var hasFeature = this.forEachFeatureAtCoordinate(
coordinate, frameState, ol.functions.TRUE, this); coordinate, frameState, 0, ol.functions.TRUE, this);
return hasFeature !== undefined; return hasFeature !== undefined;
}; };
@@ -232,7 +232,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fra
var coordinate = ol.transform.apply( var coordinate = ol.transform.apply(
frameState.pixelToCoordinateTransform, pixel.slice()); frameState.pixelToCoordinateTransform, pixel.slice());
var hasFeature = this.forEachFeatureAtCoordinate( var hasFeature = this.forEachFeatureAtCoordinate(
coordinate, frameState, ol.functions.TRUE, this); coordinate, frameState, 0, ol.functions.TRUE, this);
if (hasFeature) { if (hasFeature) {
return callback.call(thisArg, this.getLayer(), null); return callback.call(thisArg, this.getLayer(), null);
+7 -7
View File
@@ -111,11 +111,11 @@ describe('ol.renderer.canvas.Map', function() {
map.addLayer(layer); map.addLayer(layer);
map.renderSync(); map.renderSync();
var cb = sinon.spy(); var cb = sinon.spy();
map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]), { map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]), cb, null, {
layerFilter: function() { layerFilter: function() {
return false; return false;
} }
}, cb); });
expect(cb).to.not.be.called(); expect(cb).to.not.be.called();
}); });
@@ -151,13 +151,13 @@ describe('ol.renderer.canvas.Map', function() {
]; ];
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
map.forEachFeatureAtPixel(pixelsInside[i], {hitTolerance:10}, cb1); map.forEachFeatureAtPixel(pixelsInside[i], cb1, null, {hitTolerance:10});
} }
expect(cb1.callCount).to.be(4); expect(cb1.callCount).to.be(4);
expect(cb1.firstCall.args[1]).to.be(layer); expect(cb1.firstCall.args[1]).to.be(layer);
for (var j = 0; j < 4; j++) { for (var j = 0; j < 4; j++) {
map.forEachFeatureAtPixel(pixelsOutside[j], {hitTolerance:10}, cb2); map.forEachFeatureAtPixel(pixelsOutside[j], cb2, null, {hitTolerance:10});
} }
expect(cb2).not.to.be.called(); expect(cb2).not.to.be.called();
}); });