diff --git a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts index 1b17f7a01c..708d041864 100644 --- a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts +++ b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts @@ -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) */ @@ -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) => { @@ -334,13 +339,14 @@ 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; @@ -348,6 +354,7 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr return style; } }); + this.modifyControl = new ModifyControl(controlOptions); } /** diff --git a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field.component.html b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field.component.html index a98a513726..7aae3f5efa 100644 --- a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field.component.html +++ b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field.component.html @@ -6,6 +6,7 @@ [measure]="measure" [drawControlIsActive]="drawControlIsActive" [freehandDrawIsActive]="freehandDrawIsActive" + [controlOptions]="controlOptions" [drawStyle]="drawStyle" [overlayStyle]="overlayStyle"> diff --git a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field.component.ts b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field.component.ts index 5aaeaed02b..454c33a466 100644 --- a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field.component.ts +++ b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field.component.ts @@ -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) */ diff --git a/packages/geo/src/lib/geometry/shared/controls/modify.ts b/packages/geo/src/lib/geometry/shared/controls/modify.ts index 8bf4453765..31a1cdbf6d 100644 --- a/packages/geo/src/lib/geometry/shared/controls/modify.ts +++ b/packages/geo/src/lib/geometry/shared/controls/modify.ts @@ -33,6 +33,8 @@ export interface ModifyControlOptions { layer?: OlVectorLayer; layerStyle?: OlStyle | ((olfeature: OlFeature) => OlStyle); drawStyle?: OlStyle | ((olfeature: OlFeature) => OlStyle); + modify?: boolean; + translate?: boolean; } /** @@ -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 { @@ -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(); + } } /**