Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset rotation to map view #261

Merged
merged 9 commits into from Feb 15, 2019
1 change: 1 addition & 0 deletions demo/src/app/context/context/context.component.html
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
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
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
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
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
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';
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
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
@@ -0,0 +1 @@
export * from './rotation-button.component';
@@ -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>
@@ -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;
}
@@ -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
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
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
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