Skip to content

Commit 44295aa

Browse files
committed
chore(text): allow adding custom styles to text
- allow hiding text based on zoom level of map
1 parent 5ecb2e0 commit 44295aa

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

projects/demo/src/app/app.component.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, ViewEncapsulation } from '@angular/core';
22

3-
import { MapRangeComponent } from 'projects/library/src/lib/components/overlays/map-range/map-range.component';
43
import { MapPinComponent } from 'projects/library/src/lib/components/overlays/map-pin/map-pin.component';
4+
import { MapRadiusComponent } from 'projects/library/src/lib/components/overlays/map-radius/map-radius.component';
55

66
import * as dayjs from 'dayjs';
77

@@ -19,6 +19,11 @@ export class AppComponent {
1919
this.model.show = {};
2020
this.model.map = {};
2121
this.model.map.src = 'assets/australia.svg';
22+
this.model.map.text = [
23+
{ id: 'area-10.06-status', content: 'Meeting Room\n10.06' },
24+
{ id: 'area-10.05-status', content: 'Meeting Room\n10.05' },
25+
{ id: 'scanner-2', content: 'Scanner', show_after_zoom: 2, styles: { 'color': 'red' } }
26+
];
2227
this.model.zoom = 1;
2328
this.model.center = { x: 0.25, y: 0.75 };
2429
this.model.count = Array(3).fill(0);
@@ -57,10 +62,9 @@ export class AppComponent {
5762
this.model.map.poi = [];
5863
if (this.model.show.radius) {
5964
this.model.map.poi.push({
60-
id: 'Nyada',
6165
coordinates: { x: 3000, y: 3000 },
62-
content: MapRangeComponent,
63-
data: { text: `I'm somewhere in this circle`, diameter: 10 }
66+
content: MapRadiusComponent,
67+
data: { text: `I'm somewhere in this circle`, diameter: 5 }
6468
});
6569
}
6670
if (this.model.show.pin) {
@@ -74,11 +78,11 @@ export class AppComponent {
7478
text: fixed ? 'NSW is here' : `I'm currently round here`
7579
}
7680
});
77-
const focus: any = {};
81+
let focus: any = null;
7882
if (fixed) {
79-
focus.id = 'AU-NSW';
83+
focus = 'area-10.05-status';
8084
} else {
81-
focus.coordinates = { x: 5000, y: 7500 };
85+
focus = { x: 0.75, y: 0.25 };
8286
}
8387
this.model.map.focus = focus;
8488
this.model.map.styles = {

projects/demo/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { NgModule } from '@angular/core';
55
import { AppComponent } from './app.component';
66
import { AInteractiveMapModule } from 'projects/library/src/public-api';
77

8+
import 'hammerjs';
9+
810
@NgModule({
911
declarations: [
1012
AppComponent

projects/library/src/lib/classes/map-render-feature.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class MapRenderFeature {
1313
public readonly content: RenderFeature;
1414
/** Data to pass to the content */
1515
public readonly data: any;
16+
/** Data to pass to the content */
17+
public readonly show_after_zoom: number;
1618

1719
/** Type of content being rendered by this feature */
1820
public get content_type(): 'component' | 'template' | 'html' {
@@ -28,7 +30,8 @@ export class MapRenderFeature {
2830
this.id = data.id || JSON.stringify(coordinates);
2931
this.coordinates = coordinates;
3032
this.content = data.content;
31-
this.data = data.data;
33+
this.data = data.data || data.styles;
34+
this.show_after_zoom = data.show_after_zoom;
3235
}
3336

3437
private processCoordinates(data: string | Point, map: RenderableMap): Point {

projects/library/src/lib/components/map-outlet/map-outlet.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
>
2222
<div class="map" *ngIf="map" [innerHTML]="map.raw_data | safe"></div>
2323
<map-overlay-outlet [zoom]="local_zoom" [center]="local_center" [items]="features"></map-overlay-outlet>
24-
<map-text-outlet [items]="text"></map-text-outlet>
24+
<map-text-outlet [zoom]="local_zoom" [items]="text"></map-text-outlet>
2525
</div>
2626
</div>
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<ng-container *ngIf="items && items.length">
22
<ng-container *ngFor="let item of items">
33
<div
4-
*ngIf="item.coordinates"
4+
*ngIf="item.coordinates && (!item.show_after_zoom || zoom >= item.show_after_zoom)"
55
class="map-text"
6-
[style.top]="(item.coordinates.y * 100) + '%'"
7-
[style.left]="(item.coordinates.x * 100) + '%'"
6+
[style.top]="item.coordinates.y * 100 + '%'"
7+
[style.left]="item.coordinates.x * 100 + '%'"
88
[style.transform]="'rotate(' + rotation + 'deg)'"
9-
109
>
11-
<div class="text">{{ item.content }}</div>
10+
<div
11+
class="text"
12+
[ngStyle]="item.data"
13+
>
14+
{{ item.content }}
15+
</div>
1216
</div>
1317
</ng-container>
1418
</ng-container>

projects/library/src/lib/components/map-text-outlet/map-text-outlet.component.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
.map-text {
33
position: absolute;
4+
font-size: 1rem;
45
}
56

67
.text {
@@ -9,7 +10,7 @@
910
left: 50%;
1011
transform: translate(-50%, -50%);
1112
color: #fff;
12-
font-size: .8rem;
13+
font-size: .8em;
1314
text-shadow: 0 0 2px #000;
1415
white-space: pre-line;
1516
min-width: 20em;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Input } from '@angular/core';
22

3-
import { MapRenderFeature } from '../../classes/map-render-feature';
3+
import { MapTextFeature } from '../../helpers/map.interfaces';
44

55
@Component({
66
selector: 'map-text-outlet',
@@ -9,7 +9,9 @@ import { MapRenderFeature } from '../../classes/map-render-feature';
99
})
1010
export class MapTextOutletComponent {
1111
/** List of text items to render on top of the map */
12-
@Input() items: MapRenderFeature[] = [];
12+
@Input() items: MapTextFeature[] = [];
13+
/** Rotation of the map */
14+
@Input() zoom: number = 1;
1315
/** Rotation of the map */
1416
@Input() rotation: number = 0;
1517
}

projects/library/src/lib/helpers/map.interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export interface MapFeature<T = any> {
1515

1616
export interface MapTextFeature extends MapFeature {
1717
readonly content: string;
18+
/** Minimum zoom level to show the text feature */
19+
readonly show_after_zoom?: number;
20+
/** Map of CSS properties to their values */
21+
readonly styles?: { [style: string]: string };
1822
}
1923

2024
export interface MapState {

0 commit comments

Comments
 (0)