Skip to content

Commit

Permalink
Merge pull request #2 from acaprojects/feature/lock
Browse files Browse the repository at this point in the history
feat: add lock feature
  • Loading branch information
alexchuvand authored Nov 10, 2020
2 parents 0be18e8 + 5919cbe commit 6add9d3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[(zoom)]="zoom"
(zoomChange)="updateZoom($event)"
[(center)]="center"
[lock]="lock"
(centerChange)="updateCenter($event)"
[map]="map"
[element]="map_element"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export class MapOutletComponent implements OnInit, OnChanges, OnDestroy {
@Input() public listeners: MapListener[] = [];
/** List of text to render over the map */
@Input() public text: MapRenderFeature[] = [];
/** Whether Map cannot be moved */
@Input() public lock: boolean;
/** Emitter for changes to the zoom value */
@Output() public zoomChange = new EventEmitter<number>();
/** Emitter for changes to the center value */
Expand Down
1 change: 1 addition & 0 deletions projects/library/src/lib/components/map/map.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
[listeners]="listeners"
[text]="text_list"
[class.locked]="options?.lock"
[lock]="lock"
></a-map-outlet>
2 changes: 2 additions & 0 deletions projects/library/src/lib/components/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
@Input() public focus: string | Point;
/** Optional flags for the map */
@Input() public options: MapOptions;
/** Whether Map cannot be moved */
@Input() public lock: boolean;
/** Emitter for changes to the zoom value */
@Output() public zoomChange = new EventEmitter<number>();
/** Emitter for changes to the center value */
Expand Down
7 changes: 7 additions & 0 deletions projects/library/src/lib/directives/map-center.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export class MapCenterDirective implements OnDestroy {
@Input() public center: Point;
/** Element containing the map */
@Input() public element: ElementRef<HTMLDivElement>;
/** Lock Map */
@Input() public lock: boolean;
/** Emitter for changes to the center value */
@Output() public centerChange = new EventEmitter<Point>();
/** Bound box of the host element */
Expand All @@ -44,11 +46,13 @@ export class MapCenterDirective implements OnDestroy {

@HostListener('mousedown', ['$event'])
public startMoveMouse(event: MouseEvent) {
if (this.lock) { return; }
this.startMove(event);
}

@HostListener('touchstart', ['$event'])
public startMoveTouch(event: any) {
if (this.lock) { return; }
this.startMove(event);
}

Expand Down Expand Up @@ -103,6 +107,9 @@ export class MapCenterDirective implements OnDestroy {
*/
private move(event: MouseEvent | TouchEvent) {
if (!this._box) { return; }
if (this.lock) {
return;
}
const position = eventToPoint(event);
if (!insideRect(position, this._parent_box)) { return; }
event.preventDefault();
Expand Down

0 comments on commit 6add9d3

Please sign in to comment.