Use declutter tree only for text and image replays
This commit is contained in:
@@ -34,6 +34,11 @@ var _ol_render_canvas_ReplayGroup_ = function(
|
||||
tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree, opt_renderBuffer) {
|
||||
_ol_render_ReplayGroup_.call(this);
|
||||
|
||||
/**
|
||||
* @type {ol.render.ReplayType}
|
||||
*/
|
||||
this.currentReplayType_;
|
||||
|
||||
/**
|
||||
* Declutter tree.
|
||||
* @private
|
||||
@@ -325,15 +330,18 @@ _ol_render_canvas_ReplayGroup_.prototype.forEachFeatureAtCoordinate = function(
|
||||
/**
|
||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
* @this {ol.render.canvas.ReplayGroup}
|
||||
*/
|
||||
function hitDetectionCallback(feature) {
|
||||
var hitDetectionCallback = (function(feature) {
|
||||
var imageData = context.getImageData(0, 0, contextSize, contextSize).data;
|
||||
for (var i = 0; i < contextSize; i++) {
|
||||
for (var j = 0; j < contextSize; j++) {
|
||||
if (mask[i][j]) {
|
||||
if (imageData[(j * contextSize + i) * 4 + 3] > 0) {
|
||||
var replayType = this.currentReplayType_;
|
||||
var result;
|
||||
if (!declutteredFeatures || declutteredFeatures.indexOf(feature) !== -1) {
|
||||
if (!(declutteredFeatures && (replayType == ReplayType.IMAGE || replayType == ReplayType.TEXT)) ||
|
||||
declutteredFeatures.indexOf(feature) !== -1) {
|
||||
result = callback(feature);
|
||||
}
|
||||
if (result) {
|
||||
@@ -346,7 +354,7 @@ _ol_render_canvas_ReplayGroup_.prototype.forEachFeatureAtCoordinate = function(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).bind(this);
|
||||
|
||||
return this.replayHitDetection_(context, transform, rotation,
|
||||
skippedFeaturesHash, hitDetectionCallback, hitExtent, declutterReplays);
|
||||
@@ -498,6 +506,7 @@ _ol_render_canvas_ReplayGroup_.prototype.replayHitDetection_ = function(
|
||||
declutter.push(replay, transform.slice(0));
|
||||
}
|
||||
} else {
|
||||
this.currentReplayType_ = replayType;
|
||||
result = replay.replayHitDetection(context, transform, viewRotation,
|
||||
skippedFeaturesHash, featureCallback, opt_hitExtent);
|
||||
if (result) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import Map from '../../../src/ol/Map.js';
|
||||
import MapEvent from '../../../src/ol/MapEvent.js';
|
||||
import Overlay from '../../../src/ol/Overlay.js';
|
||||
import _ol_View_ from '../../../src/ol/View.js';
|
||||
import Point from '../../../src/ol/geom/Point.js';
|
||||
import LineString from '../../../src/ol/geom/LineString.js';
|
||||
import _ol_has_ from '../../../src/ol/has.js';
|
||||
import {defaults as defaultInteractions} from '../../../src/ol/interaction.js';
|
||||
import DoubleClickZoom from '../../../src/ol/interaction/DoubleClickZoom.js';
|
||||
@@ -197,12 +197,12 @@ describe('ol.Map', function() {
|
||||
target: target,
|
||||
layers: [new _ol_layer_Vector_({
|
||||
source: new _ol_source_Vector_({
|
||||
features: [new _ol_Feature_(new Point([0, 0]))]
|
||||
features: [new _ol_Feature_(new LineString([[-50, 0], [50, 0]]))]
|
||||
})
|
||||
})],
|
||||
view: new _ol_View_({
|
||||
center: [0, 0],
|
||||
zoom: 2
|
||||
zoom: 17
|
||||
})
|
||||
});
|
||||
map.renderSync();
|
||||
@@ -222,6 +222,20 @@ describe('ol.Map', function() {
|
||||
expect(features[0]).to.be.an(_ol_Feature_);
|
||||
});
|
||||
|
||||
it('returns an array of found features with declutter: true', function() {
|
||||
var layer = map.getLayers().item(0);
|
||||
map.removeLayer(layer);
|
||||
var otherLayer = new _ol_layer_Vector_({
|
||||
declutter: true,
|
||||
source: layer.getSource()
|
||||
});
|
||||
map.addLayer(otherLayer);
|
||||
map.renderSync();
|
||||
var features = map.getFeaturesAtPixel([50, 50]);
|
||||
expect(features).to.be.an(Array);
|
||||
expect(features[0]).to.be.an(_ol_Feature_);
|
||||
});
|
||||
|
||||
it('respects options', function() {
|
||||
var otherLayer = new _ol_layer_Vector_({
|
||||
source: new _ol_source_Vector_
|
||||
|
||||
Reference in New Issue
Block a user