Skip to content

Commit

Permalink
feat(geometry): allow control options to be passed and translation to…
Browse files Browse the repository at this point in the history
… be disabled
  • Loading branch information
cbourget authored and mbarbeau committed Aug 7, 2020
1 parent cb7c1b9 commit 61835ab
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr
}
private _freehandDrawIsActive: boolean;

/**
* Control options
*/
@Input() controlOptions: {[key: string]: any} = {};

/**
* Style for the draw control (applies while the geometry is being drawn)
*/
Expand Down Expand Up @@ -325,7 +330,7 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr
* Create a draw control and subscribe to it's geometry
*/
private createDrawControl() {
this.drawControl = new DrawControl({
const controlOptions = Object.assign({}, this.controlOptions, {
geometryType: this.geometryType || 'Point',
layer: this.olOverlayLayer,
drawStyle: typeof this.drawStyle === 'function' ? this.drawStyle : (olFeature: OlFeature, resolution: number) => {
Expand All @@ -334,20 +339,22 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr
return style;
}
});
this.drawControl = new DrawControl(controlOptions);
}

/**
* Create a modify control and subscribe to it's geometry
*/
private createModifyControl() {
this.modifyControl = new ModifyControl({
const controlOptions = Object.assign({}, this.controlOptions, {
layer: this.olOverlayLayer,
drawStyle: typeof this.drawStyle === 'function' ? this.drawStyle : (olFeature: OlFeature, resolution: number) => {
const style = this.drawStyle;
this.updateDrawStyleWithDrawGuide(style, resolution);
return style;
}
});
this.modifyControl = new ModifyControl(controlOptions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[measure]="measure"
[drawControlIsActive]="drawControlIsActive"
[freehandDrawIsActive]="freehandDrawIsActive"
[controlOptions]="controlOptions"
[drawStyle]="drawStyle"
[overlayStyle]="overlayStyle">
</igo-geometry-form-field-input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export class GeometryFormFieldComponent implements OnInit, OnDestroy {
*/
@Input() measure: boolean = false;

/**
* Control options
*/
@Input() controlOptions: {[key: string]: any} = {};

/**
* Style for the draw control (applies while the geometry is being drawn)
*/
Expand Down
38 changes: 33 additions & 5 deletions packages/geo/src/lib/geometry/shared/controls/modify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface ModifyControlOptions {
layer?: OlVectorLayer;
layerStyle?: OlStyle | ((olfeature: OlFeature) => OlStyle);
drawStyle?: OlStyle | ((olfeature: OlFeature) => OlStyle);
modify?: boolean;
translate?: boolean;
}

/**
Expand Down Expand Up @@ -108,7 +110,24 @@ export class ModifyControl {
return this.olLinearRingsLayer.getSource();
}

/**
* Whether a modify control should be available
*/
private modify: boolean = true;

/**
* Whether a translate control should be available
*/
private translate: boolean = true;

constructor(private options: ModifyControlOptions) {
if (options.modify !== undefined) {
this.modify = options.modify;
}
if (options.translate !== undefined) {
this.translate = options.translate;
}

if (options.layer !== undefined) {
this.olOverlayLayer = options.layer;
} else {
Expand All @@ -134,11 +153,20 @@ export class ModifyControl {

this.olMap = olMap;
this.addOlInnerOverlayLayer();
this.addOlDrawInteraction();
this.addOlTranslateInteraction();
this.activateTranslateInteraction();
this.addOlModifyInteraction();
this.activateModifyInteraction();

if (this.modify === true) {
this.addOlDrawInteraction();
}

if (this.translate === true) {
this.addOlTranslateInteraction();
this.activateTranslateInteraction();
}

if (this.modify === true) {
this.addOlModifyInteraction();
this.activateModifyInteraction();
}
}

/**
Expand Down

0 comments on commit 61835ab

Please sign in to comment.