@loaders.gl/wms 3.3.0-alpha.13 → 3.3.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/dist.min.js +182 -1046
  2. package/dist/es5/index.js +20 -13
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/lerc-loader.js +1 -1
  5. package/dist/es5/lib/data-sources/adhoc-image-service.js +4 -0
  6. package/dist/es5/lib/data-sources/adhoc-image-service.js.map +1 -1
  7. package/dist/es5/lib/data-sources/arcgis-image-service.js +180 -0
  8. package/dist/es5/lib/data-sources/arcgis-image-service.js.map +1 -0
  9. package/dist/es5/lib/data-sources/create-image-source.js +45 -0
  10. package/dist/es5/lib/data-sources/create-image-source.js.map +1 -0
  11. package/dist/es5/lib/data-sources/image-services/arcgis-image-service.js +179 -0
  12. package/dist/es5/lib/data-sources/image-services/arcgis-image-service.js.map +1 -0
  13. package/dist/es5/lib/data-sources/image-services/image-service.js +163 -0
  14. package/dist/es5/lib/data-sources/image-services/image-service.js.map +1 -0
  15. package/dist/es5/lib/data-sources/{wms-service.js → image-services/wms-service.js} +116 -75
  16. package/dist/es5/lib/data-sources/image-services/wms-service.js.map +1 -0
  17. package/dist/es5/wip/arcgis-feature-service.js +45 -0
  18. package/dist/es5/wip/arcgis-feature-service.js.map +1 -0
  19. package/dist/es5/wip/data-source.js.map +1 -1
  20. package/dist/es5/wip/gml-loader.js +1 -1
  21. package/dist/es5/wip/wcs-capabilities-loader.js +1 -1
  22. package/dist/es5/wip/wfs-capabilities-loader.js +1 -1
  23. package/dist/es5/wip/wmts-capabilities-loader.js +1 -1
  24. package/dist/es5/wms-capabilities-loader.js +1 -1
  25. package/dist/es5/wms-error-loader.js +1 -1
  26. package/dist/esm/index.js +5 -5
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/lerc-loader.js +1 -1
  29. package/dist/esm/lib/data-sources/adhoc-image-service.js +2 -0
  30. package/dist/esm/lib/data-sources/adhoc-image-service.js.map +1 -1
  31. package/dist/esm/lib/data-sources/arcgis-image-service.js +62 -0
  32. package/dist/esm/lib/data-sources/arcgis-image-service.js.map +1 -0
  33. package/dist/esm/lib/data-sources/create-image-source.js +30 -0
  34. package/dist/esm/lib/data-sources/create-image-source.js.map +1 -0
  35. package/dist/esm/lib/data-sources/image-services/arcgis-image-service.js +61 -0
  36. package/dist/esm/lib/data-sources/image-services/arcgis-image-service.js.map +1 -0
  37. package/dist/esm/lib/data-sources/image-services/image-service.js +72 -0
  38. package/dist/esm/lib/data-sources/image-services/image-service.js.map +1 -0
  39. package/dist/esm/lib/data-sources/{wms-service.js → image-services/wms-service.js} +46 -32
  40. package/dist/esm/lib/data-sources/image-services/wms-service.js.map +1 -0
  41. package/dist/esm/wip/arcgis-feature-service.js +28 -0
  42. package/dist/esm/wip/arcgis-feature-service.js.map +1 -0
  43. package/dist/esm/wip/data-source.js.map +1 -1
  44. package/dist/esm/wip/gml-loader.js +1 -1
  45. package/dist/esm/wip/wcs-capabilities-loader.js +1 -1
  46. package/dist/esm/wip/wfs-capabilities-loader.js +1 -1
  47. package/dist/esm/wip/wmts-capabilities-loader.js +1 -1
  48. package/dist/esm/wms-capabilities-loader.js +1 -1
  49. package/dist/esm/wms-error-loader.js +1 -1
  50. package/dist/index.d.ts +9 -7
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +14 -8
  53. package/dist/lib/data-sources/adhoc-image-service.d.ts +2 -0
  54. package/dist/lib/data-sources/adhoc-image-service.d.ts.map +1 -1
  55. package/dist/lib/data-sources/adhoc-image-service.js +2 -0
  56. package/dist/lib/data-sources/arcgis-image-service.d.ts +79 -0
  57. package/dist/lib/data-sources/arcgis-image-service.d.ts.map +1 -0
  58. package/dist/lib/data-sources/arcgis-image-service.js +85 -0
  59. package/dist/lib/data-sources/create-image-source.d.ts +16 -0
  60. package/dist/lib/data-sources/create-image-source.d.ts.map +1 -0
  61. package/dist/lib/data-sources/create-image-source.js +39 -0
  62. package/dist/lib/data-sources/image-services/arcgis-image-service.d.ts +71 -0
  63. package/dist/lib/data-sources/image-services/arcgis-image-service.d.ts.map +1 -0
  64. package/dist/lib/data-sources/image-services/arcgis-image-service.js +85 -0
  65. package/dist/lib/data-sources/image-services/image-service.d.ts +39 -0
  66. package/dist/lib/data-sources/image-services/image-service.d.ts.map +1 -0
  67. package/dist/lib/data-sources/image-services/image-service.js +82 -0
  68. package/dist/lib/data-sources/{wms-service.d.ts → image-services/wms-service.d.ts} +33 -38
  69. package/dist/lib/data-sources/image-services/wms-service.d.ts.map +1 -0
  70. package/dist/lib/data-sources/{wms-service.js → image-services/wms-service.js} +40 -28
  71. package/dist/wip/arcgis-feature-service.d.ts +56 -0
  72. package/dist/wip/arcgis-feature-service.d.ts.map +1 -0
  73. package/dist/wip/arcgis-feature-service.js +28 -0
  74. package/dist/wip/data-source.d.ts +14 -13
  75. package/dist/wip/data-source.d.ts.map +1 -1
  76. package/dist/wip/data-source.js +15 -13
  77. package/package.json +6 -6
  78. package/src/index.ts +13 -8
  79. package/src/lib/data-sources/adhoc-image-service.ts +3 -0
  80. package/src/lib/data-sources/arcgis-image-service.ts +146 -0
  81. package/src/lib/data-sources/create-image-source.ts +46 -0
  82. package/src/lib/data-sources/image-services/arcgis-image-service.ts +136 -0
  83. package/src/lib/data-sources/image-services/image-service.ts +105 -0
  84. package/src/lib/data-sources/{wms-service.ts → image-services/wms-service.ts} +51 -47
  85. package/src/wip/arcgis-feature-service.ts +89 -0
  86. package/src/wip/data-source.ts +15 -13
  87. package/dist/es5/lib/data-sources/wms-service.js.map +0 -1
  88. package/dist/esm/lib/data-sources/wms-service.js.map +0 -1
  89. package/dist/lib/data-sources/wms-service.d.ts.map +0 -1
@@ -4,22 +4,10 @@
4
4
  // export abstract class DataSource {};
5
5
  // export type DataSourceMetadata = {};
6
6
  // ImageSource
7
+ // Tile Source
7
8
  /** Data source that serves data by tile index *
8
9
  export abstract class TileDataSource extends DataSource {};
9
10
 
10
- // Vector Tile Source
11
-
12
- export type VectorTileDataSourceCapabilities = {
13
- // check tile.json
14
- }
15
-
16
- export type VectorTile = Record<string, any>;
17
-
18
- export abstract class VectorTileDataSource extends TileDataSource {
19
- abstract getCapabilities(): Promise<VectorTileDataSourceCapabilities>;
20
- abstract getTile({x, y, z, width, height, layers, parameters}): Promise<VectorTile>;
21
- }
22
-
23
11
  // Image Tile Data Source
24
12
 
25
13
  export type ImageTileDataSourceCapabilities = {
@@ -54,4 +42,18 @@ export abstract class ImageTileDataSource extends TileDataSource {
54
42
  return [0, 0, 1, 1];
55
43
  }
56
44
  }
45
+
46
+ // Vector Tile Source
47
+
48
+ export type VectorTileDataSourceCapabilities = {
49
+ // check tile.json
50
+ }
51
+
52
+ export type VectorTile = Record<string, any>;
53
+
54
+ export abstract class VectorTileDataSource extends TileDataSource {
55
+ abstract getCapabilities(): Promise<VectorTileDataSourceCapabilities>;
56
+ abstract getTile({x, y, z, width, height, layers, parameters}): Promise<VectorTile>;
57
+ }
58
+
57
59
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/wms",
3
- "version": "3.3.0-alpha.13",
3
+ "version": "3.3.0-alpha.14",
4
4
  "description": "Framework-independent loaders for the WMS (Web Map Service) standard",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -39,10 +39,10 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@babel/runtime": "^7.3.1",
42
- "@loaders.gl/images": "3.3.0-alpha.13",
43
- "@loaders.gl/loader-utils": "3.3.0-alpha.13",
44
- "@loaders.gl/schema": "3.3.0-alpha.13",
45
- "@loaders.gl/xml": "3.3.0-alpha.13",
42
+ "@loaders.gl/images": "3.3.0-alpha.14",
43
+ "@loaders.gl/loader-utils": "3.3.0-alpha.14",
44
+ "@loaders.gl/schema": "3.3.0-alpha.14",
45
+ "@loaders.gl/xml": "3.3.0-alpha.14",
46
46
  "@turf/rewind": "^5.1.5",
47
47
  "deep-strict-equal": "^0.2.0",
48
48
  "lerc": "^4.0.1"
@@ -50,5 +50,5 @@
50
50
  "devDependencies": {
51
51
  "xmldom": "0.6.0"
52
52
  },
53
- "gitHead": "429a5667c9903cc2de4d1f3e55e1c2f2e58a3ff6"
53
+ "gitHead": "cc91201ca3c0581a5c9edf7a8bc0fc230212bf3d"
54
54
  }
package/src/index.ts CHANGED
@@ -9,14 +9,18 @@ export type {WMSLoaderOptions} from './wms-capabilities-loader';
9
9
  export type {WMSCapabilities} from './lib/wms/wms-types';
10
10
  export {WMSCapabilitiesLoader} from './wms-capabilities-loader';
11
11
 
12
- export type {WMSServiceProps} from './lib/data-sources/wms-service';
13
- export {WMSService} from './lib/data-sources/wms-service';
14
-
15
12
  // NOTE: Will likely move to tiles module
16
- export type {ImageSourceMetadata as _ImageSourceMetadata} from './lib/data-sources/image-source';
17
- export {ImageSource as _ImageSource} from './lib/data-sources/image-source';
13
+ export type {ImageSourceMetadata} from './lib/data-sources/image-source';
14
+ export type {ImageType} from '@loaders.gl/images';
15
+ export {ImageSource} from './lib/data-sources/image-source';
16
+
17
+ export type {ImageServiceType} from './lib/data-sources/create-image-source';
18
+ export {createImageSource} from './lib/data-sources/create-image-source';
18
19
 
19
- export {AdHocImageService as _AdHocImageService} from './lib/data-sources/adhoc-image-service';
20
+ export type {ImageServiceProps} from './lib/data-sources/image-services/image-service';
21
+ export {ImageService} from './lib/data-sources/image-services/image-service';
22
+ export {WMSService} from './lib/data-sources/image-services/wms-service';
23
+ export {ArcGISImageService as _ArcGISImageService} from './lib/data-sources/image-services/arcgis-image-service';
20
24
 
21
25
  // WIP /////////////////////////////////////////////////////////////////
22
26
  // Plumbing set up but details of parsing and typing not yet completed
@@ -49,5 +53,6 @@ export {GMLLoader as _GMLLoader} from './wip/gml-loader';
49
53
 
50
54
  // LERC
51
55
 
52
- export type {LERCData} from './lib/lerc/lerc-types';
53
- export {LERCLoader} from './lerc-loader';
56
+ // TODO - restore once esbuild bundling issues have been resolved
57
+ // export type {LERCData} from './lib/lerc/lerc-types';
58
+ // export {LERCLoader} from './lerc-loader';
@@ -17,6 +17,9 @@ export type AdHocImageServiceProps = {
17
17
  * Accepts a template url string and builds requests URLs
18
18
  */
19
19
  export class AdHocImageService extends ImageSource {
20
+ static type: 'template' = 'template';
21
+ static testURL = (url: string): boolean => url.toLowerCase().includes('{');
22
+
20
23
  templateUrl: string;
21
24
 
22
25
  constructor(props: AdHocImageServiceProps) {
@@ -0,0 +1,146 @@
1
+ // loaders.gl, MIT license
2
+
3
+ import {LoaderOptions} from '@loaders.gl/loader-utils';
4
+ import {/* ImageLoader, */ ImageType} from '@loaders.gl/images';
5
+ import type {ImageSourceMetadata, GetImageParameters} from './image-source';
6
+ import {ImageSource} from './image-source';
7
+
8
+ type FetchLike = (url: string, options?: RequestInit) => Promise<Response>;
9
+
10
+ export type ArcGISImageServiceProps = {
11
+ url: string;
12
+ loadOptions?: LoaderOptions;
13
+ fetch?: typeof fetch | FetchLike;
14
+ };
15
+
16
+ export class ArcGISImageService extends ImageSource {
17
+ static type: 'arcgis-image-server' = 'arcgis-image-server';
18
+ static testURL = (url: string): boolean => url.toLowerCase().includes('ImageServer');
19
+
20
+ url: string;
21
+ loadOptions: LoaderOptions;
22
+ fetch: typeof fetch | FetchLike;
23
+
24
+ constructor(props: ArcGISImageServiceProps) {
25
+ super();
26
+ this.url = props.url;
27
+ this.loadOptions = props.loadOptions || {};
28
+ this.fetch = props.fetch || fetch;
29
+ }
30
+
31
+ // ImageSource (normalized endpoints)
32
+
33
+ async getMetadata(): Promise<ImageSourceMetadata> {
34
+ return (await this.info()) as ImageSourceMetadata;
35
+ // TODO - normalize metadata
36
+ }
37
+
38
+ async getImage(parameters: GetImageParameters): Promise<ImageType> {
39
+ throw new Error('not implemented');
40
+ // TODO - Map generic parameters to ArcGIS specific parameters
41
+ // return await this.exportImage(parameters);
42
+ }
43
+
44
+ // ImageServer endpoints
45
+
46
+ async info(): Promise<unknown> {
47
+ // We just need a JSON parsing...
48
+ // return this.getUrl({path: '', ...options});
49
+ throw new Error('not implemented');
50
+ }
51
+
52
+ /**
53
+ * Form a URL to an ESRI ImageServer
54
+ // https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer/exportImage?bbox=${bounds[0]},${bounds[1]},${bounds[2]},${bounds[3]}&bboxSR=4326&size=${width},${height}&imageSR=102100&time=&format=jpgpng&pixelType=U8&noData=&noDataInterpretation=esriNoDataMatchAny&interpolation=+RSP_NearestNeighbor&compression=&compressionQuality=&bandIds=&mosaicRule=&renderingRule=&f=image`,
55
+ */
56
+ exportImage(options: {
57
+ boundingBox: [number, number, number, number];
58
+ boundingBoxSR?: string;
59
+ width: number;
60
+ height: number;
61
+ imageSR?: string;
62
+ time?: never;
63
+ format?: 'jpgpng';
64
+ pixelType?: 'U8';
65
+ noData?: never;
66
+ noDataInterpretation?: 'esriNoDataMatchAny';
67
+ interpolation?: '+RSP_NearestNeighbor';
68
+ compression?: never;
69
+ compressionQuality?: never;
70
+ bandIds?: never;
71
+ mosaicRule?: never;
72
+ renderingRule?: never;
73
+ f?: 'image';
74
+ }): Promise<ImageType> {
75
+ // See WMSService.getMap()
76
+ throw new Error('not implemented');
77
+ }
78
+
79
+ // URL creators
80
+
81
+ infoURL(options: {parameters?: Record<string, unknown>}): string {
82
+ return this.url;
83
+ // return this.getUrl({path: '', ...options});
84
+ }
85
+
86
+ /**
87
+ * Form a URL to an ESRI ImageServer
88
+ // https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer/exportImage?bbox=${bounds[0]},${bounds[1]},${bounds[2]},${bounds[3]}&bboxSR=4326&size=${width},${height}&imageSR=102100&time=&format=jpgpng&pixelType=U8&noData=&noDataInterpretation=esriNoDataMatchAny&interpolation=+RSP_NearestNeighbor&compression=&compressionQuality=&bandIds=&mosaicRule=&renderingRule=&f=image`,
89
+ */
90
+ exportImageURL(options: {
91
+ boundingBox: [number, number, number, number];
92
+ boundingBoxSR?: string;
93
+ width: number;
94
+ height: number;
95
+ imageSR?: string;
96
+ time?: never;
97
+ format?: 'jpgpng';
98
+ pixelType?: 'U8';
99
+ noData?: never;
100
+ noDataInterpretation?: 'esriNoDataMatchAny';
101
+ interpolation?: '+RSP_NearestNeighbor';
102
+ compression?: never;
103
+ compressionQuality?: never;
104
+ bandIds?: never;
105
+ mosaicRule?: never;
106
+ renderingRule?: never;
107
+ f?: 'image';
108
+ }): string {
109
+ // const {boundingBox} = options;
110
+ // const bbox = `bbox=${boundingBox[0]},${boundingBox[1]},${boundingBox[2]},${boundingBox[3]}`;
111
+ // const size = `size=${width},${height}`;
112
+ // return this.getUrl({path: 'exportImage'});
113
+ return this.url;
114
+ }
115
+
116
+ // INTERNAL METHODS
117
+
118
+ /**
119
+ * @note protected, since perhaps getWMSUrl may need to be overridden to handle certain backends?
120
+ * @note if override is common, maybe add a callback prop?
121
+ * */
122
+ protected getUrl(options: Record<string, unknown>, extra?: Record<string, unknown>): string {
123
+ let url = `${this.url}`;
124
+ let first = true;
125
+ for (const [key, value] of Object.entries(options)) {
126
+ url += first ? '?' : '&';
127
+ first = false;
128
+ if (Array.isArray(value)) {
129
+ url += `${key.toUpperCase()}=${value.join(',')}`;
130
+ } else {
131
+ url += `${key.toUpperCase()}=${value ? String(value) : ''}`;
132
+ }
133
+ }
134
+ return url;
135
+ }
136
+
137
+ /** Checks for and parses a WMS XML formatted ServiceError and throws an exception */
138
+ protected async checkResponse(response: Response) {
139
+ if (!response.ok) {
140
+ // } || response.headers['content-type'] === WMSErrorLoader.mimeTypes[0]) {
141
+ // const arrayBuffer = await response.arrayBuffer();
142
+ // const error = await WMSErrorLoader.parse(arrayBuffer, this.loadOptions);
143
+ throw new Error('error');
144
+ }
145
+ }
146
+ }
@@ -0,0 +1,46 @@
1
+ // loaders.gl, MIT license
2
+
3
+ import {ImageSource} from './image-source';
4
+ import {ImageService, ImageServiceProps} from './image-services/image-service';
5
+ import {WMSService} from './image-services/wms-service';
6
+ import {ArcGISImageService} from './image-services/arcgis-image-service';
7
+
8
+ export type ImageServiceType = 'wms' | 'arcgis-image-server' | 'template';
9
+
10
+ const SERVICES = [WMSService, ArcGISImageService, ImageService];
11
+
12
+ type Props = ImageServiceProps & {
13
+ type?: ImageServiceType | 'auto';
14
+ };
15
+
16
+ /**
17
+ * Creates an image source
18
+ * If type is not supplied, will try to automatically detec the the
19
+ * @param url URL to the image source
20
+ * @param type type of source. if not known, set to 'auto'
21
+ * @returns an ImageSource instance
22
+ */
23
+ export function createImageSource(props: Props): ImageSource {
24
+ const {type = 'auto'} = props;
25
+ const serviceType = type === 'auto' ? guessServiceType(props.url) : type;
26
+ switch (serviceType) {
27
+ case 'template':
28
+ return new ImageService(props);
29
+ case 'wms':
30
+ return new WMSService(props);
31
+ default:
32
+ // currently only wms service supported
33
+ throw new Error('Not a valid image source type');
34
+ }
35
+ }
36
+
37
+ /** Guess service type from URL */
38
+ function guessServiceType(url: string): ImageServiceType {
39
+ for (const Service of SERVICES) {
40
+ if (Service.testURL && Service.testURL(url)) {
41
+ return Service.type;
42
+ }
43
+ }
44
+ // If all else fails, guess that this is MS service
45
+ return 'wms';
46
+ }
@@ -0,0 +1,136 @@
1
+ // loaders.gl, MIT license
2
+
3
+ import {ImageType} from '@loaders.gl/images';
4
+ import type {ImageSourceMetadata, GetImageParameters} from '../image-source';
5
+ import {ImageSource} from '../image-source';
6
+ import {ImageServiceProps, mergeImageServiceProps, getFetchFunction} from './image-service';
7
+
8
+ export class ArcGISImageService extends ImageSource {
9
+ static type: 'arcgis-image-server' = 'arcgis-image-server';
10
+ static testURL = (url: string): boolean => url.toLowerCase().includes('ImageServer');
11
+
12
+ props: Required<ImageServiceProps>;
13
+ fetch: (url: string, options?: RequestInit) => Promise<Response>;
14
+
15
+ constructor(props: ImageServiceProps) {
16
+ super();
17
+ this.props = mergeImageServiceProps(props);
18
+ this.fetch = getFetchFunction(this.props);
19
+ }
20
+
21
+ // ImageSource (normalized endpoints)
22
+
23
+ async getMetadata(): Promise<ImageSourceMetadata> {
24
+ return (await this.info()) as ImageSourceMetadata;
25
+ // TODO - normalize metadata
26
+ }
27
+
28
+ async getImage(parameters: GetImageParameters): Promise<ImageType> {
29
+ throw new Error('not implemented');
30
+ // TODO - Map generic parameters to ArcGIS specific parameters
31
+ // return await this.exportImage(parameters);
32
+ }
33
+
34
+ // ImageServer endpoints
35
+
36
+ async info(): Promise<unknown> {
37
+ // We just need a JSON parsing...
38
+ // return this.getUrl({path: '', ...options});
39
+ throw new Error('not implemented');
40
+ }
41
+
42
+ /**
43
+ * Form a URL to an ESRI ImageServer
44
+ // https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer/exportImage?bbox=${bounds[0]},${bounds[1]},${bounds[2]},${bounds[3]}&bboxSR=4326&size=${width},${height}&imageSR=102100&time=&format=jpgpng&pixelType=U8&noData=&noDataInterpretation=esriNoDataMatchAny&interpolation=+RSP_NearestNeighbor&compression=&compressionQuality=&bandIds=&mosaicRule=&renderingRule=&f=image`,
45
+ */
46
+ exportImage(options: {
47
+ boundingBox: [number, number, number, number];
48
+ boundingBoxSR?: string;
49
+ width: number;
50
+ height: number;
51
+ imageSR?: string;
52
+ time?: never;
53
+ format?: 'jpgpng';
54
+ pixelType?: 'U8';
55
+ noData?: never;
56
+ noDataInterpretation?: 'esriNoDataMatchAny';
57
+ interpolation?: '+RSP_NearestNeighbor';
58
+ compression?: never;
59
+ compressionQuality?: never;
60
+ bandIds?: never;
61
+ mosaicRule?: never;
62
+ renderingRule?: never;
63
+ f?: 'image';
64
+ }): Promise<ImageType> {
65
+ // See WMSService.getMap()
66
+ throw new Error('not implemented');
67
+ }
68
+
69
+ // URL creators
70
+
71
+ infoURL(options: {parameters?: Record<string, unknown>}): string {
72
+ return this.props.url;
73
+ // return this.getUrl({path: '', ...options});
74
+ }
75
+
76
+ /**
77
+ * Form a URL to an ESRI ImageServer
78
+ // https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer/exportImage?bbox=${bounds[0]},${bounds[1]},${bounds[2]},${bounds[3]}&bboxSR=4326&size=${width},${height}&imageSR=102100&time=&format=jpgpng&pixelType=U8&noData=&noDataInterpretation=esriNoDataMatchAny&interpolation=+RSP_NearestNeighbor&compression=&compressionQuality=&bandIds=&mosaicRule=&renderingRule=&f=image`,
79
+ */
80
+ exportImageURL(options: {
81
+ boundingBox: [number, number, number, number];
82
+ boundingBoxSR?: string;
83
+ width: number;
84
+ height: number;
85
+ imageSR?: string;
86
+ time?: never;
87
+ format?: 'jpgpng';
88
+ pixelType?: 'U8';
89
+ noData?: never;
90
+ noDataInterpretation?: 'esriNoDataMatchAny';
91
+ interpolation?: '+RSP_NearestNeighbor';
92
+ compression?: never;
93
+ compressionQuality?: never;
94
+ bandIds?: never;
95
+ mosaicRule?: never;
96
+ renderingRule?: never;
97
+ f?: 'image';
98
+ }): string {
99
+ // const {boundingBox} = options;
100
+ // const bbox = `bbox=${boundingBox[0]},${boundingBox[1]},${boundingBox[2]},${boundingBox[3]}`;
101
+ // const size = `size=${width},${height}`;
102
+ // return this.getUrl({path: 'exportImage'});
103
+ return this.props.url;
104
+ }
105
+
106
+ // INTERNAL METHODS
107
+
108
+ /**
109
+ * @note protected, since perhaps getWMSUrl may need to be overridden to handle certain backends?
110
+ * @note if override is common, maybe add a callback prop?
111
+ * */
112
+ protected getUrl(options: Record<string, unknown>, extra?: Record<string, unknown>): string {
113
+ let url = `${this.props.url}`;
114
+ let first = true;
115
+ for (const [key, value] of Object.entries(options)) {
116
+ url += first ? '?' : '&';
117
+ first = false;
118
+ if (Array.isArray(value)) {
119
+ url += `${key.toUpperCase()}=${value.join(',')}`;
120
+ } else {
121
+ url += `${key.toUpperCase()}=${value ? String(value) : ''}`;
122
+ }
123
+ }
124
+ return url;
125
+ }
126
+
127
+ /** Checks for and parses a WMS XML formatted ServiceError and throws an exception */
128
+ protected async checkResponse(response: Response) {
129
+ if (!response.ok) {
130
+ // } || response.headers['content-type'] === WMSErrorLoader.mimeTypes[0]) {
131
+ // const arrayBuffer = await response.arrayBuffer();
132
+ // const error = await WMSErrorLoader.parse(arrayBuffer, this.loadOptions);
133
+ throw new Error('error');
134
+ }
135
+ }
136
+ }
@@ -0,0 +1,105 @@
1
+ // loaders.gl, MIT license
2
+
3
+ import {LoaderOptions} from '@loaders.gl/loader-utils';
4
+ import type {ImageType} from '@loaders.gl/images';
5
+ import {ImageLoader} from '@loaders.gl/images';
6
+
7
+ import type {ImageSourceMetadata, GetImageParameters} from '../image-source';
8
+ import {ImageSource} from '../image-source';
9
+
10
+ /** Template URL string should contain `${width}` etc which will be substituted. */
11
+ export type ImageServiceProps = {
12
+ /** Base URL to the service */
13
+ url: string;
14
+ /** Any load options to the loaders.gl Loaders used by the WMSService methods */
15
+ loadOptions?: LoaderOptions;
16
+ };
17
+
18
+ /**
19
+ * Quickly connect to "ad hoc" image sources without subclassing ImageSource.
20
+ * ImageSource allows template url strings to be used to ad hoc connect to arbitrary image data sources
21
+ * Accepts a template url string and builds requests URLs
22
+ */
23
+ export class ImageService extends ImageSource {
24
+ static type: 'template' = 'template';
25
+ static testURL = (url: string): boolean => url.toLowerCase().includes('{');
26
+
27
+ props: Required<ImageServiceProps>;
28
+ fetch: (url: string, options?: RequestInit) => Promise<Response>;
29
+
30
+ constructor(props: ImageServiceProps) {
31
+ super();
32
+ this.props = mergeImageServiceProps(props);
33
+ this.fetch = getFetchFunction(props);
34
+ }
35
+
36
+ // IMAGE SOURCE API
37
+
38
+ async getMetadata(): Promise<ImageSourceMetadata> {
39
+ throw new Error('ImageSource.getMetadata not implemented');
40
+ }
41
+
42
+ async getImage(parameters: GetImageParameters): Promise<ImageType> {
43
+ const granularParameters = this.getGranularParameters(parameters);
44
+ const url = this.getURLFromTemplate(granularParameters);
45
+ const response = await this.fetch(url);
46
+ const arrayBuffer = await response.arrayBuffer();
47
+ return await ImageLoader.parse(arrayBuffer);
48
+ }
49
+
50
+ // HELPERS
51
+
52
+ /** Break up bounding box in east, north, south, west */
53
+ protected getGranularParameters(parameters: GetImageParameters): Record<string, unknown> {
54
+ const [east, north, west, south] = parameters.bbox;
55
+ return {...parameters, east, north, south, west};
56
+ }
57
+
58
+ /** Supports both ${} and {} notations */
59
+ protected getURLFromTemplate(parameters: Record<string, unknown>): string {
60
+ let url = this.props.url;
61
+ for (const [key, value] of Object.entries(parameters)) {
62
+ // TODO - parameter could be repeated
63
+ // const regex = new RegExp(`\${${key}}`, 'g');
64
+ url = url.replace(`\${${key}}`, String(value));
65
+ url = url.replace(`{${key}}`, String(value));
66
+ }
67
+ return url;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Gets the current fetch function from options
73
+ * @todo - move to loader-utils module
74
+ * @todo - use in core module counterpart
75
+ * @param options
76
+ * @param context
77
+ */
78
+ export function getFetchFunction(options?: LoaderOptions) {
79
+ const fetchFunction = options?.fetch;
80
+
81
+ // options.fetch can be a function
82
+ if (fetchFunction && typeof fetchFunction === 'function') {
83
+ return (url: string, fetchOptions?: RequestInit) => fetchFunction(url, fetchOptions);
84
+ }
85
+
86
+ // options.fetch can be an options object, use global fetch with those options
87
+ const fetchOptions = options?.fetch;
88
+ if (fetchOptions && typeof fetchOptions !== 'function') {
89
+ return (url) => fetch(url, fetchOptions);
90
+ }
91
+
92
+ // else return the global fetch function
93
+ return (url) => fetch(url);
94
+ }
95
+
96
+ export function mergeImageServiceProps(props: ImageServiceProps): Required<ImageServiceProps> {
97
+ return {
98
+ // Default fetch
99
+ ...props,
100
+ loadOptions: {
101
+ ...props.loadOptions,
102
+ fetch: getFetchFunction(props.loadOptions)
103
+ }
104
+ };
105
+ }