diff --git a/frontend/src/app/components/location-card/location-card.component.html b/frontend/src/app/components/location-card/location-card.component.html index 15473ec..4043312 100644 --- a/frontend/src/app/components/location-card/location-card.component.html +++ b/frontend/src/app/components/location-card/location-card.component.html @@ -1,14 +1,14 @@ -
+
-

+

{{ location.name }}

-

+

{{ location.address }}

-

+

Kategorija: {{ location.type }}

diff --git a/frontend/src/app/components/location-card/location-card.component.ts b/frontend/src/app/components/location-card/location-card.component.ts index a6e3963..b16a85e 100644 --- a/frontend/src/app/components/location-card/location-card.component.ts +++ b/frontend/src/app/components/location-card/location-card.component.ts @@ -1,4 +1,5 @@ -import { Component, Input } from '@angular/core'; +import { NgClass } from '@angular/common'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; export interface Location { id: number; @@ -6,15 +7,23 @@ export interface Location { address: string; type: string; image?: string; + coordinates: google.maps.LatLngLiteral } @Component({ selector: 'app-location-card', standalone: true, - imports: [], + imports: [NgClass], templateUrl: './location-card.component.html', styleUrls: ['./location-card.component.scss'], }) export class LocationCardComponent { @Input() location: Location = {} as Location; + @Input() index: number | undefined; + @Input() isSelected: boolean = false; // Receives the selected state from the parent + @Output() locationSelected = new EventEmitter(); // Emit event when card is clicked + + onSelectLocation() { + this.locationSelected.emit(this.index); // Emit the event when the card is clicked + } } diff --git a/frontend/src/app/pages/home/home.component.html b/frontend/src/app/pages/home/home.component.html index 9dcd6d1..b277140 100644 --- a/frontend/src/app/pages/home/home.component.html +++ b/frontend/src/app/pages/home/home.component.html @@ -14,7 +14,7 @@

Lokacije

- +

Konjički klub "Smet"

@@ -22,7 +22,7 @@

Konjički klub "Smet"
- +

Spomen obilježje

@@ -30,7 +30,7 @@

Spomen obilježje

- +

Restoran 360

@@ -38,7 +38,7 @@

Restoran 360

- +

Dom Saveza Izviđača i Radioamatera

diff --git a/frontend/src/app/pages/location/location.component.html b/frontend/src/app/pages/location/location.component.html index 1f41979..83ca83d 100644 --- a/frontend/src/app/pages/location/location.component.html +++ b/frontend/src/app/pages/location/location.component.html @@ -1,18 +1,33 @@
-
- - +
+ + +
-
- +
+ + + + +
+ +
+

{{ infoWindowContent.name }}

+
+
+
+
diff --git a/frontend/src/app/pages/location/location.component.scss b/frontend/src/app/pages/location/location.component.scss index e69de29..c240caf 100644 --- a/frontend/src/app/pages/location/location.component.scss +++ b/frontend/src/app/pages/location/location.component.scss @@ -0,0 +1,12 @@ +.marker-info { + img { + max-width: 300px; + max-height: 200px; + min-height: 200px; + object-fit: cover; + width: 300px; + } + .marker-details { + padding: 10px; + } +} \ No newline at end of file diff --git a/frontend/src/app/pages/location/location.component.ts b/frontend/src/app/pages/location/location.component.ts index 690692d..7662477 100644 --- a/frontend/src/app/pages/location/location.component.ts +++ b/frontend/src/app/pages/location/location.component.ts @@ -1,8 +1,8 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core'; import { CommonModule } from '@angular/common'; import { LocationCardComponent } from 'src/app/components/location-card/location-card.component'; import { Location } from 'src/app/components/location-card/location-card.component'; -import { GoogleMapsModule } from '@angular/google-maps'; +import { GoogleMapsModule, MapMarker, MapInfoWindow } from '@angular/google-maps'; const DUMMY_LOCATIONS = [ { @@ -11,51 +11,120 @@ const DUMMY_LOCATIONS = [ address: 'Smetovi bb', type: 'Zooloski vrt', image: '/assets/images/smet.jpg', + coordinates: { lat: 44.241592, lng: 17.969323 }, }, { id: 2, name: 'Restoran "960"', address: 'Smetovi bb', type: 'Restoran', - image: - '/assets/images/restoran_960.jpg', + image: '/assets/images/restoran_960.jpg', + coordinates: { lat: 44.242418, lng: 17.97361 }, }, ]; +interface Marker { + position: google.maps.LatLngLiteral; + title: string; +} + +interface InfoWindowContent { + name: string; + image?: string; +} + +interface Marker extends google.maps.MarkerOptions { + image?: string; // Add custom field for image URL +} + @Component({ selector: 'app-location', standalone: true, imports: [LocationCardComponent, CommonModule, GoogleMapsModule], templateUrl: './location.component.html', - styleUrls: ['./location.component.scss'] + styleUrls: ['./location.component.scss'], }) - - - export class LocationComponent implements OnInit { - zoom = 12; + @ViewChild(MapInfoWindow) infoWindow: MapInfoWindow | undefined; + @ViewChildren('markerRef') markerElements!: QueryList; + center: google.maps.LatLngLiteral = { lat: 44.241962, - lng: 17.969424 + lng: 17.969424, }; + zoom = 12; + markers: Marker[] = []; options: google.maps.MapOptions = { mapTypeId: 'hybrid', - zoomControl: false, - scrollwheel: false, + zoomControl: true, + scrollwheel: true, draggable: false, + fullscreenControl: false, disableDoubleClickZoom: true, maxZoom: 20, minZoom: 16, - } + styles: [ + { + featureType: 'poi', // Hides points of interest + stylers: [{ visibility: 'off' }], + }, + { + featureType: 'transit', // Hides transit stations + stylers: [{ visibility: 'off' }], + }, + { + featureType: 'business', // Hides businesses + stylers: [{ visibility: 'off' }], + }, + ], + }; locations: Location[] = DUMMY_LOCATIONS; + selectedLocationIndex!: number; // Tracks the selected location index + infoWindowContent: InfoWindowContent = { + name: '', + image: '' + }; + + ngOnInit() { + this.locations.forEach(location => { + this.markers.push( + { + position: location.coordinates, + title: location.name, + image: location.image + }, + ) + }); + } + + // Handle card click and open corresponding marker infoWindow + openInfoWindowFromCard(index: number) { + const markerRef = this.markerElements.get(index); // Get the marker reference by index + if (markerRef) { + this.center = this.markers[index].position; // Center map on the marker's position + this.selectedLocationIndex = index; // Set the selected location index + this.openInfoWindow(this.markers[index], markerRef, index); + } + } - ngOnInit() {} - - zoomIn() { - if (this.zoom < 15) this.zoom++; + openInfoWindow(marker: Marker, markerRef: MapMarker, index: number) { + this.infoWindowContent = { name: marker.title, image: marker.image }; + this.center = marker.position; // Center map on the marker's position + this.selectedLocationIndex = index; // Set the selected location index + this.infoWindow?.open(markerRef); } - - zoomOut() { - if (this.zoom > 8) this.zoom--; + + isLocationSelected(index: number): boolean { + return this.selectedLocationIndex === index; // Check if current index is selected + } + + getMarkerOptions(index: number): google.maps.MarkerOptions { + return { + position: this.markers[index].position, + icon: (index === this.selectedLocationIndex) + ? 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png' + : 'http://maps.google.com/mapfiles/ms/icons/red-dot.png', + title: this.markers[index].title, + }; } } diff --git a/frontend/src/styles.scss b/frontend/src/styles.scss index 575610e..1805406 100644 --- a/frontend/src/styles.scss +++ b/frontend/src/styles.scss @@ -23,4 +23,17 @@ button, .button { .primary { background-color: #fff; color: #222; +} + +/* Google maps styling */ +.gm-style-iw-chr { + display: none; +} + +.gm-style-iw-d { + overflow: hidden !important; +} + +.gm-style-iw.gm-style-iw-c { + padding: 0px!important; } \ No newline at end of file