@here/olp-sdk-dataservice-read 2.0.0 → 3.1.0
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.
- package/README.md +3 -3
- package/bundle.umd.dev.js +12548 -76
- package/bundle.umd.min.js +1 -1
- package/index.js +5 -1
- package/index.web.js +5 -1
- package/lib/cache/MetadataCacheRepository.js +1 -0
- package/lib/cache/QuadTreeIndexCacheRepository.js +1 -0
- package/lib/cache/index.js +5 -1
- package/lib/client/ArtifactClient.d.ts +2 -1
- package/lib/client/ArtifactClient.js +31 -43
- package/lib/client/CatalogClient.d.ts +3 -1
- package/lib/client/CatalogClient.js +59 -78
- package/lib/client/CatalogRequest.js +4 -3
- package/lib/client/CatalogVersionRequest.js +6 -3
- package/lib/client/CatalogsRequest.js +5 -3
- package/lib/client/ConfigClient.d.ts +1 -1
- package/lib/client/ConfigClient.js +13 -23
- package/lib/client/DataRequest.js +7 -6
- package/lib/client/IndexLayerClient.d.ts +1 -1
- package/lib/client/IndexLayerClient.js +37 -40
- package/lib/client/IndexQueryRequest.js +2 -0
- package/lib/client/LayerVersionsRequest.js +5 -3
- package/lib/client/PartitionsRequest.js +10 -7
- package/lib/client/PollRequest.js +2 -0
- package/lib/client/QuadKeyPartitionsRequest.d.ts +1 -1
- package/lib/client/QuadKeyPartitionsRequest.js +7 -3
- package/lib/client/QuadTreeIndexRequest.d.ts +1 -1
- package/lib/client/QuadTreeIndexRequest.js +11 -3
- package/lib/client/QueryClient.d.ts +2 -1
- package/lib/client/QueryClient.js +85 -96
- package/lib/client/SchemaDetailsRequest.js +5 -3
- package/lib/client/SchemaRequest.js +5 -3
- package/lib/client/SeekRequest.js +3 -0
- package/lib/client/StatisticsClient.d.ts +2 -1
- package/lib/client/StatisticsClient.js +51 -65
- package/lib/client/StatisticsRequest.js +9 -4
- package/lib/client/StreamLayerClient.d.ts +4 -1
- package/lib/client/StreamLayerClient.js +117 -139
- package/lib/client/SubscribeRequest.js +4 -0
- package/lib/client/SummaryRequest.js +5 -2
- package/lib/client/TileRequest.js +6 -6
- package/lib/client/UnsubscribeRequest.js +2 -0
- package/lib/client/VersionedLayerClient.d.ts +45 -1
- package/lib/client/VersionedLayerClient.js +133 -147
- package/lib/client/VolatileLayerClient.d.ts +4 -1
- package/lib/client/VolatileLayerClient.js +104 -108
- package/lib/client/index.js +5 -1
- package/lib/index.js +5 -1
- package/lib/utils/getTile.d.ts +37 -1
- package/lib/utils/getTile.js +121 -132
- package/lib/utils/index.js +5 -1
- package/lib/utils/validateBillingTag.js +1 -2
- package/lib/utils/validatePartitionsIdsList.js +1 -2
- package/package.json +11 -55
- package/webpack.config.js +2 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (C) 2019-
|
|
3
|
+
* Copyright (C) 2019-2026 HERE Europe B.V.
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -17,31 +17,39 @@
|
|
|
17
17
|
* SPDX-License-Identifier: Apache-2.0
|
|
18
18
|
* License-Filename: LICENSE
|
|
19
19
|
*/
|
|
20
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
21
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
22
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
24
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
21
|
exports.VolatileLayerClient = void 0;
|
|
31
22
|
const olp_sdk_core_1 = require("@here/olp-sdk-core");
|
|
32
23
|
const olp_sdk_dataservice_api_1 = require("@here/olp-sdk-dataservice-api");
|
|
33
|
-
const
|
|
24
|
+
const MetadataCacheRepository_1 = require("../cache/MetadataCacheRepository");
|
|
25
|
+
const getTile_1 = require("../utils/getTile");
|
|
26
|
+
const PartitionsRequest_1 = require("./PartitionsRequest");
|
|
27
|
+
const QuadKeyPartitionsRequest_1 = require("./QuadKeyPartitionsRequest");
|
|
28
|
+
const QuadTreeIndexRequest_1 = require("./QuadTreeIndexRequest");
|
|
29
|
+
const QueryClient_1 = require("./QueryClient");
|
|
34
30
|
/**
|
|
35
31
|
* Describes a voaltile layer and provides the possibility to get partitions metadata and data.
|
|
36
32
|
*/
|
|
37
33
|
class VolatileLayerClient {
|
|
34
|
+
apiVersion = "v1";
|
|
35
|
+
/**
|
|
36
|
+
* HRN of the catalog.
|
|
37
|
+
*/
|
|
38
|
+
hrn;
|
|
39
|
+
/**
|
|
40
|
+
* The ID of the layer.
|
|
41
|
+
*/
|
|
42
|
+
layerId;
|
|
43
|
+
/**
|
|
44
|
+
* The [[OlpClientSettings]] instance.
|
|
45
|
+
*/
|
|
46
|
+
settings;
|
|
38
47
|
/**
|
|
39
48
|
* Creates the [[VolatileLayerClient]] instance with VolatileLayerClientParams.
|
|
40
49
|
*
|
|
41
50
|
* @param params parameters for use to initialize VolatileLayerClient.
|
|
42
51
|
*/
|
|
43
52
|
constructor(params) {
|
|
44
|
-
this.apiVersion = "v1";
|
|
45
53
|
this.hrn = params.catalogHrn.toString();
|
|
46
54
|
this.layerId = params.layerId;
|
|
47
55
|
this.settings = params.settings;
|
|
@@ -59,16 +67,14 @@ class VolatileLayerClient {
|
|
|
59
67
|
*
|
|
60
68
|
* @return Tile data (if it exists) or the nearest parent tile data
|
|
61
69
|
*/
|
|
62
|
-
getAggregatedData(request, abortSignal) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return olp_sdk_dataservice_read_1.getTile(request, params, abortSignal);
|
|
71
|
-
});
|
|
70
|
+
async getAggregatedData(request, abortSignal) {
|
|
71
|
+
const params = {
|
|
72
|
+
catalogHrn: olp_sdk_core_1.HRN.fromString(this.hrn),
|
|
73
|
+
layerId: this.layerId,
|
|
74
|
+
layerType: "volatile",
|
|
75
|
+
settings: this.settings
|
|
76
|
+
};
|
|
77
|
+
return (0, getTile_1.getTile)(request, params, abortSignal);
|
|
72
78
|
}
|
|
73
79
|
/**
|
|
74
80
|
* Fetches partition data using one of the following methods: ID, quadkey, or data handle.
|
|
@@ -81,79 +87,73 @@ class VolatileLayerClient {
|
|
|
81
87
|
*
|
|
82
88
|
* @return The data from the requested partition.
|
|
83
89
|
*/
|
|
84
|
-
getData(dataRequest, abortSignal) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (dataHandle
|
|
89
|
-
|
|
90
|
-
return this.downloadPartition(dataHandle, abortSignal, dataRequest.getBillingTag());
|
|
91
|
-
}
|
|
92
|
-
if (partitionId) {
|
|
93
|
-
const partitionIdDataHandle = yield this.getDataHandleByPartitionId(partitionId, dataRequest.getFetchOption(), dataRequest.getBillingTag()).catch(error => Promise.reject(error));
|
|
94
|
-
return this.downloadPartition(partitionIdDataHandle, abortSignal, dataRequest.getBillingTag());
|
|
95
|
-
}
|
|
90
|
+
async getData(dataRequest, abortSignal) {
|
|
91
|
+
const dataHandle = dataRequest.getDataHandle();
|
|
92
|
+
const partitionId = dataRequest.getPartitionId();
|
|
93
|
+
if (dataHandle !== undefined || partitionId !== undefined) {
|
|
94
|
+
if (dataHandle) {
|
|
95
|
+
return this.downloadPartition(dataHandle, abortSignal, dataRequest.getBillingTag());
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
getPartitions(request, abortSignal) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
if (request instanceof olp_sdk_dataservice_read_1.QuadKeyPartitionsRequest) {
|
|
103
|
-
const quadKey = request.getQuadKey();
|
|
104
|
-
if (!quadKey) {
|
|
105
|
-
return Promise.reject(new Error("Please provide correct QuadKey"));
|
|
106
|
-
}
|
|
107
|
-
const queryClient = new olp_sdk_dataservice_read_1.QueryClient(this.settings);
|
|
108
|
-
const quadTreeIndexRequest = new olp_sdk_dataservice_read_1.QuadTreeIndexRequest(olp_sdk_core_1.HRN.fromString(this.hrn), this.layerId, "volatile")
|
|
109
|
-
.withQuadKey(quadKey)
|
|
110
|
-
.withDepth(request.getDepth())
|
|
111
|
-
.withAdditionalFields(request.getAdditionalFields());
|
|
112
|
-
return queryClient.fetchQuadTreeIndex(quadTreeIndexRequest, abortSignal);
|
|
97
|
+
if (partitionId) {
|
|
98
|
+
const partitionIdDataHandle = await this.getDataHandleByPartitionId(partitionId, dataRequest.getFetchOption(), dataRequest.getBillingTag());
|
|
99
|
+
return this.downloadPartition(partitionIdDataHandle, abortSignal, dataRequest.getBillingTag());
|
|
113
100
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
}
|
|
102
|
+
return Promise.reject(new Error(`No data provided. Add dataHandle, partitionId or quadKey to the DataRequest object`));
|
|
103
|
+
}
|
|
104
|
+
async getPartitions(request, abortSignal) {
|
|
105
|
+
if (request instanceof QuadKeyPartitionsRequest_1.QuadKeyPartitionsRequest) {
|
|
106
|
+
const quadKey = request.getQuadKey();
|
|
107
|
+
if (!quadKey) {
|
|
108
|
+
return Promise.reject(new Error("Please provide correct QuadKey"));
|
|
117
109
|
}
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
110
|
+
const queryClient = new QueryClient_1.QueryClient(this.settings);
|
|
111
|
+
const quadTreeIndexRequest = new QuadTreeIndexRequest_1.QuadTreeIndexRequest(olp_sdk_core_1.HRN.fromString(this.hrn), this.layerId, "volatile")
|
|
112
|
+
.withQuadKey(quadKey)
|
|
113
|
+
.withDepth(request.getDepth())
|
|
114
|
+
.withAdditionalFields(request.getAdditionalFields());
|
|
115
|
+
return queryClient.fetchQuadTreeIndex(quadTreeIndexRequest, abortSignal);
|
|
116
|
+
}
|
|
117
|
+
if (request.getPartitionIds()) {
|
|
118
|
+
const queryClient = new QueryClient_1.QueryClient(this.settings);
|
|
119
|
+
return queryClient.getPartitionsById(request, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal);
|
|
120
|
+
}
|
|
121
|
+
const cache = new MetadataCacheRepository_1.MetadataCacheRepository(this.settings.cache);
|
|
122
|
+
if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly) {
|
|
123
|
+
const partitions = cache.get(request, this.hrn.toString(), this.layerId);
|
|
124
|
+
if (partitions) {
|
|
125
|
+
const additionalFields = request.getAdditionalFields();
|
|
126
|
+
let existFields;
|
|
127
|
+
if (additionalFields) {
|
|
128
|
+
existFields = additionalFields.filter((field) => {
|
|
129
|
+
return partitions.every((partition) => partition[field] !== undefined);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (!additionalFields ||
|
|
133
|
+
!existFields ||
|
|
134
|
+
additionalFields.length === existFields.length) {
|
|
135
|
+
return Promise.resolve({ partitions });
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly &&
|
|
143
|
-
metadata.partitions.length) {
|
|
144
|
-
cache.put(request, this.hrn.toString(), this.layerId, metadata.partitions);
|
|
145
|
-
}
|
|
146
|
-
return Promise.resolve(metadata);
|
|
138
|
+
}
|
|
139
|
+
const metaRequestBilder = await this.getRequestBuilder("metadata", olp_sdk_core_1.HRN.fromString(this.hrn));
|
|
140
|
+
const metadata = await olp_sdk_dataservice_api_1.MetadataApi.getPartitions(metaRequestBilder, {
|
|
141
|
+
layerId: this.layerId,
|
|
142
|
+
additionalFields: request.getAdditionalFields(),
|
|
143
|
+
billingTag: request.getBillingTag()
|
|
147
144
|
});
|
|
145
|
+
if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly &&
|
|
146
|
+
metadata.partitions.length) {
|
|
147
|
+
cache.put(request, this.hrn.toString(), this.layerId, metadata.partitions);
|
|
148
|
+
}
|
|
149
|
+
return Promise.resolve(metadata);
|
|
148
150
|
}
|
|
149
|
-
downloadPartition(dataHandle, abortSignal, billingTag) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
billingTag
|
|
156
|
-
});
|
|
151
|
+
async downloadPartition(dataHandle, abortSignal, billingTag) {
|
|
152
|
+
const builder = await this.getRequestBuilder("volatile-blob", olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal);
|
|
153
|
+
return olp_sdk_dataservice_api_1.VolatileBlobApi.getVolatileBlob(builder, {
|
|
154
|
+
dataHandle,
|
|
155
|
+
layerId: this.layerId,
|
|
156
|
+
billingTag
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
@@ -162,10 +162,8 @@ class VolatileLayerClient {
|
|
|
162
162
|
*
|
|
163
163
|
* @returns requestBuilder
|
|
164
164
|
*/
|
|
165
|
-
getRequestBuilder(builderType, hrn, abortSignal) {
|
|
166
|
-
return
|
|
167
|
-
return olp_sdk_core_1.RequestFactory.create(builderType, this.apiVersion, this.settings, hrn, abortSignal);
|
|
168
|
-
});
|
|
165
|
+
async getRequestBuilder(builderType, hrn, abortSignal) {
|
|
166
|
+
return olp_sdk_core_1.RequestFactory.create(builderType, this.apiVersion, this.settings, hrn, abortSignal);
|
|
169
167
|
}
|
|
170
168
|
/**
|
|
171
169
|
* Fetch and returns partition metadata
|
|
@@ -173,22 +171,20 @@ class VolatileLayerClient {
|
|
|
173
171
|
* @param fetchOption The option of caching (online only or return from cache if exist)
|
|
174
172
|
* @returns A promise of partition metadata which used to get partition data
|
|
175
173
|
*/
|
|
176
|
-
getDataHandleByPartitionId(partitionId, fetchOption, billingTag) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
: Promise.reject(new olp_sdk_core_1.HttpError(olp_sdk_core_1.STATUS_CODES.NOT_FOUND, `No partition dataHandle for partition ${partitionId}. HRN: ${this.hrn}`));
|
|
191
|
-
});
|
|
174
|
+
async getDataHandleByPartitionId(partitionId, fetchOption, billingTag) {
|
|
175
|
+
const queryClient = new QueryClient_1.QueryClient(this.settings);
|
|
176
|
+
const partitionsRequest = new PartitionsRequest_1.PartitionsRequest()
|
|
177
|
+
.withPartitionIds([partitionId])
|
|
178
|
+
.withFetchOption(fetchOption);
|
|
179
|
+
if (billingTag) {
|
|
180
|
+
partitionsRequest.withBillingTag(billingTag);
|
|
181
|
+
}
|
|
182
|
+
const metadata = await queryClient.getPartitionsById(partitionsRequest, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn));
|
|
183
|
+
return metadata.partitions &&
|
|
184
|
+
metadata.partitions[0] &&
|
|
185
|
+
metadata.partitions[0].dataHandle
|
|
186
|
+
? metadata.partitions[0].dataHandle
|
|
187
|
+
: Promise.reject(new olp_sdk_core_1.HttpError(olp_sdk_core_1.STATUS_CODES.NOT_FOUND, `No partition dataHandle for partition ${partitionId}. HRN: ${this.hrn}`));
|
|
192
188
|
}
|
|
193
189
|
}
|
|
194
190
|
exports.VolatileLayerClient = VolatileLayerClient;
|
package/lib/client/index.js
CHANGED
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
*/
|
|
20
20
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
21
|
if (k2 === undefined) k2 = k;
|
|
22
|
-
Object.
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
23
27
|
}) : (function(o, m, k, k2) {
|
|
24
28
|
if (k2 === undefined) k2 = k;
|
|
25
29
|
o[k2] = m[k];
|
package/lib/index.js
CHANGED
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
*/
|
|
20
20
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
21
|
if (k2 === undefined) k2 = k;
|
|
22
|
-
Object.
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
23
27
|
}) : (function(o, m, k, k2) {
|
|
24
28
|
if (k2 === undefined) k2 = k;
|
|
25
29
|
o[k2] = m[k];
|
package/lib/utils/getTile.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FetchOptions, HRN, TileKey, OlpClientSettings } from "@here/olp-sdk-core";
|
|
2
2
|
import { Index as QuadTreeIndex } from "@here/olp-sdk-dataservice-api/lib/query-api";
|
|
3
|
-
import { QuadTreeIndexDepth
|
|
3
|
+
import { QuadTreeIndexDepth } from "../client/QuadTreeIndexRequest";
|
|
4
|
+
import { TileRequest, TileRequestParams } from "../client/TileRequest";
|
|
4
5
|
/**
|
|
5
6
|
* Parameters used to get a tile.
|
|
6
7
|
*/
|
|
@@ -10,6 +11,10 @@ export interface GetTileParams {
|
|
|
10
11
|
layerId: string;
|
|
11
12
|
layerType: "versioned" | "volatile";
|
|
12
13
|
}
|
|
14
|
+
export interface TileResponse {
|
|
15
|
+
response: Response;
|
|
16
|
+
parentTileKey: TileKey | undefined;
|
|
17
|
+
}
|
|
13
18
|
/**
|
|
14
19
|
* Fetches asynchronously data from a tile or from its nearest ancestor if not found.
|
|
15
20
|
*
|
|
@@ -45,6 +50,37 @@ export interface GetTileParams {
|
|
|
45
50
|
* @returns The blob of the requested tile or the blob of the closest parent Tile.
|
|
46
51
|
*/
|
|
47
52
|
export declare function getTile(request: TileRequest, params: TileRequestParams, abortSignal?: AbortSignal): Promise<Response>;
|
|
53
|
+
/**
|
|
54
|
+
* Same as the three-argument [[getTile]], but also resolves the tile key of
|
|
55
|
+
* the parent whose data was actually returned.
|
|
56
|
+
*
|
|
57
|
+
* @param options Pass `{ includeTileKey: true }` to receive a [[TileResponse]]
|
|
58
|
+
* instead of a plain `Response`.
|
|
59
|
+
*
|
|
60
|
+
* @returns The blob of the requested tile or the blob of the closest parent
|
|
61
|
+
* tile, together with that tile's key.
|
|
62
|
+
*/
|
|
63
|
+
export declare function getTile(request: TileRequest, params: TileRequestParams, abortSignal: AbortSignal | undefined, options: {
|
|
64
|
+
includeTileKey: true;
|
|
65
|
+
}): Promise<TileResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Same as the three-argument [[getTile]], for callers that pass an options
|
|
68
|
+
* object with `includeTileKey` disabled or omitted.
|
|
69
|
+
*
|
|
70
|
+
* @returns The blob of the requested tile or the blob of the closest parent Tile.
|
|
71
|
+
*/
|
|
72
|
+
export declare function getTile(request: TileRequest, params: TileRequestParams, abortSignal: AbortSignal | undefined, options: {
|
|
73
|
+
includeTileKey?: false;
|
|
74
|
+
}): Promise<Response>;
|
|
75
|
+
/**
|
|
76
|
+
* Same as the three-argument [[getTile]], for an `includeTileKey` flag whose
|
|
77
|
+
* value is only known at run time. Narrow the result before using it.
|
|
78
|
+
*
|
|
79
|
+
* @returns A [[TileResponse]] if the flag was `true`, otherwise the plain blob.
|
|
80
|
+
*/
|
|
81
|
+
export declare function getTile(request: TileRequest, params: TileRequestParams, abortSignal: AbortSignal | undefined, options: {
|
|
82
|
+
includeTileKey?: boolean;
|
|
83
|
+
}): Promise<Response | TileResponse>;
|
|
48
84
|
/**
|
|
49
85
|
* The function should request quad tree index for the parent tile with delta 4
|
|
50
86
|
* and cache the responses in cache for later calls.
|
package/lib/utils/getTile.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (C) 2020-
|
|
3
|
+
* Copyright (C) 2020-2026 HERE Europe B.V.
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -17,150 +17,139 @@
|
|
|
17
17
|
* SPDX-License-Identifier: Apache-2.0
|
|
18
18
|
* License-Filename: LICENSE
|
|
19
19
|
*/
|
|
20
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
21
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
22
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
24
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.
|
|
21
|
+
exports.getTile = getTile;
|
|
22
|
+
exports.fetchQuadTreeIndex = fetchQuadTreeIndex;
|
|
31
23
|
const olp_sdk_core_1 = require("@here/olp-sdk-core");
|
|
32
24
|
const olp_sdk_dataservice_api_1 = require("@here/olp-sdk-dataservice-api");
|
|
33
|
-
const
|
|
25
|
+
const QuadTreeIndexCacheRepository_1 = require("../cache/QuadTreeIndexCacheRepository");
|
|
26
|
+
const QuadTreeIndexRequest_1 = require("../client/QuadTreeIndexRequest");
|
|
27
|
+
const QueryClient_1 = require("../client/QueryClient");
|
|
28
|
+
async function getTile(request, params, abortSignal, options) {
|
|
29
|
+
const tileResponse = await fetchTile(request, params, abortSignal);
|
|
30
|
+
return options?.includeTileKey ? tileResponse : tileResponse.response;
|
|
31
|
+
}
|
|
34
32
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* The tile is a geometric area represented as a HERE tile.
|
|
38
|
-
* The quad tree metadata fetches the blob of needed tile from the HERE Query Service,
|
|
39
|
-
* then caches it, and returns to the user.
|
|
40
|
-
* To disable caching of metadata use `request.withFetchOption(FetchOptions.OnlineOnly)`.
|
|
41
|
-
*
|
|
42
|
-
* @param request Requests the [[TileRequest]] instance with the configured parameters.
|
|
43
|
-
* @see [[TileRequest]]
|
|
44
|
-
*
|
|
45
|
-
* @param abortSignal The signal object that allows you to communicate with a request (such as the `fetch` request)
|
|
46
|
-
* and, if required, abort it using the `AbortController` object.
|
|
47
|
-
* @see the [`AbortController` documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
*
|
|
51
|
-
* ```
|
|
52
|
-
* const params: GetTileParams = {
|
|
53
|
-
* settings: "% your `OlpClientSettings` instance % ",
|
|
54
|
-
* catalogHrn: "% the HRN instance of your catalog %",
|
|
55
|
-
* layerId: "% your layer ID %",
|
|
56
|
-
* layerType: "% versioned or volatile %",
|
|
57
|
-
* }
|
|
58
|
-
*
|
|
59
|
-
* const request = new TileRequest();
|
|
60
|
-
*
|
|
61
|
-
* const tile1 = await getTile(request.withTileKey(yourTileKey1), params);
|
|
62
|
-
* const tile2 = await getTile(request.withTileKey(yourTileKey2), params);
|
|
63
|
-
*
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @returns The blob of the requested tile or the blob of the closest parent Tile.
|
|
33
|
+
* @hidden
|
|
67
34
|
*/
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
35
|
+
async function fetchTile(request, params, abortSignal) {
|
|
36
|
+
let catalogVersion;
|
|
37
|
+
const quadKey = request.getTileKey();
|
|
38
|
+
if (!quadKey) {
|
|
39
|
+
return Promise.reject(new Error("Please provide correct QuadKey"));
|
|
40
|
+
}
|
|
41
|
+
if (params.layerType === "versioned") {
|
|
42
|
+
catalogVersion = params.catalogVersion;
|
|
43
|
+
}
|
|
44
|
+
const blobType = params.layerType === "versioned" ? "blob" : "volatile-blob";
|
|
45
|
+
const blobRequestBuilder = await olp_sdk_core_1.RequestFactory.create(blobType, "v1", params.settings, params.catalogHrn, abortSignal);
|
|
46
|
+
const depth = 4;
|
|
47
|
+
const requestedTileKey = olp_sdk_core_1.TileKey.fromRowColumnLevel(quadKey.row, quadKey.column, quadKey.level);
|
|
48
|
+
const quadTreeIndexRoot = requestedTileKey.changedLevelBy(-depth);
|
|
49
|
+
let quadTreeIndex;
|
|
50
|
+
if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly) {
|
|
51
|
+
const cache = new QuadTreeIndexCacheRepository_1.QuadTreeIndexCacheRepository(params.settings.cache);
|
|
52
|
+
quadTreeIndex = cache.get({
|
|
53
|
+
hrn: params.catalogHrn.toString(),
|
|
54
|
+
layerId: params.layerId,
|
|
55
|
+
depth,
|
|
56
|
+
root: quadTreeIndexRoot,
|
|
57
|
+
version: catalogVersion
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (!quadTreeIndex) {
|
|
61
|
+
quadTreeIndex = await fetchQuadTreeIndex({
|
|
62
|
+
...params,
|
|
63
|
+
catalogVersion,
|
|
64
|
+
depth,
|
|
65
|
+
fetchOptions: request.getFetchOption(),
|
|
66
|
+
tileKey: quadTreeIndexRoot,
|
|
67
|
+
abortSignal,
|
|
68
|
+
billingTag: request.getBillingTag()
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const subQuads = quadTreeIndex.subQuads ?? [];
|
|
72
|
+
const parentQuads = quadTreeIndex.parentQuads ?? [];
|
|
73
|
+
if (!subQuads.length && !parentQuads.length) {
|
|
74
|
+
return Promise.resolve({
|
|
75
|
+
response: new Response(null, {
|
|
105
76
|
status: 204,
|
|
106
77
|
statusText: "No Content"
|
|
107
|
-
})
|
|
78
|
+
}),
|
|
79
|
+
parentTileKey: undefined
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const closestParent = findClosestParent(requestedTileKey, quadTreeIndex, quadTreeIndexRoot);
|
|
83
|
+
if (!closestParent) {
|
|
84
|
+
return Promise.reject(new Error(`Error getting blob for Tile: ${requestedTileKey.toHereTile()}`));
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
response: await olp_sdk_dataservice_api_1.BlobApi.getBlob(blobRequestBuilder, {
|
|
88
|
+
dataHandle: closestParent.parentQuad.dataHandle,
|
|
89
|
+
layerId: params.layerId,
|
|
90
|
+
billingTag: request.getBillingTag()
|
|
91
|
+
}),
|
|
92
|
+
parentTileKey: closestParent.tileKey
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Helper function to get the closest parent quad for a given tile key.
|
|
97
|
+
* @hidden
|
|
98
|
+
*/
|
|
99
|
+
function findClosestParent(tileKey, quadTreeIndex, quadTreeIndexRoot) {
|
|
100
|
+
const subQuads = quadTreeIndex.subQuads ?? [];
|
|
101
|
+
const parentQuads = quadTreeIndex.parentQuads ?? [];
|
|
102
|
+
// First, iterate through the sub quad trees, starting from lowest level up to the quad tree index root
|
|
103
|
+
let currentTileKey = tileKey;
|
|
104
|
+
while (currentTileKey.level >= quadTreeIndexRoot.level) {
|
|
105
|
+
const currentDelta = currentTileKey.level - quadTreeIndexRoot.level;
|
|
106
|
+
const subHereTile = currentTileKey.getSubHereTile(currentDelta);
|
|
107
|
+
const subQuad = subQuads.find((item) => item.subQuadKey === subHereTile);
|
|
108
|
+
if (subQuad) {
|
|
109
|
+
return { parentQuad: subQuad, tileKey: currentTileKey };
|
|
108
110
|
}
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const metadata = subQuads.find(item => item.subQuadKey === currentTileKey.getSubHereTile(currentDelta));
|
|
115
|
-
if (metadata) {
|
|
116
|
-
return olp_sdk_dataservice_api_1.BlobApi.getBlob(blobRequestBuilder, {
|
|
117
|
-
dataHandle: metadata.dataHandle,
|
|
118
|
-
layerId: params.layerId,
|
|
119
|
-
billingTag: request.getBillingTag()
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
currentTileKey = currentTileKey.parent();
|
|
124
|
-
currentDelta = parentTileKey.level - currentTileKey.level;
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
111
|
+
// Stop before requesting the parent of the quad tree index root -
|
|
112
|
+
// that root can be the global root tile (level 0), whose parent()
|
|
113
|
+
// throws rather than returning another tile.
|
|
114
|
+
if (currentTileKey.level === quadTreeIndexRoot.level) {
|
|
115
|
+
break;
|
|
129
116
|
}
|
|
130
|
-
|
|
131
|
-
}
|
|
117
|
+
currentTileKey = currentTileKey.parent();
|
|
118
|
+
}
|
|
119
|
+
// not found? Find the closest parent quad
|
|
120
|
+
return parentQuads.reduce((closest, parentQuad) => {
|
|
121
|
+
const tileKey = olp_sdk_core_1.TileKey.fromHereTile(parentQuad.partition);
|
|
122
|
+
return !closest || tileKey.level > closest.tileKey.level
|
|
123
|
+
? { parentQuad, tileKey }
|
|
124
|
+
: closest;
|
|
125
|
+
}, undefined);
|
|
132
126
|
}
|
|
133
|
-
exports.getTile = getTile;
|
|
134
127
|
/**
|
|
135
128
|
* The function should request quad tree index for the parent tile with delta 4
|
|
136
129
|
* and cache the responses in cache for later calls.
|
|
137
130
|
* @hidden
|
|
138
131
|
*/
|
|
139
|
-
function fetchQuadTreeIndex(params) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
return Promise.resolve(quadTreeIndex);
|
|
164
|
-
});
|
|
132
|
+
async function fetchQuadTreeIndex(params) {
|
|
133
|
+
const cache = new QuadTreeIndexCacheRepository_1.QuadTreeIndexCacheRepository(params.settings.cache);
|
|
134
|
+
const queryClient = new QueryClient_1.QueryClient(params.settings);
|
|
135
|
+
const quadTreeIndexRequest = new QuadTreeIndexRequest_1.QuadTreeIndexRequest(params.catalogHrn, params.layerId, params.layerType)
|
|
136
|
+
.withQuadKey(params.tileKey)
|
|
137
|
+
.withDepth(params.depth);
|
|
138
|
+
if (params.layerType === "versioned") {
|
|
139
|
+
quadTreeIndexRequest.withVersion(params.catalogVersion);
|
|
140
|
+
}
|
|
141
|
+
const quadTreeIndex = await queryClient.fetchQuadTreeIndex(quadTreeIndexRequest, params.abortSignal);
|
|
142
|
+
if (params.fetchOptions !== olp_sdk_core_1.FetchOptions.OnlineOnly &&
|
|
143
|
+
(quadTreeIndex.subQuads !== undefined ||
|
|
144
|
+
quadTreeIndex.parentQuads !== undefined)) {
|
|
145
|
+
cache.put({
|
|
146
|
+
hrn: params.catalogHrn.toString(),
|
|
147
|
+
layerId: params.layerId,
|
|
148
|
+
depth: params.depth,
|
|
149
|
+
root: params.tileKey,
|
|
150
|
+
tree: quadTreeIndex,
|
|
151
|
+
version: params.catalogVersion
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return Promise.resolve(quadTreeIndex);
|
|
165
155
|
}
|
|
166
|
-
exports.fetchQuadTreeIndex = fetchQuadTreeIndex;
|