Merge pull request #9983 from KlausBenndorf/get-features-returns-array

getFeaturesAtPixel always returns array
This commit is contained in:
Tim Schaub
2019-09-24 17:32:45 +02:00
committed by GitHub
4 changed files with 14 additions and 10 deletions
+4
View File
@@ -279,6 +279,10 @@ The `getGetFeatureInfoUrl` of `ol/source/ImageWMS` and `ol/source/TileWMS` is no
The `SelectInteraction` is removed. There are two examples ([Select Features by Hover](https://openlayers.org/en/master/examples/select-hover-features.html) and [Select multiple Features](https://openlayers.org/en/master/examples/select-multiple-features.html) which show how similar results can be achieved by using more basic methods. The `SelectInteraction` is removed. There are two examples ([Select Features by Hover](https://openlayers.org/en/master/examples/select-hover-features.html) and [Select multiple Features](https://openlayers.org/en/master/examples/select-multiple-features.html) which show how similar results can be achieved by using more basic methods.
##### `getFeatureAtPixel` returns always an array
`getFeatureAtPixel` returns now an empty array instead of `null` if no features were found.
#### Other changes #### Other changes
##### Allow declutter in image render mode ##### Allow declutter in image render mode
+2 -5
View File
@@ -562,15 +562,12 @@ class PluggableMap extends BaseObject {
* @param {import("./pixel.js").Pixel} pixel Pixel. * @param {import("./pixel.js").Pixel} pixel Pixel.
* @param {AtPixelOptions=} opt_options Optional options. * @param {AtPixelOptions=} opt_options Optional options.
* @return {Array<import("./Feature.js").FeatureLike>} The detected features or * @return {Array<import("./Feature.js").FeatureLike>} The detected features or
* `null` if none were found. * an empty array if none were found.
* @api * @api
*/ */
getFeaturesAtPixel(pixel, opt_options) { getFeaturesAtPixel(pixel, opt_options) {
let features = null; const features = [];
this.forEachFeatureAtPixel(pixel, function(feature) { this.forEachFeatureAtPixel(pixel, function(feature) {
if (!features) {
features = [];
}
features.push(feature); features.push(feature);
}, opt_options); }, opt_options);
return features; return features;
+6 -4
View File
@@ -279,9 +279,10 @@ describe('ol.Map', function() {
document.body.removeChild(target); document.body.removeChild(target);
}); });
it('returns null if no feature was found', function() { it('returns an empty array if no feature was found', function() {
const features = map.getFeaturesAtPixel([0, 0]); const features = map.getFeaturesAtPixel([0, 0]);
expect(features).to.be(null); expect(features).to.be.an(Array);
expect(features).to.be.empty();
}); });
it('returns an array of found features', function() { it('returns an array of found features', function() {
@@ -311,10 +312,11 @@ describe('ol.Map', function() {
map.addLayer(otherLayer); map.addLayer(otherLayer);
const features = map.getFeaturesAtPixel([50, 50], { const features = map.getFeaturesAtPixel([50, 50], {
layerFilter: function(layer) { layerFilter: function(layer) {
return layer == otherLayer; return layer === otherLayer;
} }
}); });
expect(features).to.be(null); expect(features).to.be.an(Array);
expect(features).to.be.empty();
}); });
}); });
@@ -369,7 +369,8 @@ describe('ol.renderer.canvas.VectorTileLayer', function() {
const features = map.getFeaturesAtPixel([96, 96]); const features = map.getFeaturesAtPixel([96, 96]);
document.body.removeChild(target); document.body.removeChild(target);
map.dispose(); map.dispose();
expect(features).to.be(null); expect(features).to.be.an(Array);
expect(features).to.be.empty();
done(); done();
}, 200); }, 200);
}); });