| 
									
										
										
										
											2020-10-17 00:37:45 +02:00
										 |  |  | import {UIElement} from "../UIElement"; | 
					
						
							|  |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import {LicenseInfo} from "../../Logic/Web/Wikimedia"; | 
					
						
							|  |  |  | import {Mapillary} from "../../Logic/Web/Mapillary"; | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  | import Svg from "../../Svg"; | 
					
						
							| 
									
										
										
										
											2021-01-29 03:23:53 +01:00
										 |  |  | import {SimpleImageElement} from "./SimpleImageElement"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							|  |  |  | import Attribution from "./Attribution"; | 
					
						
							| 
									
										
										
										
											2020-10-17 00:37:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class MapillaryImage extends UIElement { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /*** | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  |      * Dictionary from url to already known license info | 
					
						
							| 
									
										
										
										
											2020-10-17 00:37:45 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     private static allLicenseInfos: any = {}; | 
					
						
							|  |  |  |     private readonly _imageMeta: UIEventSource<LicenseInfo>; | 
					
						
							|  |  |  |     private readonly _imageLocation: string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(source: string) { | 
					
						
							|  |  |  |         super() | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (source.toLowerCase().startsWith("https://www.mapillary.com/map/im/")) { | 
					
						
							| 
									
										
										
										
											2020-10-17 00:37:45 +02:00
										 |  |  |             source = source.substring("https://www.mapillary.com/map/im/".length); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 00:37:45 +02:00
										 |  |  |         this._imageLocation = source; | 
					
						
							|  |  |  |         if (MapillaryImage.allLicenseInfos[source] !== undefined) { | 
					
						
							|  |  |  |             this._imageMeta = MapillaryImage.allLicenseInfos[source]; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             this._imageMeta = new UIEventSource<LicenseInfo>(null); | 
					
						
							|  |  |  |             MapillaryImage.allLicenseInfos[source] = this._imageMeta; | 
					
						
							|  |  |  |             const self = this; | 
					
						
							|  |  |  |             Mapillary.getDescriptionOfImage(source, (license) => { | 
					
						
							|  |  |  |                 self._imageMeta.setData(license) | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.ListenTo(this._imageMeta); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     InnerRender(): string { | 
					
						
							|  |  |  |         const url = `https://images.mapillary.com/${this._imageLocation}/thumb-640.jpg?client_id=TXhLaWthQ1d4RUg0czVxaTVoRjFJZzowNDczNjUzNmIyNTQyYzI2`; | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  |         const image = new SimpleImageElement(new UIEventSource<string>(url)) | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         const meta = this._imageMeta?.data; | 
					
						
							|  |  |  |         if (!meta) { | 
					
						
							| 
									
										
										
										
											2021-01-29 03:23:53 +01:00
										 |  |  |             return image.Render(); | 
					
						
							| 
									
										
										
										
											2020-10-17 00:37:45 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-01-29 03:23:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return new Combine([ | 
					
						
							|  |  |  |             image, | 
					
						
							|  |  |  |             new Attribution(meta.artist, meta.license, Svg.mapillary_svg()) | 
					
						
							|  |  |  |         ]).SetClass("relative block").Render(); | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 00:37:45 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |