Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 68 additions & 6 deletions projects/ngx-openlayers/src/lib/interactions/default.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
import { Component, Input, OnChanges, OnDestroy, OnInit, inject } from '@angular/core';
import { defaults, Interaction } from 'ol/interaction';
import { Collection } from 'ol';
import { MapComponent } from '../map.component';
Expand All @@ -8,17 +8,79 @@ import { MapComponent } from '../map.component';
template: '',
standalone: true,
})
export class DefaultInteractionComponent implements OnInit, OnDestroy {
export class DefaultInteractionComponent implements OnInit, OnChanges, OnDestroy {
private map = inject(MapComponent);

instance: Collection<Interaction>;
@Input()
altShiftDragRotate?: boolean | undefined;
@Input()
doubleClickZoom?: boolean | undefined;
@Input()
keyboard?: boolean | undefined;
@Input()
mouseWheelZoom?: boolean | undefined;
@Input()
shiftDragZoom?: boolean | undefined;
@Input()
dragPan?: boolean | undefined;
@Input()
pinchRotate?: boolean | undefined;
@Input()
pinchZoom?: boolean | undefined;
@Input()
onFocusOnly?: boolean | undefined;
@Input()
zoomDelta?: number | undefined;
@Input()
zoomDuration?: number | undefined;


ngOnInit(): void {
this.instance = defaults();
this.instance.forEach((i) => this.map.instance.addInteraction(i));
this.instance = defaults({
altShiftDragRotate: this.altShiftDragRotate,
doubleClickZoom: this.doubleClickZoom,
keyboard: this.keyboard,
mouseWheelZoom: this.mouseWheelZoom,
shiftDragZoom: this.shiftDragZoom,
dragPan: this.dragPan,
pinchRotate: this.pinchRotate,
pinchZoom: this.pinchZoom,
onFocusOnly: this.onFocusOnly,
zoomDelta: this.zoomDelta,
zoomDuration: this.zoomDuration,
});
if (this.map.instance) {
this.instance.forEach((i) => this.map.instance.addInteraction(i));
}
}

ngOnChanges() {
if (this.instance) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the following:

if (this.instance && this.map.instance) {
      this.instance.forEach((i) => this.map.instance.removeInteraction(i));
}
this.instance = defaults({
  ...
});
if (this.map.instance) {
  this.instance.forEach((i) => this.map.instance.addInteraction(i));
}

if (this.map.instance) {
this.instance.forEach((i) => this.map.instance.removeInteraction(i));
}
this.instance = defaults({
altShiftDragRotate: this.altShiftDragRotate,
doubleClickZoom: this.doubleClickZoom,
keyboard: this.keyboard,
mouseWheelZoom: this.mouseWheelZoom,
shiftDragZoom: this.shiftDragZoom,
dragPan: this.dragPan,
pinchRotate: this.pinchRotate,
pinchZoom: this.pinchZoom,
onFocusOnly: this.onFocusOnly,
zoomDelta: this.zoomDelta,
zoomDuration: this.zoomDuration,
});
if (this.map.instance) {
this.instance.forEach((i) => this.map.instance.addInteraction(i));
}
}
}

ngOnDestroy(): void {
this.instance.forEach((i) => this.map.instance.removeInteraction(i));
if (this.map.instance) {
this.instance.forEach((i) => this.map.instance.removeInteraction(i));
}
}
}
2 changes: 2 additions & 0 deletions src/app/app.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ImageStaticComponent } from './image-static/image-static.component';
import { GraticuleComponent } from './graticule/graticule.component';
import { SnapInteractionComponent } from './snap-interaction/snap-interaction.component';
import { StylesCompositionComponent } from './styles/styles-composition.component';
import { DefaultInteractionComponent } from './default-interaction/default-interaction.component';

export const routes: Routes = [
{ path: '', component: ExamplesListComponent },
Expand All @@ -34,6 +35,7 @@ export const routes: Routes = [
component: ExamplesItemComponent,
children: [
{ path: 'simple', component: SimpleComponent },
{ path: 'default-interaction', component: DefaultInteractionComponent },
{ path: 'map-position', component: MapPositionComponent },
{ path: 'cursor-position', component: CursorPositionComponent },
{ path: 'display-geometry', component: DisplayGeometryComponent },
Expand Down
138 changes: 138 additions & 0 deletions src/app/default-interaction/default-interaction.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { Component } from '@angular/core';
import {
CoordinateComponent,
DefaultInteractionComponent as NgxOlDefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
ViewComponent,
} from 'ngx-openlayers';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@Component({
selector: 'app-default-interaction',
template: `
<div>
<aol-map #map width="100%" height="100%">
<aol-interaction-default
[altShiftDragRotate]="altShiftDragRotate"
[doubleClickZoom]="doubleClickZoom"
[keyboard]="keyboard"
[mouseWheelZoom]="mouseWheelZoom"
[shiftDragZoom]="shiftDragZoom"
[dragPan]="dragPan"
[pinchRotate]="pinchRotate"
[pinchZoom]="pinchZoom"
[onFocusOnly]="onFocusOnly"
[zoomDelta]="zoomDelta"
[zoomDuration]="zoomDuration"
>
</aol-interaction-default>
<aol-view [zoom]="5">
<aol-coordinate [x]="1.4886" [y]="43.5554" [srid]="'EPSG:4326'"></aol-coordinate>
</aol-view>

<aol-layer-tile [opacity]="1">
<aol-source-osm></aol-source-osm>
</aol-layer-tile>
</aol-map>
<div class="options">
<h2>Options</h2>
<form>
<div>
<label for="altShiftDragRotate">Alt shift drag rotate</label>
<input id="altShiftDragRotate" type="checkbox" [(ngModel)]="altShiftDragRotate" />
</div>
<div>
<label for="doubleClickZoom">Double click zoom</label>
<input id="doubleClickZoom" type="checkbox" [(ngModel)]="doubleClickZoom" />
</div>
<div>
<label for="keyboard">Keyboard</label>
<input id="keyboard" type="checkbox" [(ngModel)]="keyboard" />
</div>
<div>
<label for="mouseWheelZoom">Mouse wheel zoom</label>
<input id="mouseWheelZoom" type="checkbox" [(ngModel)]="mouseWheelZoom" />
</div>
<div>
<label for="shiftDragZoom">Alt shift drag rotate</label>
<input id="shiftDragZoom" type="checkbox" [(ngModel)]="shiftDragZoom" />
</div>
<div>
<label for="dragPan">Drag Pan</label>
<input id="dragPan" type="checkbox" [(ngModel)]="dragPan" />
</div>
<div>
<label for="pinchRotate">Pinch rotate</label>
<input id="pinchRotate" type="checkbox" [(ngModel)]="pinchRotate" />
</div>
<div>
<label for="pinchZoom">Pinch zoom</label>
<input id="pinchZoom" type="checkbox" [(ngModel)]="pinchZoom" />
</div>
<div>
<label for="onFocusOnly">On focus only</label>
<input id="onFocusOnly" type="checkbox" [(ngModel)]="onFocusOnly" />
</div>
<div>
<label for="zoomDelta">Zoom delta</label>
<input id="zoomDelta" type="number" [(ngModel)]="zoomDelta" />
</div>
<div>
<label for="zoomDuration">Zoom duration (ms)</label>
<input id="zoomDuration" type="number" [(ngModel)]="zoomDuration" />
</div>
</form>
</div>
</div>
`,
styles: [
`
div {
height: 100%;
display: flex;
}

aol-map {
width: 70%;
}

.options {
width: 28%;
padding: 1rem;
display: block;
flex-direction: column;
}

.options div {
display: flex;
justify-content: space-between;
}
`,
],

imports: [
MapComponent,
NgxOlDefaultInteractionComponent,
ViewComponent,
CoordinateComponent,
LayerTileComponent,
SourceOsmComponent,
ReactiveFormsModule,
FormsModule,
],
})
export class DefaultInteractionComponent {
altShiftDragRotate = true;
doubleClickZoom = true;
keyboard = true;
mouseWheelZoom = true;
shiftDragZoom = true;
dragPan = true;
pinchRotate = true;
pinchZoom = true;
onFocusOnly = true;
zoomDelta = 1;
zoomDuration = 250;
}
5 changes: 5 additions & 0 deletions src/app/example-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export const examplesList = [
routerLink: 'simple',
openLayersLink: 'https://openlayers.org/en/latest/examples/simple.html',
},
{
title: 'Default interaction',
description: 'Manage default interaction with options',
routerLink: 'default-interaction',
},
{
title: 'Map position',
description: 'Map longitude, latitude and zoom.',
Expand Down
Loading