Skip to content

Commit

Permalink
fix(rotation): add rotation button (#261)
Browse files Browse the repository at this point in the history
* feat(map) acces to view rotation

* feat(map) rotation button to reset view  rotation (if map rotated)

* feat(demo) map rotation & rotation button

* refactor(radio-button) Cleaning component

* refactor(igo-rotation-button) Placement on top

* feat(rotation-button) Provide rotation to button. Pointing to "north"

* refactor(rotation-button) rotationClass to rotationStyle

* refactor(rotation-button) degree to radians

* Update rotation-button.component.ts
  • Loading branch information
pelord authored and mbarbeau committed Feb 15, 2019
1 parent a8c8394 commit 039ae62
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 3 deletions.
1 change: 1 addition & 0 deletions demo/src/app/context/context/context.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
(query)="handleQueryResults($event)">
<igo-zoom-button [map]="map" color="primary"></igo-zoom-button>
<igo-geolocate-button [map]="map" color="primary"></igo-geolocate-button>
<igo-rotation-button [map]="map" color="primary"></igo-rotation-button>
</igo-map-browser>

<igo-panel title="Contexts list">
Expand Down
1 change: 1 addition & 0 deletions demo/src/app/geo/directions/directions.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<igo-map-browser [map]="map" [view]="view">
<igo-zoom-button [map]="map" color="primary"></igo-zoom-button>
<igo-geolocate-button [map]="map" color="primary"></igo-geolocate-button>
<igo-rotation-button [map]="map" color="primary"></igo-rotation-button>
</igo-map-browser>

<igo-routing-form [map]="map"></igo-routing-form>
Expand Down
1 change: 1 addition & 0 deletions demo/src/app/geo/print/print.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<igo-map-browser [map]="map" [view]="view">
<igo-zoom-button [map]="map" color="primary"></igo-zoom-button>
<igo-geolocate-button [map]="map" color="primary"></igo-geolocate-button>
<igo-rotation-button [map]="map" color="primary"></igo-rotation-button>
</igo-map-browser>

<igo-print [map]="map"></igo-print>
Expand Down
1 change: 1 addition & 0 deletions demo/src/app/geo/simple-map/simple-map.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<igo-map-browser [map]="map" [view]="view">
<igo-zoom-button [map]="map" color="primary"></igo-zoom-button>
<igo-geolocate-button [map]="map" color="primary"></igo-geolocate-button>
<igo-rotation-button [map]="map" color="primary"></igo-rotation-button>
</igo-map-browser>

</mat-card>
3 changes: 2 additions & 1 deletion demo/src/app/geo/simple-map/simple-map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class AppSimpleMapComponent {

public view = {
center: [-73, 47.2],
zoom: 6
zoom: 6,
rotation: 0.75
};

constructor(
Expand Down
1 change: 1 addition & 0 deletions projects/geo/src/lib/map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './map-browser';
export * from './zoom-button';
export * from './geolocate-button';
export * from './baselayers-switcher';
export * from './rotation-button';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
}
}

:host >>> igo-rotation-button {
position: absolute;
top: calc(#{$igo-icon-size} + 5px + #{$igo-margin});
right: $igo-margin;
@include mobile {
top: calc(#{$igo-icon-size} + 5px + #{$igo-margin});
}
}

:host >>> igo-user-button {
position: absolute;
bottom: $igo-margin;
Expand Down
3 changes: 3 additions & 0 deletions projects/geo/src/lib/map/map.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MapBrowserBindingDirective } from './map-browser/map-browser-binding.di
import { MapBrowserComponent } from './map-browser/map-browser.component';
import { ZoomButtonComponent } from './zoom-button/zoom-button.component';
import { GeolocateButtonComponent } from './geolocate-button/geolocate-button.component';
import { RotationButtonComponent } from './rotation-button/rotation-button.component';
import { BaseLayersSwitcherComponent } from './baselayers-switcher/baselayers-switcher.component';
import { MiniBaseMapComponent } from './baselayers-switcher/mini-basemap.component';

Expand All @@ -31,6 +32,7 @@ import { MiniBaseMapComponent } from './baselayers-switcher/mini-basemap.compone
MapBrowserBindingDirective,
ZoomButtonComponent,
GeolocateButtonComponent,
RotationButtonComponent,
BaseLayersSwitcherComponent,
MiniBaseMapComponent
],
Expand All @@ -39,6 +41,7 @@ import { MiniBaseMapComponent } from './baselayers-switcher/mini-basemap.compone
MapBrowserBindingDirective,
ZoomButtonComponent,
GeolocateButtonComponent,
RotationButtonComponent,
BaseLayersSwitcherComponent,
MiniBaseMapComponent
]
Expand Down
1 change: 1 addition & 0 deletions projects/geo/src/lib/map/rotation-button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './rotation-button.component';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="igo-rotation-button-container">
<button
*ngIf="map.getRotation() !== 0"
mat-icon-button
[matTooltip]="'igo.geo.mapButtons.resetRotation' | translate"
matTooltipPosition="left"
[color]="color"
(click)="map.resetRotation()">
<mat-icon [ngStyle]="rotationStyle(map.getRotation())">
navigation
</mat-icon>
</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import '../../../../../core/src/style/partial/core.variables';

.igo-rotation-button-container {
width: $igo-icon-size;
background-color: #fff;
&:hover {
background-color: #efefef;
}
}

button,
:host >>> button .mat-button-ripple-round {
border-radius: 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Component, Input } from '@angular/core';

import { IgoMap } from '../shared/map';

@Component({
selector: 'igo-rotation-button',
templateUrl: './rotation-button.component.html',
styleUrls: ['./rotation-button.component.scss']
})
export class RotationButtonComponent {
@Input()
get map(): IgoMap {
return this._map;
}
set map(value: IgoMap) {
this._map = value;
}
private _map: IgoMap;

@Input()
get color(): string {
return this._color;
}
set color(value: string) {
this._color = value;
}
private _color: string;

constructor() {}

rotationStyle(radians): {} {
const rotation = 'rotate(' + radians + 'rad)';
return {
'transform': rotation
};
}
}
8 changes: 8 additions & 0 deletions projects/geo/src/lib/map/shared/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ export class IgoMap {
return ext;
}

resetRotation() {
this.ol.getView().setRotation(0);
}

getRotation() {
return this.ol.getView().getRotation();
}

getZoom(): number {
return Math.round(this.ol.getView().getZoom());
}
Expand Down
3 changes: 2 additions & 1 deletion projects/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"baselayerSwitcher": "Change base layer",
"geolocate": "Geolocate",
"zoomIn": "Zoom in ({{zoom}})",
"zoomOut": "Zoom out ({{zoom}})"
"zoomOut": "Zoom out ({{zoom}})",
"resetRotation": "Set map to north"
},
"metadata": {
"show": "Show metadata"
Expand Down
3 changes: 2 additions & 1 deletion projects/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
"baselayerSwitcher": "Changer le fond de carte",
"geolocate": "Positionnement GPS",
"zoomIn": "Zoomer ({{zoom}})",
"zoomOut": "Dézoomer ({{zoom}})"
"zoomOut": "Dézoomer ({{zoom}})",
"resetRotation": "Réinitialiser la carte vers le nord"
},
"metadata": {
"show": "Montrer les métadonnées"
Expand Down

0 comments on commit 039ae62

Please sign in to comment.