Skip to content

Commit

Permalink
fix(geometry): properly compute the draw guide style when the draw st…
Browse files Browse the repository at this point in the history
…yle is an array
  • Loading branch information
cbourget authored and mbarbeau committed Aug 7, 2020
1 parent bb0e1bd commit 8087029
Showing 1 changed file with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr
value = createDrawInteractionStyle();
}
this._drawStyle = value;
if (value && this.isStyleWithRadius(value)) {
this.defaultDrawStyleRadius = value.getImage().getRadius();

var olGuideStyle = this.getGuideStyleFromDrawStyle(value);
if (olGuideStyle !== undefined) {
this.defaultDrawStyleRadius = olGuideStyle.getImage().getRadius();
} else {
this.defaultDrawStyleRadius = null;
}
Expand Down Expand Up @@ -545,16 +547,19 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr
* @param resolution Resolution (to make the screen size of symbol fit the drawGuide value)
*/
private updateDrawStyleWithDrawGuide(olStyle: OlStyle, resolution: number) {
if (this.isStyleWithRadius(olStyle)) {
const drawGuide = this.drawGuide;
let radius;
if (!drawGuide || drawGuide < 0) {
radius = this.defaultDrawStyleRadius;
} else {
radius = drawGuide > 0 ? drawGuide / resolution : drawGuide;
}
olStyle.getImage().setRadius(radius);
var olGuideStyle = this.getGuideStyleFromDrawStyle(olStyle);
if (olGuideStyle === undefined) {
return;
}

const drawGuide = this.drawGuide;
let radius;
if (!drawGuide || drawGuide < 0) {
radius = this.defaultDrawStyleRadius;
} else {
radius = drawGuide > 0 ? drawGuide / resolution : drawGuide;
}
olGuideStyle.getImage().setRadius(radius);
}

/**
Expand All @@ -564,4 +569,18 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr
private isStyleWithRadius(olStyle: OlStyle): boolean {
return typeof olStyle !== 'function' && olStyle.getImage && olStyle.getImage().setRadius;
}

/**
* Returns wether a given Open Layers style has a radius property that can be set (used to set draw guide)
* @param olStyle The style on which to perform the check
*/
private getGuideStyleFromDrawStyle(olStyle: OlStyle | OlStyle[]): OlStyle {
if (Array.isArray(olStyle)) {
olStyle = olStyle[0];
}
if (this.isStyleWithRadius(olStyle)) {
return olStyle;
}
return undefined;
}
}

0 comments on commit 8087029

Please sign in to comment.