ogcopenapis 0.0.3 → 0.0.5

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.
@@ -4,6 +4,6 @@ declare class OgcOpenApiCrsTools {
4
4
  * @param uriOrName
5
5
  * @private
6
6
  */
7
- static getReferenceName(uriOrName: string): string;
7
+ static getReferenceName(uriOrNameI: string): string;
8
8
  }
9
9
  export { OgcOpenApiCrsTools };
@@ -4,7 +4,10 @@ class OgcOpenApiCrsTools {
4
4
  * @param uriOrName
5
5
  * @private
6
6
  */
7
- static getReferenceName(uriOrName) {
7
+ static getReferenceName(uriOrNameI) {
8
+ if (typeof uriOrNameI === "undefined")
9
+ return uriOrNameI;
10
+ const uriOrName = uriOrNameI.replace(/[<>]/g, '');
8
11
  if (!uriOrName.startsWith('http')) {
9
12
  return uriOrName;
10
13
  }
@@ -5,12 +5,14 @@ import { Evented, Handle } from '@luciad/ria/util/Evented';
5
5
  import { Bounds } from '@luciad/ria/shape/Bounds';
6
6
  import { Codec, CodecDecodeOptions } from '@luciad/ria/model/codec/Codec';
7
7
  import { CoordinateReference } from '@luciad/ria/reference/CoordinateReference';
8
- interface OAPIFeatureStoreConstructorOptions {
8
+ import { ProxifyFunction } from "./OgcOpenApiGetCapabilities";
9
+ export interface OgcOpenApiFeatureStoreConstructorOptions {
9
10
  dataUrl: string;
10
11
  featureUrl?: string;
11
12
  outputFormat: string;
12
- useCrs84Bounds: boolean;
13
+ useCrs84Bounds?: boolean;
13
14
  codec: Codec;
15
+ credentials?: boolean;
14
16
  requestHeaders?: {
15
17
  [key: string]: string;
16
18
  };
@@ -21,8 +23,9 @@ interface OAPIFeatureStoreConstructorOptions {
21
23
  };
22
24
  };
23
25
  reference: CoordinateReference;
26
+ proxify?: ProxifyFunction;
24
27
  }
25
- interface OAPIFeatureStoreQueryOptions {
28
+ export interface OgcOpenApiFeatureStoreQueryOptions {
26
29
  f?: string;
27
30
  limit?: number;
28
31
  offset?: number;
@@ -57,7 +60,7 @@ interface OAPIFeatureStoreQueryOptions {
57
60
  wkhrCode?: string;
58
61
  wkhrRemark?: string;
59
62
  }
60
- interface OgcOpenApiCodecDecodeOptions extends CodecDecodeOptions {
63
+ interface OgcOpenApiFeaturesCodecDecodeOptions extends CodecDecodeOptions {
61
64
  contentCrs?: string;
62
65
  contentLength?: number;
63
66
  }
@@ -74,13 +77,16 @@ export declare class OgcOpenApiFeatureStore implements Store, Evented {
74
77
  private outputFormat;
75
78
  private useCrs84Bounds;
76
79
  private featureUrl;
77
- constructor(options: OAPIFeatureStoreConstructorOptions);
80
+ private proxy;
81
+ private credentials;
82
+ private serverOptions;
83
+ constructor(options: OgcOpenApiFeatureStoreConstructorOptions);
78
84
  on(event: string, callback: any, context: any, options: any): Handle;
79
85
  get(id: number | string, optionsInput?: any): Promise<Feature>;
80
- query(receivedQuery?: OAPIFeatureStoreQueryOptions, options?: any): Cursor | Promise<Cursor>;
81
- spatialQuery(bounds?: Bounds, receivedQuery?: OAPIFeatureStoreQueryOptions, options?: any): Promise<Cursor> | Cursor;
86
+ query(receivedQuery?: OgcOpenApiFeatureStoreQueryOptions, options?: any): Cursor | Promise<Cursor>;
87
+ spatialQuery(bounds?: Bounds, receivedQuery?: OgcOpenApiFeatureStoreQueryOptions, options?: any): Promise<Cursor> | Cursor;
82
88
  private static getCRS84BoundingBox;
83
89
  private static cleanUrl;
84
90
  private static dataFormatInQuery;
85
91
  }
86
- export { OgcOpenApiCodecDecodeOptions };
92
+ export { OgcOpenApiFeaturesCodecDecodeOptions };
@@ -2,6 +2,10 @@ import { EventedSupport } from '@luciad/ria/util/EventedSupport';
2
2
  import { createBounds } from '@luciad/ria/shape/ShapeFactory';
3
3
  import { getReference } from "@luciad/ria/reference/ReferenceProvider";
4
4
  import { createTransformation } from "@luciad/ria/transformation/TransformationFactory";
5
+ import { OgcOpenApiCrsTools } from "./OgcOpenApiCrsTools";
6
+ import { GeoJsonCodec } from "@luciad/ria/model/codec/GeoJsonCodec";
7
+ import { GMLCodec } from "@luciad/ria/model/codec/GMLCodec";
8
+ import { OgcOpenApiFetchTools } from "./OgcOpenApiFetchTools";
5
9
  export class OgcOpenApiFeatureStore {
6
10
  constructor(options) {
7
11
  // console.log(options);
@@ -17,6 +21,9 @@ export class OgcOpenApiFeatureStore {
17
21
  this.eventedSupport = new EventedSupport();
18
22
  this.requestHeaders = options.requestHeaders ? options.requestHeaders : {};
19
23
  this.reference = options.reference;
24
+ this.proxy = options.proxify;
25
+ this.credentials = options.credentials;
26
+ this.serverOptions = OgcOpenApiFetchTools.createFetchOptions({ originalUrl: this.dataUrl, proxify: options.proxify });
20
27
  if (options.extent &&
21
28
  options.extent.spatial &&
22
29
  options.extent.spatial.bbox &&
@@ -60,14 +67,15 @@ export class OgcOpenApiFeatureStore {
60
67
  request += "?" + queryString;
61
68
  }
62
69
  const headers = Object.assign(Object.assign({}, this.requestHeaders), { Accept: accept });
63
- fetch(request, {
70
+ OgcOpenApiFetchTools.fetch(request, {
64
71
  method: 'GET',
72
+ credentials: this.credentials ? "same-origin" : "omit",
65
73
  headers,
66
- }).then((response) => {
74
+ }, this.serverOptions).then((response) => {
67
75
  if (response.status === 200) {
68
76
  response.text().then((content) => {
69
77
  let contentType = response.headers.get('Content-Type');
70
- const contentCrs = response.headers.get('content-crs');
78
+ const contentCrs = response.headers.get('content-crs') ? response.headers.get('content-crs') : this.customCrs;
71
79
  const contentLengthStr = response.headers.get('Content-Length');
72
80
  const contentLength = Number(contentLengthStr);
73
81
  contentType = contentType ? contentType : 'text/plain';
@@ -120,14 +128,15 @@ export class OgcOpenApiFeatureStore {
120
128
  }
121
129
  const headers = Object.assign(Object.assign({}, this.requestHeaders), { Accept: accept });
122
130
  // const headers = { ...this.requestHeaders };
123
- fetch(request, {
131
+ OgcOpenApiFetchTools.fetch(request, {
124
132
  method: 'GET',
133
+ credentials: this.credentials ? "same-origin" : "omit",
125
134
  headers,
126
- }).then((response) => {
135
+ }, this.serverOptions).then((response) => {
127
136
  if (response.status === 200) {
128
137
  response.text().then((content) => {
129
138
  let contentType = response.headers.get('Content-Type');
130
- const contentCrs = response.headers.get('content-crs');
139
+ const contentCrs = response.headers.get('content-crs') ? response.headers.get('content-crs') : this.customCrs;
131
140
  const contentLengthStr = response.headers.get('Content-Length');
132
141
  const contentLength = Number(contentLengthStr);
133
142
  contentType = contentType ? contentType : 'text/plain';
@@ -137,8 +146,14 @@ export class OgcOpenApiFeatureStore {
137
146
  const codecOptions = {
138
147
  content, contentType, contentCrs, contentLength
139
148
  };
140
- const cursor = this.codec.decode(codecOptions);
141
- resolve(cursor);
149
+ if (this.codec instanceof GeoJsonCodec || this.codec instanceof GMLCodec) {
150
+ const cursor = this.codec.decode(Object.assign(Object.assign({}, codecOptions), { reference: getReference(OgcOpenApiCrsTools.getReferenceName(contentCrs)) }));
151
+ resolve(cursor);
152
+ }
153
+ else {
154
+ const cursor = this.codec.decode(codecOptions);
155
+ resolve(cursor);
156
+ }
142
157
  });
143
158
  }
144
159
  });
@@ -1,10 +1,8 @@
1
+ import { ProxifyFunction } from "./OgcOpenApiGetCapabilities";
1
2
  interface ExtFetchOptions {
2
3
  originalUrl: string;
3
4
  complete?: (url: string) => string;
4
- proxify?: (url: string) => {
5
- url: string;
6
- fetchOptions: RequestInit;
7
- };
5
+ proxify?: ProxifyFunction;
8
6
  }
9
7
  export interface FetchServerOptions {
10
8
  proxy: (url: string, fetchOptions: any) => {
@@ -18,6 +18,8 @@ class OgcOpenApiFetchTools {
18
18
  return fetch(result.url, result.fetchOptions);
19
19
  }
20
20
  static addHostURL(url, HostUrl) {
21
+ if (typeof url === "undefined")
22
+ return url;
21
23
  const hostUrl = HostUrl ? HostUrl : "";
22
24
  if (url.startsWith("http://") || url.startsWith("https://")) {
23
25
  return url;
@@ -76,16 +76,17 @@ export declare enum CollectionLinkType {
76
76
  Map = "map",
77
77
  Tiles = "tiles"
78
78
  }
79
+ export type ProxifyFunction = (url: string, fetchOptions: RequestInit) => {
80
+ url: string;
81
+ fetchOptions: RequestInit;
82
+ };
79
83
  export interface OgcOpenApiGetCapabilitiesFromURL {
80
84
  filterCollectionsByLinkType?: CollectionLinkType;
81
85
  credentials?: boolean;
82
86
  requestHeaders?: {
83
87
  [headerName: string]: string;
84
88
  } | null;
85
- proxify?: (url: string) => {
86
- url: string;
87
- fetchOptions: RequestInit;
88
- };
89
+ proxify?: ProxifyFunction;
89
90
  }
90
91
  export declare class OgcOpenApiGetCapabilities {
91
92
  static fromURL(inputRequest: string, options?: OgcOpenApiGetCapabilitiesFromURL): Promise<OgcOpenApiCapabilitiesObject>;
@@ -98,10 +99,7 @@ export declare class OgcOpenApiGetCapabilities {
98
99
  requestHeaders?: RequestHeaders;
99
100
  }): Promise<TileSetData[]>;
100
101
  static getQuadTreeCompatibleLevelOffset(tileMatrixSet: TileSetData): number;
101
- static fetchTileSets(capabilities: OgcOpenApiCapabilitiesObject | null, options?: {
102
- credentials?: boolean;
103
- requestHeaders?: RequestHeaders;
104
- }): Promise<TileSetMeta[]>;
102
+ private static fetchTileSets;
105
103
  static getTilesLink(capabilities: OgcOpenApiCapabilitiesObject | null, currentCollection: OgcOpenApiCapabilitiesCollection, tileMatrixId: string, options?: {
106
104
  credentials?: boolean;
107
105
  requestHeaders?: RequestHeaders;
@@ -64,12 +64,13 @@ export class OgcOpenApiGetCapabilities {
64
64
  const layer = Object.assign({ description: collection.description, id: name, name, title: collection.title, keywords: collection.keywords
65
65
  ? collection.keywords
66
66
  : [], defaultReference: 'CRS:84', links: collection.links, outputFormats: options.filterCollectionsByLinkType ?
67
- this.filterCollectionLinks(collection.links, options.filterCollectionsByLinkType).map(link => this.detectTypeFormat(link)) :
68
- collection.links.map(link => this.detectTypeFormat(link)), extent: collection.extent }, collectionCrsObject);
67
+ this.filterCollectionLinks(collection.links, options.filterCollectionsByLinkType).map(link => this.detectTypeFormat(link))
68
+ :
69
+ collection.links.map(link => this.detectTypeFormat(link)), extent: collection.extent }, collectionCrsObject);
69
70
  return layer;
70
71
  });
71
72
  // console.log(featureTypes);
72
- const o = Object.assign(Object.assign({ name: '', collections: foundCollections, version: responseOpenApi ? responseOpenApi.openapi : '', service: '', info: responseOpenApi ? responseOpenApi.info : {} }, crsArray), { serverOptions: serverOptions, baseUrl });
73
+ const o = Object.assign(Object.assign({ name: '', collections: foundCollections.map(col => (Object.assign(Object.assign({}, col), { crs: col.crs ? col.crs : [], links: col.links.map(l => (Object.assign(Object.assign({}, l), { href: serverOptions.complete(l.href) }))) }))), version: responseOpenApi ? responseOpenApi.openapi : '', service: '', info: responseOpenApi ? responseOpenApi.info : {} }, crsArray), { serverOptions: serverOptions, baseUrl });
73
74
  resolve(o);
74
75
  });
75
76
  }
@@ -183,7 +184,7 @@ export class OgcOpenApiGetCapabilities {
183
184
  if (result.status === 200) {
184
185
  result.json().then((data) => {
185
186
  if (data.tileMatrixSets) {
186
- resolve(data.tileMatrixSets);
187
+ resolve(data.tileMatrixSets.map(tml => (Object.assign(Object.assign({}, tml), { href: capabilities.serverOptions.complete(tml.href) }))));
187
188
  }
188
189
  else {
189
190
  reject({ error: true, message: "tileMatrixSets not defined" });
@@ -2,12 +2,14 @@ import { RasterDataType } from "@luciad/ria/model/tileset/RasterDataType";
2
2
  import { RasterSamplingMode } from "@luciad/ria/model/tileset/RasterSamplingMode";
3
3
  import { WMSTileSetModel } from "@luciad/ria/model/tileset/WMSTileSetModel";
4
4
  import { TileCoordinate } from "@luciad/ria/model/tileset/TileCoordinate";
5
+ import { ProxifyFunction } from "./OgcOpenApiGetCapabilities";
5
6
  interface OgcOpenApiMapsModelConstructorOptions {
6
7
  crs: string;
7
8
  baseURL: string;
8
9
  collection: string;
9
10
  dataType?: RasterDataType;
10
11
  samplingMode?: RasterSamplingMode;
12
+ credentials?: boolean;
11
13
  requestHeaders?: {
12
14
  [p: string]: string;
13
15
  };
@@ -17,6 +19,7 @@ interface OgcOpenApiMapsModelConstructorOptions {
17
19
  subset?: string[];
18
20
  transparent?: boolean;
19
21
  bgcolor?: string;
22
+ proxify?: ProxifyFunction;
20
23
  }
21
24
  declare class OgcOpenApiMapsModel extends WMSTileSetModel {
22
25
  private format;
@@ -25,6 +28,7 @@ declare class OgcOpenApiMapsModel extends WMSTileSetModel {
25
28
  private datetime;
26
29
  private subset;
27
30
  private bgcolor;
31
+ private proxy;
28
32
  constructor(o: OgcOpenApiMapsModelConstructorOptions);
29
33
  getTileURL(baseURL: string, tile: TileCoordinate): string | null;
30
34
  private static createURLParameters;
@@ -11,6 +11,7 @@ class OgcOpenApiMapsModel extends WMSTileSetModel {
11
11
  layers: [o.collection],
12
12
  dataType: o.dataType,
13
13
  samplingMode: o.samplingMode,
14
+ credentials: o.credentials,
14
15
  requestHeaders: o.requestHeaders
15
16
  });
16
17
  this.crs = o.crs;
@@ -20,6 +21,7 @@ class OgcOpenApiMapsModel extends WMSTileSetModel {
20
21
  this.subset = o.subset;
21
22
  this.transparent = typeof o.transparent !== "undefined" ? o.transparent : true;
22
23
  this.bgcolor = o.bgcolor;
24
+ this.proxy = o.proxify;
23
25
  this.modelDescriptor = {
24
26
  source: o.baseURL,
25
27
  name: o.collection,
@@ -46,7 +48,11 @@ class OgcOpenApiMapsModel extends WMSTileSetModel {
46
48
  bgcolor: this.transparent ? undefined : this.bgcolor
47
49
  };
48
50
  const query = OgcOpenApiMapsModel.createURLParameters(urlParameters);
49
- const transformedUrl = url + "?" + query;
51
+ let transformedUrl = url + "?" + query;
52
+ if (typeof this.proxy === "function") {
53
+ const proxyfied = this.proxy(transformedUrl, {});
54
+ transformedUrl = proxyfied.url;
55
+ }
50
56
  return transformedUrl;
51
57
  }
52
58
  else {
@@ -2,18 +2,20 @@ import { UrlTileSetModel } from "@luciad/ria/model/tileset/UrlTileSetModel";
2
2
  import { RasterDataType } from "@luciad/ria/model/tileset/RasterDataType";
3
3
  import { RasterSamplingMode } from "@luciad/ria/model/tileset/RasterSamplingMode";
4
4
  import { TileCoordinate } from "@luciad/ria/model/tileset/TileCoordinate";
5
- import { TileSetData } from "./OgcOpenApiGetCapabilities";
5
+ import { ProxifyFunction, TileSetData } from "./OgcOpenApiGetCapabilities";
6
6
  export interface OgcOpenApiTilesModelOptions {
7
7
  tileMatrix: TileSetData;
8
8
  baseURL: string;
9
9
  collection: string;
10
10
  dataType?: RasterDataType;
11
11
  samplingMode?: RasterSamplingMode;
12
+ credentials?: boolean;
12
13
  requestHeaders?: {
13
14
  [p: string]: string;
14
15
  };
15
16
  transparent?: boolean;
16
17
  bgcolor?: string;
18
+ proxify?: ProxifyFunction;
17
19
  }
18
20
  export declare class OgcOpenApiTilesModel extends UrlTileSetModel {
19
21
  private tileMatrix;
@@ -21,6 +23,7 @@ export declare class OgcOpenApiTilesModel extends UrlTileSetModel {
21
23
  private plevel0Rows;
22
24
  private transparent;
23
25
  private bgcolor;
26
+ private proxy;
24
27
  constructor(options: OgcOpenApiTilesModelOptions);
25
28
  getTileURL(baseURL: string, tile: TileCoordinate): string | null;
26
29
  debugAsImage(tileCorrected: TileCoordinate): string;
@@ -61,6 +61,7 @@ export class OgcOpenApiTilesModel extends UrlTileSetModel {
61
61
  level0Rows,
62
62
  dataType: options.dataType,
63
63
  samplingMode: options.samplingMode,
64
+ credentials: options.credentials,
64
65
  requestHeaders: options.requestHeaders ? options.requestHeaders : {},
65
66
  };
66
67
  super(o);
@@ -69,6 +70,7 @@ export class OgcOpenApiTilesModel extends UrlTileSetModel {
69
70
  this.bgcolor = options.bgcolor;
70
71
  this.invertY = invertY;
71
72
  this.tileMatrix = options.tileMatrix;
73
+ this.proxy = options.proxify;
72
74
  this.modelDescriptor = {
73
75
  source: options.baseURL,
74
76
  name: options.collection,
@@ -89,7 +91,12 @@ export class OgcOpenApiTilesModel extends UrlTileSetModel {
89
91
  };
90
92
  const query = OgcOpenApiTilesModel.createURLParameters(urlParameters);
91
93
  const targetUrl = baseURL.replace("{tileMatrix}", level).replace("{tileRow}", tileCorrected.y.toString()).replace("{tileCol}", tileCorrected.x.toString());
92
- return targetUrl + (query && query !== "") ? targetUrl + "?" + query : targetUrl;
94
+ let tileUrl = targetUrl + (query && query !== "") ? targetUrl + "?" + query : targetUrl;
95
+ if (typeof this.proxy === "function") {
96
+ const proxyfied = this.proxy(tileUrl, {});
97
+ tileUrl = proxyfied.url;
98
+ }
99
+ return tileUrl;
93
100
  }
94
101
  debugAsImage(tileCorrected) {
95
102
  const canvas = document.createElement('canvas');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ogcopenapis",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Implements OGC OPEN API Features/Maps/Tiles capabilities and models for LuciadRIA",
5
5
  "files": [
6
6
  "lib/"