Changes for the CircleStyle inconsistency seen in #9395

Change hit detection test to reflect fix for #9395 CircleStyle inconsistency

Update ol/style/Circle and ol/style/RegularShapen tests
Revise test for no fill
Add test for transparent fill

Update Upgrade notes
Changes to hit detection with unfilled styles
This commit is contained in:
mike-000
2019-09-25 21:17:58 +01:00
parent e1d9f8dd59
commit e28fa56edd
5 changed files with 73 additions and 20 deletions

View File

@@ -2,6 +2,7 @@
* @module ol/style/RegularShape
*/
import {asArray} from '../color.js';
import {asColorLike} from '../colorlike.js';
import {createCanvasContext2D} from '../dom.js';
import ImageState from '../ImageState.js';
@@ -429,17 +430,31 @@ class RegularShape extends ImageStyle {
*/
createHitDetectionCanvas_(renderOptions) {
this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size];
this.hitDetectionCanvas_ = this.canvas_;
if (this.fill_) {
this.hitDetectionCanvas_ = this.canvas_;
return;
let color = this.fill_.getColor();
// determine if fill is transparent (or pattern or gradient)
let opacity = 0;
if (typeof color === 'string') {
color = asArray(color);
}
if (color === null) {
opacity = 1;
} else if (Array.isArray(color)) {
opacity = color.length === 4 ? color[3] : 1;
}
if (opacity === 0) {
// if a transparent fill style is set, create an extra hit-detection image
// with a default fill style
const context = createCanvasContext2D(renderOptions.size, renderOptions.size);
this.hitDetectionCanvas_ = context.canvas;
this.drawHitDetectionCanvas_(renderOptions, context, 0, 0);
}
}
// if no fill style is set, create an extra hit-detection image with a
// default fill style
const context = createCanvasContext2D(renderOptions.size, renderOptions.size);
this.hitDetectionCanvas_ = context.canvas;
this.drawHitDetectionCanvas_(renderOptions, context, 0, 0);
}
/**