11import Tile from 'Core/Tile/Tile' ;
22import URLBuilder from 'Provider/URLBuilder' ;
33import { Extent } from '@itowns/geographic' ;
4- import * as THREE from 'three' ;
54import Layer from 'Layer/Layer' ;
65import { RemoteSource , RemoteSourceOptions } from './RemoteSource' ;
6+ import { SourceCapabilities } from './SourceCapabilities' ;
77
88export type TmsLimit = {
99 minTileRow : number ;
@@ -19,21 +19,94 @@ export interface TmsSourceOptions<Data> extends RemoteSourceOptions<Data> {
1919 zoom ?: { min : number ; max : number ; } ;
2020}
2121
22- export class TmsSource < Data extends THREE . Texture >
23- extends RemoteSource < Tile , Data > {
22+ /**
23+ * An object defining the source of resources to get from a
24+ * [TMS](https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification) server.
25+ *
26+ * @example
27+ *
28+ * **Source from OpenStreetMap server:**
29+ * ```ts
30+ * // Create the source
31+ * const tmsSource = new itowns.TMSSource({
32+ * format: 'image/png',
33+ * url: 'http://osm.io/styles/${z}/${x}/${y}.png',
34+ * attribution: {
35+ * name: 'OpenStreetMap',
36+ * url: 'http://www.openstreetmap.org/',
37+ * },
38+ * crs: 'EPSG:3857',
39+ * });
40+ *
41+ * // Create the layer
42+ * const colorLayer = new itowns.ColorLayer('OPENSM', {
43+ * source: tmsSource,
44+ * });
45+ *
46+ * // Add the layer
47+ * view.addLayer(colorLayer);
48+ * ```
49+ *
50+ * @example
51+ *
52+ * **Source from Mapbox server:**
53+ * ```ts
54+ * // Create the source
55+ * const orthoSource = new itowns.TMSSource({
56+ * url: 'https://api.mapbox.com/v4/mapbox.satellite/${z}/${x}/${y}.jpg?access_token=' + accessToken,
57+ * crs: 'EPSG:3857',
58+ * };
59+ *
60+ * // Create the layer
61+ * const imageryLayer = new itowns.ColorLayer("Ortho", {
62+ * source: orthoSource,
63+ * };
64+ *
65+ * // Add the layer to the view
66+ * view.addLayer(imageryLayer);
67+ * ```
68+ */
69+ export class TmsSource < Data > extends RemoteSource < Tile , Data > {
70+ /** Used to checkout whether this source is a TMSSource. */
2471 public readonly isTMSSource = true as const ;
2572 public readonly isSourceEventHandler = true as const ;
2673
74+ public readonly capabilities : SourceCapabilities = {
75+ layerEventHandler : {
76+ onLayerAdded : this . onLayerAdded ,
77+ onLayerRemoved : this . onLayerRemoved ,
78+ } ,
79+ } ;
80+
81+ /**
82+ * Minimum and maximum values of the zoom level.
83+ * Defaults are 0 and Infinity.
84+ */
2785 public zoom : { min : number ; max : number ; } ;
86+ /**
87+ * The isInverted property is to be set to the correct value, true or false
88+ * (default being false) if the computation of the coordinates needs to be
89+ * inverted to match the same scheme as OSM, Google Maps or other system.
90+ * See [this link](https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/)
91+ * for more information.
92+ */
2893 public isInverted : boolean ;
2994
95+ /** Describes the available tile for this layer. */
3096 public tileMatrixSetLimits ?: Record < number , TmsLimit > ;
3197
98+ /** These are the extents of the set of identical zoom tiles. */
3299 public extentSetLimits : Record < string , Record < number , Extent > > ;
33100
101+ /**
102+ * Creates a TileMatrix identifier from the zoom level. For example, if set
103+ * to `(zoomLevel) => 'EPSG:4326:' + zoomLevel`, the TileMatrix that will be
104+ * fetched at zoom level 5 will be the one with identifier `EPSG:4326:5`.
105+ * By default, the method returns the input zoom level.
106+ */
34107 public tileMatrixCallback : ( level : number ) => string ;
35108
36- protected constructor (
109+ public constructor (
37110 options : TmsSourceOptions < Data > ,
38111 ) {
39112 super ( options ) ;
@@ -60,13 +133,6 @@ export class TmsSource<Data extends THREE.Texture>
60133 max : Infinity ,
61134 } ;
62135 }
63-
64- this . capabilities = {
65- layerEventHandler : {
66- onLayerAdded : this . onLayerAdded ,
67- onLayerRemoved : this . onLayerRemoved ,
68- } ,
69- } ;
70136 }
71137
72138 public async load ( tile : Tile ) : Promise < Data > {
0 commit comments