Skip to content

Commit 06ae306

Browse files
authored
feat(ngx-layout): Allow zoom levels to be passed to the image-marker
1 parent 33cd9a3 commit 06ae306

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

apps/docs/src/app/pages/docs/angular/layout/implementation/components/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ We can switch between edit mode and view mode by using the `canEdit` Input. Simu
136136

137137
The `stateUpdated` Output will emit whenever a change has been made to the annotations during edit mode, whilst `markerClicked` will emit whenever a marker is clicked during view mode.
138138

139+
By providing both the `zoomLevels` and the `currentZoomLevel` we can adjust how much you can zoom in on to the image, and at which zoom level you wish the image to be.
140+
139141
Additionally, we can pass a set of `markerTypes` we want the MarkerJs package to be restricted to. It's important to know that we need to provide markers for both the view and the edit mode, given they both use different packages and interfaces; being `marker-live` and `markerjs2` respectively.
140142

141143
### Future improvements

apps/layout-test/src/pages/image-marker/image-marker.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
image="assets/klimmuur.webp"
33
imageDescription="Floor-plan of a climbing place"
44
[canEdit]="allowEdit"
5+
[zoomLevels]="[0.5, 1, 1.5, 2]"
6+
[currentZoomLevel]="1.5"
57
[startState]="currentState"
68
(stateUpdated)="updateState($event)"
79
(markerClicked)="markerClicked()"

libs/angular/layout/src/lib/components/image-marker/image-marker.component.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ export class NgxImageMarkerComponent implements AfterViewInit, OnChanges, OnDest
7979
*/
8080
@Input() public canEdit: boolean = true;
8181

82+
/**
83+
* An optional current zoom level
84+
*/
85+
@Input() public currentZoomLevel: number;
86+
87+
/**
88+
* An optional amount of times we can zoom in and out
89+
*/
90+
@Input() public zoomLevels: number[];
91+
8292
/**
8393
* An optional record of types of Markerjs markers we wish to render
8494
*/
@@ -118,7 +128,9 @@ export class NgxImageMarkerComponent implements AfterViewInit, OnChanges, OnDest
118128
this.currentMarker &&
119129
(simpleChangeHasChanged(changes.startState) ||
120130
simpleChangeHasChanged(changes.canEdit) ||
121-
simpleChangeHasChanged(changes.markerTypes));
131+
simpleChangeHasChanged(changes.markerTypes) ||
132+
simpleChangeHasChanged(changes.currentZoomLevel) ||
133+
simpleChangeHasChanged(changes.zoomLevels));
122134

123135
// Iben: Recreate the marker whenever the configuration is adjusted
124136
if (!this.currentMarker || hasChanges) {
@@ -156,6 +168,10 @@ export class NgxImageMarkerComponent implements AfterViewInit, OnChanges, OnDest
156168
allowZoom: true,
157169
defaultState: this.startState || undefined,
158170
markerTypes: this.markerTypes,
171+
zoom:
172+
this.currentZoomLevel !== undefined && this.zoomLevels
173+
? { current: this.currentZoomLevel, levels: this.zoomLevels }
174+
: undefined,
159175
}
160176
);
161177

libs/angular/layout/src/lib/services/image-marker/image-marker.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export class NgxImageMarkerService implements OnDestroy {
144144
// These can later on be extended when needed
145145
marker.uiStyleSettings.zoomButtonVisible = configuration.allowZoom;
146146
marker.uiStyleSettings.zoomOutButtonVisible = configuration.allowZoom;
147+
marker.zoomSteps = configuration.zoom?.levels || [1, 2, 3, 4];
148+
marker.zoomLevel = configuration.zoom?.current ?? 1;
147149
marker.uiStyleSettings.clearButtonVisible = configuration.allowClear;
148150

149151
// Iben: Set the available marker types

libs/angular/layout/src/lib/types/image-marker.types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ export interface NgxImageMarkerConfiguration {
4444
* An optional set of allowed marker types, by default all
4545
*/
4646
markerTypes?: NgxImageMarkerTypes;
47+
48+
/**
49+
* An optional set of allowed marker types, by default the levels are [1,2,3,4] and the current zoom is 1
50+
*/
51+
zoom?: {
52+
levels: number[];
53+
current: number;
54+
};
4755
}
4856

4957
interface NgxImageMarkerBase {

0 commit comments

Comments
 (0)