Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 35x 35x 35x 35x 1x 1x 35x 35x 35x 1x 1x 35x 35x 35x 9x 9x 35x 35x 35x 35x 1x 1x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 1x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { isPlatformBrowser } from '@angular/common';
import { AfterViewInit, Component, OnInit, PLATFORM_ID, inject, input, output, viewChild } from '@angular/core';
import { google } from 'google-maps';
import { CityClass } from '@classes/city.class';
import { environment } from '@environments/environment';
import { BrandService } from '@services/brand.service';
declare const google: any; // Import Google Maps library if not already done
@Component({
selector: 'grt-g-map',
templateUrl: './g-map.component.html',
styleUrls: ['./g-map.component.scss'],
standalone: true,
})
export class GMapComponent implements OnInit, AfterViewInit {
readonly gmapElement = viewChild<any>('gmap');
readonly removeCity = output<CityClass>();
readonly addCity = output<CityClass>();
readonly mapLoaded = output<void>();
readonly pins = input<any>();
map: any;
isBrowser: any;
availableMarkers: google.maps.Marker[] = [];
selectedMarkers: google.maps.Marker[] = [];
brandService = inject(BrandService);
branding: any = null;
constructor() {
const platformId = inject(PLATFORM_ID);
this.isBrowser = isPlatformBrowser(platformId);
}
ngOnInit() {
console.log('Map Initialized');
this.branding = this.brandService.getBrand();
}
ngAfterViewInit() {
if (this.isBrowser) {
this.loadGoogleMapsScript()
.then(() => {
this.initMap();
this.mapLoaded.emit();
})
.catch((error: any) => console.error('Google Maps script could not be loaded.', error));
}
}
loadGoogleMapsScript(): Promise<void> {
return new Promise((resolve, reject) => {
if (window['google'] && window['google'].maps) {
resolve();
return;
}
const script = document.createElement('script');
script.src = `https://maps.googleapis.com/maps/api/js?v=weekly&key=${environment.googleMapsApiKey}`; // Replace YOUR_API_KEY with your actual API key
script.async = true;
script.defer = true;
document.head.appendChild(script);
script.onload = () => {
resolve();
};
script.onerror = (error) => {
reject(error);
};
});
}
initMap() {
const mapProp = {
center: new google.maps.LatLng(49.374092, 11.561137),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
this.map = new google.maps.Map(this.gmapElement().nativeElement, mapProp);
const pins = this.pins();
if (pins) {
pins.forEach((pin: any) => pin.setMap(this.map));
this.map.setCenter(pins[0].getPosition());
this.map.setZoom(18);
}
}
public setCenter(index: any) {
this.map.setCenter(this.pins()[index].getPosition());
}
focusAsia() {
if (this.isBrowser) {
this.map.setCenter(new google.maps.LatLng(14.372079, 102.517827));
this.map.setZoom(5);
}
}
focusEurope() {
if (this.isBrowser) {
this.map.setCenter(new google.maps.LatLng(49.374092, 11.561137));
this.map.setZoom(5);
}
}
focusAll() {
if (this.isBrowser) {
this.map.setCenter(new google.maps.LatLng(42.49807, 57.083454));
this.map.setZoom(2);
}
}
public drawSelected(cities: CityClass[]) {
if (this.isBrowser) {
if (this.selectedMarkers?.length > 0) {
this.selectedMarkers.forEach((marker) => {
marker.setMap(null);
});
}
this.selectedMarkers = [];
const bounds: any = new google.maps.LatLngBounds();
cities.forEach((city) => {
const marker = new google.maps.Marker({
position: new google.maps.LatLng(city.getLat(), city.getLng()),
icon: this.getMarkerIcon(this.branding?.primary_text_color || '#02A388'),
map: this.map,
title: city.name,
});
marker.addListener('click', () => {
this.removeCity.emit(city);
});
this.selectedMarkers.push(marker);
bounds.extend(marker.getPosition());
});
}
}
getMarkerIcon(color: string) {
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 550">
<path
fill="${color}"
d="M192 0C86 0 0 84.4 0 188.6 0 307.9 120.2 450.9 170.4 505.4 182.2 518.2 201.8 518.2 213.6 505.4 263.8 450.9 384 307.9 384 188.6 384 84.4 298 0 192 0z"
/>
<path
fill="none"
stroke="#FFFFFF"
stroke-width="32"
stroke-linecap="round"
stroke-linejoin="round"
d="M144 240 L192 288 L272 208"
/>
</svg>
`;
return {
url: 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg),
scaledSize: new google.maps.Size(30, 50),
};
}
getMarkerIconUnChecked(color: string) {
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 30.2">
<defs>
<radialGradient id="grad" cx="0.5" cy="0.5" r="0.5">
<stop offset="0%" stop-color="black" stop-opacity="0.5"/>
<stop offset="100%" stop-color="black" stop-opacity="0"/>
</radialGradient>
</defs>
<!-- Shadow -->
<ellipse cx="9.9" cy="28.2" rx="16.5" ry="2" fill="url(#grad)" />
<g transform="translate(8,0)">
<!-- White overlay (opacity stays same) -->
<path fill="white" opacity="0.4"
d="M2,27.7c-0.7-0.9-2.3-3-3.8-5.3c-2.7-4.1-4.2-7.4-4.2-9.3c0-4.7,3.6-8.5,8-8.5
s8,3.8,8,8.5c0,1.9-1.4,5.1-4.2,9.3C4.2,24.7,2.7,26.8,2,27.7z"/>
<!-- MAIN COLOR (dynamic) -->
<path fill="${color}"
d="M2,5.1c-4.1,0-7.5,3.6-7.5,8c0,3.4,4.9,10.4,7.5,13.8c0.8-1,2.1-2.8,3.4-4.8
c2.6-4,4.1-7.2,4.1-9C9.5,8.6,6.1,5.1,2,5.1
M2,4.1c4.7,0,8.5,4,8.5,9S2,28.5,2,28.5S-6.6,18-6.6,13.1S-2.7,4.1,2,4.1z"/>
</g>
</svg>
`;
return {
url: 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg),
scaledSize: new google.maps.Size(30, 50),
};
}
public drawAvailable(cities: CityClass[]) {
if (this.isBrowser) {
console.log('drawing available');
if (this.availableMarkers?.length > 0) {
this.availableMarkers.forEach((marker) => {
marker.setMap(null);
});
}
this.availableMarkers = [];
const bounds: any = new google.maps.LatLngBounds();
cities.forEach((city) => {
const marker = new google.maps.Marker({
position: new google.maps.LatLng(city.getLat(), city.getLng()),
icon: this.getMarkerIconUnChecked(this.branding?.primary_text_color || '#02A388'),
map: this.map,
title: city.name,
});
marker.addListener('click', () => {
this.addCity.emit(city);
});
this.availableMarkers.push(marker);
bounds.extend(marker.getPosition());
});
}
}
}
|