cloud
This commit is contained in:
@@ -15,12 +15,14 @@ import { SafePipe } from './pipes/safe.pipe';
|
|||||||
AppComponent,
|
AppComponent,
|
||||||
HomeComponent,
|
HomeComponent,
|
||||||
ListComponent,
|
ListComponent,
|
||||||
DetailComponent
|
DetailComponent,
|
||||||
|
SafePipe
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
FormsModule
|
FormsModule,
|
||||||
|
HttpClientModule
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
|||||||
@@ -26,7 +26,3 @@ input {
|
|||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sun {
|
|
||||||
width: 10%;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
<div [ngClass]="{'background-color': backgroundColor}">
|
<div [ngClass]="{'background-color': backgroundColor}">
|
||||||
|
<div class="canvas nuvola">
|
||||||
|
<canvas #myCanvas width="100vw" class="canvas"></canvas>
|
||||||
|
</div>
|
||||||
<div class="bg-image">
|
<div class="bg-image">
|
||||||
<div class="search">
|
<div class="search">
|
||||||
<input #myInput type="text" [(ngModel)]="luogoSelezionato" (keyup)="cercaLuogo(myInput.value)"
|
<input #myInput type="text" [(ngModel)]="luogoSelezionato" (keyup)="cercaLuogo(myInput.value)"
|
||||||
(keydown)="selezionaSuggerimento($event)" placeholder="Type here"
|
(keydown)="selezionaSuggerimento($event)" placeholder="Type here"
|
||||||
class="input input-bordered input-primary w-full max-w-xs">
|
class="input input-bordered input-primary w-full max-w-xs">
|
||||||
|
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li *ngFor="let luogo of luoghiPopup | async">{{luogo.nome}}</li>
|
<li *ngFor="let luogo of luoghiPopup | async">{{luogo.location}}</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
import {AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
||||||
import { distinctUntilChanged, fromEvent, Subject, Subscription} from "rxjs";
|
import {distinctUntilChanged, fromEvent, Subject, Subscription} from "rxjs";
|
||||||
import {ReadjsonService} from "../service/readjson.service";
|
import {ReadjsonService} from "../service/readjson.service";
|
||||||
|
import {Locations} from "../interface/data";
|
||||||
|
|
||||||
interface Luogo {
|
interface Luogo {
|
||||||
nome: string;
|
location: string;
|
||||||
latitudine: number;
|
lat: number;
|
||||||
longitudine: number;
|
lon: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -14,6 +15,9 @@ interface Luogo {
|
|||||||
styleUrls: ['./home.component.css']
|
styleUrls: ['./home.component.css']
|
||||||
})
|
})
|
||||||
export class HomeComponent implements OnInit, AfterViewInit, OnDestroy {
|
export class HomeComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||||
|
@ViewChild('myInput') myInput?: ElementRef;
|
||||||
|
@ViewChild('myCanvas') myCanvas?: ElementRef<HTMLCanvasElement>;
|
||||||
|
|
||||||
luoghiPopup: Subject<Luogo[]> = new Subject<Luogo[]>()
|
luoghiPopup: Subject<Luogo[]> = new Subject<Luogo[]>()
|
||||||
|
|
||||||
subs: Subscription[] = []
|
subs: Subscription[] = []
|
||||||
@@ -21,63 +25,114 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
latitude: number | undefined;
|
latitude: number | undefined;
|
||||||
longitude: number | undefined;
|
longitude: number | undefined;
|
||||||
backgroundColor: string | undefined;
|
backgroundColor: string | undefined;
|
||||||
|
locations: Locations[] = [
|
||||||
|
{location: 'Locarno', region: 'Ticino', lat: 46.1704, lon: 8.7931},
|
||||||
|
{location: 'Lugano', region: 'Ticino', lat: 46.0037, lon: 8.9511},
|
||||||
|
{location: 'Luzern', region: 'Luzern', lat: 47.0502, lon: 8.3093},
|
||||||
|
{location: 'Lauterbrunnen', region: 'Bern', lat: 46.5939, lon: 7.9085}
|
||||||
|
];
|
||||||
|
|
||||||
luoghi: Luogo[] = [
|
luoghi: Luogo[] = [
|
||||||
{nome: 'Locarno', latitudine: 46.1704, longitudine: 8.7931},
|
{location: 'Locarno', lat: 46.1704, lon: 8.7931},
|
||||||
{nome: 'Lugano', latitudine: 46.0037, longitudine: 8.9511},
|
{location: 'Lugano', lat: 46.0037, lon: 8.9511},
|
||||||
{nome: 'Luzern', latitudine: 47.0502, longitudine: 8.3093},
|
{location: 'Luzern', lat: 47.0502, lon: 8.3093},
|
||||||
{nome: 'Lauterbrunnen', latitudine: 46.5939, longitudine: 7.9085}
|
{location: 'Lauterbrunnen', lat: 46.5939, lon: 7.9085}
|
||||||
];
|
];
|
||||||
|
locationsFiltrati: Locations[] = [];
|
||||||
luoghiFiltrati: Luogo[] = [];
|
luoghiFiltrati: Luogo[] = [];
|
||||||
luogoSelezionato: string = '';
|
luogoSelezionato: string = '';
|
||||||
suggerimentoAttivo: boolean = false;
|
suggerimentoAttivo: boolean = false;
|
||||||
suggerimento: string = '';
|
suggerimento: string = '';
|
||||||
completamento: string = 'ciao';
|
completamento: string = 'ciao';
|
||||||
|
|
||||||
@ViewChild('myInput') myInput?: ElementRef;
|
constructor(private service: ReadjsonService) {
|
||||||
|
}
|
||||||
|
|
||||||
constructor(private service: ReadjsonService) {}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
console.log("home init");
|
||||||
this.subs.push(this.service.getLocation("Lugano").subscribe(val => console.log(val)))
|
this.subs.push(this.service.getLocation("Lugano").subscribe(val => console.log(val)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit() {
|
||||||
|
console.log("canvas", this.myCanvas?.nativeElement);
|
||||||
|
const canvas = this.myCanvas?.nativeElement;
|
||||||
|
console.log("canvas 2", canvas);
|
||||||
|
if (canvas)
|
||||||
|
this.animateClouds(canvas);
|
||||||
|
|
||||||
|
fromEvent(this.myInput?.nativeElement, 'focus').pipe(
|
||||||
|
// debounceTime(500), decommentarlo se bisogna fare una chiamata http
|
||||||
|
distinctUntilChanged()
|
||||||
|
).subscribe((val: any) => {
|
||||||
|
this.luoghiPopup.next(this.locations.filter(l => l.location.toLowerCase().startsWith(val.target.value.toLowerCase())
|
||||||
|
))})
|
||||||
|
|
||||||
|
fromEvent(this.myInput?.nativeElement, 'input')
|
||||||
|
.pipe(
|
||||||
|
// debounceTime(500), decommentarlo se bisogna fare una chiamata http
|
||||||
|
distinctUntilChanged()
|
||||||
|
).subscribe((val: any) => {
|
||||||
|
this.luoghiPopup.next(this.luoghi.filter(l => l.location.toLowerCase().startsWith(val.target.value.toLowerCase())))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.subs.forEach(sub => sub.unsubscribe())
|
this.subs.forEach(sub => sub.unsubscribe())
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
animateClouds(canvas: HTMLCanvasElement): void {
|
||||||
fromEvent(this.myInput?.nativeElement, 'input')
|
console.log("animating clouds")
|
||||||
.pipe(
|
let x = -200;
|
||||||
// debounceTime(500), decommentarlo se bisogna fare una chiamata http
|
let y = 100;
|
||||||
distinctUntilChanged()
|
let speed = 2;
|
||||||
).subscribe((val: any) => {
|
let rand = 30;
|
||||||
this.luoghiPopup.next(this.luoghi.filter(l => l.nome.toLowerCase().startsWith(val.target.value.toLowerCase())))
|
let ctx = canvas.getContext("2d");
|
||||||
})
|
canvas.width = window.innerWidth;
|
||||||
|
setInterval(() => {
|
||||||
|
if (ctx) {
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
this.drawCloud(x, y, ctx);
|
||||||
|
x += speed;
|
||||||
|
if (x > canvas.width + 200) {
|
||||||
|
x = -200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rand = Math.round(Math.random() * (10 - 500)) + 10
|
||||||
|
}, rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
cercaLuogo(nome: string){
|
drawCloud(x: number, y: number, ctx: CanvasRenderingContext2D) {
|
||||||
setTimeout(() => {
|
console.log("xy:"+ x, y)
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(x, y, 50, 0, 2 * Math.PI);
|
||||||
|
ctx.arc(x + 25, y - 25, 50, 0, 2 * Math.PI);
|
||||||
|
ctx.arc(x + 75, y - 25, 50, 0, 2 * Math.PI);
|
||||||
|
ctx.arc(x + 50, y, 50, 0, 2 * Math.PI);
|
||||||
|
ctx.fillStyle = "#87CEEB";
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
|
||||||
|
cercaLuogo(locations: string){
|
||||||
|
setTimeout(()=>{
|
||||||
}, 1000);
|
}, 1000);
|
||||||
this.luoghiFiltrati = this.luoghi.filter((l: Luogo) => l.nome.toLowerCase().startsWith(nome.toLowerCase()));
|
this.locationsFiltrati = this.locations.filter((l: Locations) => l.location.toLowerCase().startsWith(locations.toLowerCase()));
|
||||||
if (this.luoghiFiltrati.length > 0) {
|
if(this.locationsFiltrati.length > 0){
|
||||||
this.suggerimentoAttivo = true;
|
this.suggerimentoAttivo = true;
|
||||||
this.suggerimento = this.luoghiFiltrati[0].nome;
|
this.suggerimento = this.locationsFiltrati[0].location;
|
||||||
this.completamento = stringDifference(nome, this.suggerimento);
|
this.completamento = stringDifference(locations, this.suggerimento);
|
||||||
} else {
|
} else {
|
||||||
this.suggerimentoAttivo = false;
|
this.suggerimentoAttivo = false;
|
||||||
this.suggerimento = '';
|
this.suggerimento = '';
|
||||||
}
|
}
|
||||||
this.myInput?.nativeElement.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
consigliaSuggerimento(nome: string) {
|
consigliaSuggerimento(locations: string) {
|
||||||
if (this.suggerimentoAttivo) {
|
if (this.suggerimentoAttivo) {
|
||||||
this.luogoSelezionato = nome + "-"+this.completamento;
|
this.luogoSelezionato = locations + "-" + this.completamento;
|
||||||
this.suggerimento = '';
|
this.suggerimento = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selezionaSuggerimento(event: KeyboardEvent) {
|
selezionaSuggerimento(event: KeyboardEvent) {
|
||||||
if (event.key === 'Tab' || event.key === 'Enter') {
|
if (event.key === 'Tab' || event.key === 'Enter') {
|
||||||
if (this.suggerimentoAttivo) {
|
if (this.suggerimentoAttivo) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ export interface Locations {
|
|||||||
region: string;
|
region: string;
|
||||||
lat: number;
|
lat: number;
|
||||||
lon: number;
|
lon: number;
|
||||||
waypoints: waypoint[];
|
waypoints?: waypoint[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface waypoint {
|
export interface waypoint {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {Component, OnInit} from '@angular/core';
|
|||||||
})
|
})
|
||||||
export class ListComponent implements OnInit {
|
export class ListComponent implements OnInit {
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import { SafePipe } from './safe.pipe';
|
|
||||||
|
|
||||||
describe('SafePipe', () => {
|
|
||||||
it('create an instance', () => {
|
|
||||||
const pipe = new SafePipe();
|
|
||||||
expect(pipe).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user