Merge pull request #4117 from pgiraud/foreachfeatureatcoordinate_nosource
forEachFeatureAtPixel shouldn't fail if layer has no source
This commit is contained in:
@@ -170,9 +170,11 @@ ol.renderer.Map.prototype.forEachFeatureAtCoordinate =
|
||||
(ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
|
||||
layerFilter.call(thisArg2, layer))) {
|
||||
var layerRenderer = this.getLayerRenderer(layer);
|
||||
result = layerRenderer.forEachFeatureAtCoordinate(
|
||||
layer.getSource().getWrapX() ? translatedCoordinate : coordinate,
|
||||
frameState, callback, thisArg);
|
||||
if (!goog.isNull(layer.getSource())) {
|
||||
result = layerRenderer.forEachFeatureAtCoordinate(
|
||||
layer.getSource().getWrapX() ? translatedCoordinate : coordinate,
|
||||
frameState, callback, thisArg);
|
||||
}
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -58,12 +58,21 @@ describe('ol.renderer.canvas.Map', function() {
|
||||
it('filters managed layers', function() {
|
||||
map.addLayer(layer);
|
||||
map.renderSync();
|
||||
cb = sinon.spy();
|
||||
var cb = sinon.spy();
|
||||
map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]), cb, null,
|
||||
function() { return false; });
|
||||
expect(cb).to.not.be.called();
|
||||
});
|
||||
|
||||
it('doesn\'t fail with layer with no source', function() {
|
||||
map.addLayer(new ol.layer.Tile());
|
||||
map.renderSync();
|
||||
expect(function() {
|
||||
map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]),
|
||||
function() {});
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#renderFrame()', function() {
|
||||
@@ -92,6 +101,7 @@ goog.require('ol.Feature');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.renderer.canvas.Layer');
|
||||
goog.require('ol.renderer.canvas.Map');
|
||||
|
||||
Reference in New Issue
Block a user