| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import TilesourceConfigJson from "./Json/TilesourceConfigJson" | 
					
						
							|  |  |  | import Translations from "../../UI/i18n/Translations" | 
					
						
							|  |  |  | import { Translation } from "../../UI/i18n/Translation" | 
					
						
							| 
									
										
										
										
											2021-10-14 21:43:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class TilesourceConfig { | 
					
						
							|  |  |  |     public readonly source: string | 
					
						
							| 
									
										
										
										
											2021-10-15 00:52:31 +02:00
										 |  |  |     public readonly id: string | 
					
						
							| 
									
										
										
										
											2021-10-14 21:43:14 +02:00
										 |  |  |     public readonly isOverlay: boolean | 
					
						
							|  |  |  |     public readonly name: Translation | 
					
						
							|  |  |  |     public readonly minzoom: number | 
					
						
							|  |  |  |     public readonly maxzoom: number | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     public readonly defaultState: boolean | 
					
						
							| 
									
										
										
										
											2021-10-14 21:43:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     constructor(config: TilesourceConfigJson, ctx: string = "") { | 
					
						
							| 
									
										
										
										
											2021-10-15 00:52:31 +02:00
										 |  |  |         this.id = config.id | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this.source = config.source | 
					
						
							|  |  |  |         this.isOverlay = config.isOverlay ?? false | 
					
						
							| 
									
										
										
										
											2021-10-14 21:43:14 +02:00
										 |  |  |         this.name = Translations.T(config.name) | 
					
						
							|  |  |  |         this.minzoom = config.minZoom ?? 0 | 
					
						
							|  |  |  |         this.maxzoom = config.maxZoom ?? 999 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this.defaultState = config.defaultState ?? true | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         if (this.id === undefined) { | 
					
						
							| 
									
										
										
										
											2021-10-15 00:52:31 +02:00
										 |  |  |             throw "An id is obligated" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-10-14 21:43:14 +02:00
										 |  |  |         if (this.minzoom > this.maxzoom) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             throw ( | 
					
						
							|  |  |  |                 "Invalid tilesourceConfig: minzoom should be smaller then maxzoom (at " + ctx + ")" | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2021-10-14 21:43:14 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (this.minzoom < 0) { | 
					
						
							|  |  |  |             throw "minzoom should be > 0 (at " + ctx + ")" | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (this.maxzoom < 0) { | 
					
						
							|  |  |  |             throw "maxzoom should be > 0 (at " + ctx + ")" | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (this.source.indexOf("{zoom}") >= 0) { | 
					
						
							|  |  |  |             throw "Invalid source url: use {z} instead of {zoom}  (at " + ctx + ".source)" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         if (!this.defaultState && config.name === undefined) { | 
					
						
							| 
									
										
										
										
											2021-10-14 21:43:14 +02:00
										 |  |  |             throw "Disabling an overlay without a name is not possible" | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |