|
| 1 | +import { IgrGeographicMap } from 'igniteui-react-maps'; |
| 2 | + |
| 3 | +export enum MapRegion { |
| 4 | + Caribbean = "Caribbean", |
| 5 | + UnitedStates = "United States", |
| 6 | + UnitedKingdom = "United Kingdom", |
| 7 | + European = "European", |
| 8 | + SouthAfrica = "South Africa", |
| 9 | + Poland = "Poland", |
| 10 | + Australia = "Australia", |
| 11 | + Japan = "Japan", |
| 12 | + Uruguay = "Uruguay", |
| 13 | + Egypt = "Egypt", |
| 14 | + Hawaii = "Hawaii", |
| 15 | +} |
| 16 | + |
| 17 | +export class MapUtils { |
| 18 | + |
| 19 | + public static navigateTo(geoMap: IgrGeographicMap, name: MapRegion): void { |
| 20 | + |
| 21 | + const geoRect = this.getRegions()[name]; |
| 22 | + // console.log("MapUtils " + name) ; |
| 23 | + geoMap.zoomToGeographic(geoRect); |
| 24 | + } |
| 25 | + |
| 26 | + public static toPixel(num: number): string { |
| 27 | + const s = Math.abs(num).toFixed(0); |
| 28 | + return s + " px"; |
| 29 | + } |
| 30 | + |
| 31 | + public static toLng(num: number): string { |
| 32 | + num = this.clamp(num, -180, 180); |
| 33 | + |
| 34 | + let s = Math.abs(num).toFixed(1); |
| 35 | + if (num < 100) { |
| 36 | + s = " " + s |
| 37 | + } |
| 38 | + |
| 39 | + if (num > 0) { |
| 40 | + return s + "°E"; |
| 41 | + } else { |
| 42 | + return s + "°W"; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public static toLat(num: number): string { |
| 47 | + num = this.clamp(num, -90, 90); |
| 48 | + |
| 49 | + let s = Math.abs(num).toFixed(1); |
| 50 | + if (num < 100) { |
| 51 | + s = " " + s |
| 52 | + } |
| 53 | + |
| 54 | + if (num > 0) { |
| 55 | + return s + "°N"; |
| 56 | + } else { |
| 57 | + return s + "°S"; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + public static clamp(num: number, min: number, max: number): number { |
| 62 | + return Math.max(min, Math.min(max, num)); |
| 63 | + } |
| 64 | + |
| 65 | + public static pad(num: number, places?: number): string { |
| 66 | + places = places || 20; |
| 67 | + let s = num.toFixed(1).toString(); |
| 68 | + while (s.length < places) {s = " " + s;} |
| 69 | + return s; |
| 70 | + } |
| 71 | + |
| 72 | + public static getBingKey(): string { |
| 73 | + return "Avlo7qsH1zZZI0XNpTwZ4XwvUJmCbd-mczMeUXVAW9kYYOKdmBIVRe8aoO02Xctq"; |
| 74 | + } |
| 75 | + |
| 76 | + public static getRegions(): any { |
| 77 | + // create regions only once |
| 78 | + if (this.Regions === undefined) { |
| 79 | + this.createRegions(); |
| 80 | + } |
| 81 | + return this.Regions; |
| 82 | + } |
| 83 | + |
| 84 | + private static Regions: any; |
| 85 | + |
| 86 | + private static addRegion(name: string, geoRect: any): void { |
| 87 | + geoRect.name = name; |
| 88 | + geoRect.longitude = geoRect.left + (geoRect.width / 2); |
| 89 | + geoRect.latitude = geoRect.top + (geoRect.height / 2); |
| 90 | + |
| 91 | + this.Regions[name] = geoRect; |
| 92 | + } |
| 93 | + |
| 94 | + private static createRegions(): void { |
| 95 | + this.Regions = {}; |
| 96 | + this.addRegion(MapRegion.Australia, { left: 81.5, top: -52.0, width: 98.0, height: 56.0 }); |
| 97 | + this.addRegion(MapRegion.Caribbean, { left: -92.9, top: 5.4, width: 35.1, height: 25.8 }); |
| 98 | + this.addRegion(MapRegion.Egypt, { left: 19.3, top: 19.9, width: 19.3, height: 13.4 }); |
| 99 | + this.addRegion(MapRegion.European, { left: -36.0, top:31.0, width: 98.0, height: 38.0 }); |
| 100 | + this.addRegion(MapRegion.Japan, { left: 122.7, top: 29.4, width: 27.5, height: 17.0 }); |
| 101 | + this.addRegion(MapRegion.Hawaii, { left: -161.2, top: 18.5, width: 6.6, height: 4.8 }); |
| 102 | + this.addRegion(MapRegion.Poland, { left: 13.0, top: 48.0, width: 11.0, height: 9.0 }); |
| 103 | + this.addRegion(MapRegion.SouthAfrica, { left: 9.0, top: -37.1, width: 26.0, height: 17.8 }); |
| 104 | + this.addRegion(MapRegion.UnitedStates, { left: -134.5, top: 16.0, width: 70.0, height: 37.0 }); |
| 105 | + this.addRegion(MapRegion.UnitedKingdom, { left: -15.0, top: 49.5, width: 22.5, height: 8.0 }); |
| 106 | + this.addRegion(MapRegion.Uruguay, { left: -62.1, top: -35.7, width: 10.6, height: 7.0 }); |
| 107 | + } |
| 108 | + |
| 109 | +} |
0 commit comments