@esri/solution-simple-types 4.1.2 → 5.0.1
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/dist/cjs/dashboard.d.ts +93 -93
- package/dist/cjs/dashboard.js +352 -352
- package/dist/cjs/helpers/convert-item-to-template.d.ts +46 -46
- package/dist/cjs/helpers/convert-item-to-template.js +235 -209
- package/dist/cjs/helpers/convert-item-to-template.js.map +1 -1
- package/dist/cjs/helpers/create-item-from-template.d.ts +17 -17
- package/dist/cjs/helpers/create-item-from-template.js +153 -138
- package/dist/cjs/helpers/create-item-from-template.js.map +1 -1
- package/dist/cjs/helpers/notebook-helpers.d.ts +19 -19
- package/dist/cjs/helpers/notebook-helpers.js +24 -24
- package/dist/cjs/helpers/quickcapture-helpers.d.ts +18 -18
- package/dist/cjs/helpers/quickcapture-helpers.js +22 -22
- package/dist/cjs/helpers/simple-type-helpers.d.ts +18 -18
- package/dist/cjs/helpers/simple-type-helpers.js +22 -22
- package/dist/cjs/helpers/update-notebook-data.d.ts +17 -17
- package/dist/cjs/helpers/update-notebook-data.js +27 -27
- package/dist/cjs/index.d.ts +27 -27
- package/dist/cjs/index.js +36 -36
- package/dist/cjs/notebook.d.ts +66 -66
- package/dist/cjs/notebook.js +133 -133
- package/dist/cjs/oic.d.ts +53 -53
- package/dist/cjs/oic.js +170 -170
- package/dist/cjs/quickcapture.d.ts +76 -87
- package/dist/cjs/quickcapture.js +143 -192
- package/dist/cjs/quickcapture.js.map +1 -1
- package/dist/cjs/simple-types.d.ts +57 -57
- package/dist/cjs/simple-types.js +94 -94
- package/dist/cjs/webmap.d.ts +102 -102
- package/dist/cjs/webmap.js +325 -325
- package/dist/cjs/webmappingapplication.d.ts +176 -176
- package/dist/cjs/webmappingapplication.js +674 -674
- package/dist/cjs/webmappingapplication.js.map +1 -1
- package/dist/cjs/workforce.d.ts +34 -34
- package/dist/cjs/workforce.js +44 -44
- package/dist/esm/dashboard.d.ts +93 -93
- package/dist/esm/dashboard.js +339 -339
- package/dist/esm/helpers/convert-item-to-template.d.ts +46 -46
- package/dist/esm/helpers/convert-item-to-template.js +228 -202
- package/dist/esm/helpers/convert-item-to-template.js.map +1 -1
- package/dist/esm/helpers/create-item-from-template.d.ts +17 -17
- package/dist/esm/helpers/create-item-from-template.js +148 -133
- package/dist/esm/helpers/create-item-from-template.js.map +1 -1
- package/dist/esm/helpers/notebook-helpers.d.ts +19 -19
- package/dist/esm/helpers/notebook-helpers.js +20 -20
- package/dist/esm/helpers/quickcapture-helpers.d.ts +18 -18
- package/dist/esm/helpers/quickcapture-helpers.js +19 -19
- package/dist/esm/helpers/simple-type-helpers.d.ts +18 -18
- package/dist/esm/helpers/simple-type-helpers.js +19 -19
- package/dist/esm/helpers/update-notebook-data.d.ts +17 -17
- package/dist/esm/helpers/update-notebook-data.js +23 -23
- package/dist/esm/index.d.ts +27 -27
- package/dist/esm/index.js +27 -27
- package/dist/esm/notebook.d.ts +66 -66
- package/dist/esm/notebook.js +123 -123
- package/dist/esm/oic.d.ts +53 -53
- package/dist/esm/oic.js +162 -162
- package/dist/esm/quickcapture.d.ts +76 -87
- package/dist/esm/quickcapture.js +131 -179
- package/dist/esm/quickcapture.js.map +1 -1
- package/dist/esm/simple-types.d.ts +57 -57
- package/dist/esm/simple-types.js +86 -86
- package/dist/esm/webmap.d.ts +102 -102
- package/dist/esm/webmap.js +312 -312
- package/dist/esm/webmappingapplication.d.ts +176 -176
- package/dist/esm/webmappingapplication.js +648 -648
- package/dist/esm/webmappingapplication.js.map +1 -1
- package/dist/esm/workforce.d.ts +34 -34
- package/dist/esm/workforce.js +38 -38
- package/package.json +7 -7
package/dist/esm/webmap.js
CHANGED
|
@@ -1,313 +1,313 @@
|
|
|
1
|
-
/** @license
|
|
2
|
-
* Copyright 2018 Esri
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import * as common from "@esri/solution-common";
|
|
17
|
-
/**
|
|
18
|
-
* The portion of a Webmap URL between the server and the map id.
|
|
19
|
-
*
|
|
20
|
-
* @private
|
|
21
|
-
*/
|
|
22
|
-
const WEBMAP_APP_URL_PART = "home/webmap/viewer.html?webmap=";
|
|
23
|
-
/**
|
|
24
|
-
* A flag inserted used as a vector tile layer's styleUrl to indicate that the layer is unsupported and should
|
|
25
|
-
* be removed.
|
|
26
|
-
*/
|
|
27
|
-
const unsupportedTileLayerUrl = "unsupported";
|
|
28
|
-
// ------------------------------------------------------------------------------------------------------------------ //
|
|
29
|
-
/**
|
|
30
|
-
* Converts an AGOL webmap item to a template.
|
|
31
|
-
*
|
|
32
|
-
* @param itemTemplate Template for the webmap item
|
|
33
|
-
* @param destAuthentication Credentials for requests to the destination organization
|
|
34
|
-
* @param srcAuthentication Credentials for requests to source items
|
|
35
|
-
* @param templateDictionary Hash of key details used for variable replacement
|
|
36
|
-
* @returns Template for the solution item that contains key details for item reconstruction
|
|
37
|
-
*/
|
|
38
|
-
export function convertItemToTemplate(itemTemplate, destAuthentication, srcAuthentication, templateDictionary) {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
// Templatize the app URL if it's not a vector tile service
|
|
41
|
-
if (itemTemplate.type !== "Vector Tile Service") {
|
|
42
|
-
itemTemplate.item.url = itemTemplate.item.url
|
|
43
|
-
? common.checkUrlPathTermination(common.placeholder(common.SERVER_NAME)) + WEBMAP_APP_URL_PART + itemTemplate.item.id
|
|
44
|
-
: itemTemplate.item.url; // templatized id
|
|
45
|
-
}
|
|
46
|
-
// Extract dependencies
|
|
47
|
-
_extractDependencies(itemTemplate, srcAuthentication).then((results) => {
|
|
48
|
-
itemTemplate.dependencies = results.dependencies;
|
|
49
|
-
// Templatize the map layer ids after we've extracted them as dependencies
|
|
50
|
-
if (itemTemplate.data) {
|
|
51
|
-
const baseMapLayers = itemTemplate.data.baseMap?.baseMapLayers;
|
|
52
|
-
if (baseMapLayers) {
|
|
53
|
-
itemTemplate.data.baseMap.baseMapLayers =
|
|
54
|
-
baseMapLayers.filter(layer => layer.styleUrl !== unsupportedTileLayerUrl);
|
|
55
|
-
_templatizeWebmapLayerIdsAndUrls(itemTemplate.data.baseMap.baseMapLayers, results.urlHash, templateDictionary);
|
|
56
|
-
}
|
|
57
|
-
const operationalLayers = itemTemplate.data.operationalLayers;
|
|
58
|
-
if (operationalLayers) {
|
|
59
|
-
itemTemplate.data.operationalLayers =
|
|
60
|
-
operationalLayers.filter(layer => layer.styleUrl !== unsupportedTileLayerUrl);
|
|
61
|
-
_templatizeWebmapLayerIdsAndUrls(itemTemplate.data.operationalLayers, results.urlHash, templateDictionary);
|
|
62
|
-
}
|
|
63
|
-
_templatizeWebmapLayerIdsAndUrls(itemTemplate.data.tables, results.urlHash, templateDictionary);
|
|
64
|
-
// Exclude intialState
|
|
65
|
-
_excludeInitialState(itemTemplate.data);
|
|
66
|
-
}
|
|
67
|
-
resolve(itemTemplate);
|
|
68
|
-
}, e => reject(common.fail(e)));
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Gets the ids of the dependencies of an AGOL webmap item.
|
|
73
|
-
*
|
|
74
|
-
* @param itemTemplate A webmap item whose dependencies are sought
|
|
75
|
-
* @param authentication Credentials for any requests
|
|
76
|
-
* @returns List of dependencies ids and url/itemId hash
|
|
77
|
-
* @private
|
|
78
|
-
*/
|
|
79
|
-
export function _extractDependencies(itemTemplate, authentication) {
|
|
80
|
-
return new Promise((resolve, reject) => {
|
|
81
|
-
const dependencies = [];
|
|
82
|
-
if (itemTemplate.data) {
|
|
83
|
-
const basemapLayers = itemTemplate.data.baseMap?.baseMapLayers || [];
|
|
84
|
-
const opLayers = itemTemplate.data.operationalLayers || [];
|
|
85
|
-
const tables = itemTemplate.data.tables || [];
|
|
86
|
-
const layersAndTables = basemapLayers.concat(opLayers).concat(tables);
|
|
87
|
-
_getLayerIds(layersAndTables, dependencies, authentication).then(results => {
|
|
88
|
-
resolve(results);
|
|
89
|
-
}, e => reject(common.fail(e)));
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
resolve({
|
|
93
|
-
dependencies: dependencies,
|
|
94
|
-
urlHash: {}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Remove the initialState prop from webmaps saved from the new map viewer.
|
|
101
|
-
* This allows the map to use the item extent property that we templatize.
|
|
102
|
-
*
|
|
103
|
-
* Added for issue #662
|
|
104
|
-
*
|
|
105
|
-
* @param data the data for the web maps item template
|
|
106
|
-
* @returns void
|
|
107
|
-
* @private
|
|
108
|
-
*/
|
|
109
|
-
export function _excludeInitialState(data) {
|
|
110
|
-
common.deleteProp(data, "initialState");
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Extracts the AGOL itemId for each layer or table object in a list using the url.
|
|
114
|
-
*
|
|
115
|
-
* @param layerList List of map layers or tables; supported vector tile layers have their styleUrls templatized
|
|
116
|
-
* @param dependencies Current list of dependencies
|
|
117
|
-
* @param authentication Credentials for any requests
|
|
118
|
-
* @returns Updated list of dependencies ids, url/itemId hash (for feature layers),
|
|
119
|
-
* and id/styleUrl hash (for vector tile layers)
|
|
120
|
-
* @private
|
|
121
|
-
*/
|
|
122
|
-
export function _getLayerIds(layerList, dependencies, authentication) {
|
|
123
|
-
return new Promise((resolve, reject) => {
|
|
124
|
-
const urlHash = {};
|
|
125
|
-
const options = {
|
|
126
|
-
f: "json",
|
|
127
|
-
authentication: authentication
|
|
128
|
-
};
|
|
129
|
-
const layerPromises = [];
|
|
130
|
-
const layerChecks = {};
|
|
131
|
-
const layers = layerList.filter(layer => {
|
|
132
|
-
// Test for Vector Tile Layers
|
|
133
|
-
if (layer.itemId && layer.layerType === "VectorTileLayer") {
|
|
134
|
-
// Fetch the item so that we can check if it has the typeKeyword "Vector Tile Style Editor", which ensures
|
|
135
|
-
// that the user has edited the style and it is something that could be reasonably be packaged with the
|
|
136
|
-
// solution
|
|
137
|
-
layerPromises.push(common.getItemBase(layer.itemId, authentication));
|
|
138
|
-
return true;
|
|
139
|
-
// Handle a feature server layer
|
|
140
|
-
}
|
|
141
|
-
else if (layer.url && layer.url.indexOf("{{velocityUrl}}") < 0) {
|
|
142
|
-
const results = /.+FeatureServer/g.exec(layer.url);
|
|
143
|
-
const baseUrl = Array.isArray(results) && results.length > 0 ? results[0] : undefined;
|
|
144
|
-
if (baseUrl) {
|
|
145
|
-
// avoid redundant checks when we have a layer with subLayers
|
|
146
|
-
if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {
|
|
147
|
-
layerChecks[baseUrl] = common.rest_request(layer.url, options);
|
|
148
|
-
}
|
|
149
|
-
layerPromises.push(layerChecks[baseUrl]);
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
// This layer is not a dependency
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
// We have a mix of Vector Tile Layer item base requests and Feature Server info requests
|
|
162
|
-
if (layerPromises.length > 0) {
|
|
163
|
-
Promise.all(layerPromises).then((responses) => {
|
|
164
|
-
responses.forEach((response, i) => {
|
|
165
|
-
if (layers[i].layerType === "VectorTileLayer") {
|
|
166
|
-
const typeKeywords = common.getProp(response, "typeKeywords");
|
|
167
|
-
if (typeKeywords && typeKeywords.includes("Vector Tile Style Editor")) {
|
|
168
|
-
// Vector tiles edited by the style editor
|
|
169
|
-
if (dependencies.indexOf(response.id) < 0) {
|
|
170
|
-
dependencies.push(response.id);
|
|
171
|
-
}
|
|
172
|
-
// Templatize the URL to the style resource
|
|
173
|
-
const iSuffix = layers[i].styleUrl.indexOf(response.id) + response.id.length;
|
|
174
|
-
layers[i].styleUrl = common.templatizeTerm(layers[i].styleUrl.replace(layers[i].styleUrl.substring(0, iSuffix), response.id), response.id, ".itemUrl");
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
// Unsupported vector tiles
|
|
178
|
-
layers[i].styleUrl = unsupportedTileLayerUrl;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else if (common.getProp(response, "serviceItemId")) {
|
|
182
|
-
// Feature Service
|
|
183
|
-
const id = response.serviceItemId;
|
|
184
|
-
if (dependencies.indexOf(id) < 0) {
|
|
185
|
-
dependencies.push(id);
|
|
186
|
-
}
|
|
187
|
-
urlHash[layers[i].url] = id;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
resolve({
|
|
191
|
-
dependencies,
|
|
192
|
-
urlHash
|
|
193
|
-
});
|
|
194
|
-
}, e => reject(common.fail(e)));
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
resolve({
|
|
198
|
-
dependencies,
|
|
199
|
-
urlHash
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Templatizes the url and item id for layers or tables within the webmap.
|
|
206
|
-
*
|
|
207
|
-
* @param layerList List of map layers or tables
|
|
208
|
-
* @param urlHash Lookup object for analysis layers; hash from URL to AGO item id
|
|
209
|
-
* @param templateDictionary Hash of key details used for variable replacement
|
|
210
|
-
* @returns void
|
|
211
|
-
* @private
|
|
212
|
-
*/
|
|
213
|
-
export function _templatizeWebmapLayerIdsAndUrls(layerList = [], urlHash, templateDictionary) {
|
|
214
|
-
layerList.forEach((layer) => {
|
|
215
|
-
// Test for Vector Tile Layers
|
|
216
|
-
if (layer.itemId && layer.layerType === "VectorTileLayer") {
|
|
217
|
-
// No further test needed: we've already pruned out unsupported vector tile layers
|
|
218
|
-
layer.itemId = common.templatizeTerm(layer.itemId, layer.itemId, ".itemId");
|
|
219
|
-
// Handle a feature server layer
|
|
220
|
-
}
|
|
221
|
-
else if (layer.url) {
|
|
222
|
-
const layerId = layer.url.substr(layer.url.lastIndexOf("/") + 1);
|
|
223
|
-
const id = Object.keys(urlHash).indexOf(layer.url) > -1
|
|
224
|
-
? urlHash[layer.url]
|
|
225
|
-
: undefined;
|
|
226
|
-
if (id) {
|
|
227
|
-
common.cacheLayerInfo(layerId, id, layer.url, templateDictionary);
|
|
228
|
-
layer.url = common.templatizeTerm(id, id, ".layer" + layerId + ".url");
|
|
229
|
-
layer.itemId = common.templatizeTerm(id, id, ".layer" + layerId + ".itemId");
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Templatize field references.
|
|
236
|
-
*
|
|
237
|
-
* @param solutionTemplate The solution item template
|
|
238
|
-
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
239
|
-
* @returns The solutionTemplate with templatized field references
|
|
240
|
-
*/
|
|
241
|
-
export function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
|
|
242
|
-
const paths = [
|
|
243
|
-
"data.operationalLayers",
|
|
244
|
-
"data.tables",
|
|
245
|
-
"data.applicationProperties.viewing.search.layers"
|
|
246
|
-
];
|
|
247
|
-
paths.forEach(p => _templatizeProperty(solutionTemplate, datasourceInfos, p));
|
|
248
|
-
return solutionTemplate;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Templatize field references.
|
|
252
|
-
*
|
|
253
|
-
* @param solutionTemplate The solution item template
|
|
254
|
-
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
255
|
-
* @param path A string path to the object property to templatize
|
|
256
|
-
* @private
|
|
257
|
-
*/
|
|
258
|
-
export function _templatizeProperty(solutionTemplate, datasourceInfos, path) {
|
|
259
|
-
const objs = common.getProp(solutionTemplate, path);
|
|
260
|
-
if (objs) {
|
|
261
|
-
common.setProp(solutionTemplate, path, _templatize(objs, datasourceInfos));
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Templatize field references.
|
|
266
|
-
*
|
|
267
|
-
* @param objs Can be operationalLayers or tables or appProperties search layers
|
|
268
|
-
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
269
|
-
* @returns updated instances of the objects
|
|
270
|
-
* @private
|
|
271
|
-
*/
|
|
272
|
-
export function _templatize(objs, datasourceInfos) {
|
|
273
|
-
objs.forEach(obj => {
|
|
274
|
-
const ds = _getDatasourceInfo(obj, datasourceInfos);
|
|
275
|
-
if (ds) {
|
|
276
|
-
const fieldNames = ds.fields.map(f => f.name);
|
|
277
|
-
common._templatizePopupInfo(obj, ds, ds.basePath, ds.itemId, fieldNames);
|
|
278
|
-
common._templatizeDefinitionEditor(obj, ds.basePath, fieldNames);
|
|
279
|
-
if (obj.layerDefinition) {
|
|
280
|
-
common._templatizeDrawingInfo(obj.layerDefinition, ds.basePath, fieldNames);
|
|
281
|
-
common._templatizeDefinitionExpression(obj.layerDefinition, ds.basePath, fieldNames);
|
|
282
|
-
}
|
|
283
|
-
// used for applicationProperties search layers
|
|
284
|
-
const fieldName = common.getProp(obj, "field.name");
|
|
285
|
-
if (fieldName) {
|
|
286
|
-
common.setProp(obj, "field.name", common._templatizeFieldName(fieldName, obj, ds.itemId, ds.basePath));
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
return objs;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Get datasourceInfo by map layer id
|
|
294
|
-
*
|
|
295
|
-
* @param obj Can be operationalLayer or table or appProperties search layer
|
|
296
|
-
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
297
|
-
* @returns datasourceInfo for the given object id
|
|
298
|
-
* @private
|
|
299
|
-
*/
|
|
300
|
-
export function _getDatasourceInfo(obj, datasourceInfos) {
|
|
301
|
-
let datasourceInfo;
|
|
302
|
-
datasourceInfos.some(ds => {
|
|
303
|
-
if (ds.ids.indexOf(obj.id) > -1) {
|
|
304
|
-
datasourceInfo = ds;
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
return false;
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
return datasourceInfo;
|
|
312
|
-
}
|
|
1
|
+
/** @license
|
|
2
|
+
* Copyright 2018 Esri
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import * as common from "@esri/solution-common";
|
|
17
|
+
/**
|
|
18
|
+
* The portion of a Webmap URL between the server and the map id.
|
|
19
|
+
*
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
const WEBMAP_APP_URL_PART = "home/webmap/viewer.html?webmap=";
|
|
23
|
+
/**
|
|
24
|
+
* A flag inserted used as a vector tile layer's styleUrl to indicate that the layer is unsupported and should
|
|
25
|
+
* be removed.
|
|
26
|
+
*/
|
|
27
|
+
const unsupportedTileLayerUrl = "unsupported";
|
|
28
|
+
// ------------------------------------------------------------------------------------------------------------------ //
|
|
29
|
+
/**
|
|
30
|
+
* Converts an AGOL webmap item to a template.
|
|
31
|
+
*
|
|
32
|
+
* @param itemTemplate Template for the webmap item
|
|
33
|
+
* @param destAuthentication Credentials for requests to the destination organization
|
|
34
|
+
* @param srcAuthentication Credentials for requests to source items
|
|
35
|
+
* @param templateDictionary Hash of key details used for variable replacement
|
|
36
|
+
* @returns Template for the solution item that contains key details for item reconstruction
|
|
37
|
+
*/
|
|
38
|
+
export function convertItemToTemplate(itemTemplate, destAuthentication, srcAuthentication, templateDictionary) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
// Templatize the app URL if it's not a vector tile service
|
|
41
|
+
if (itemTemplate.type !== "Vector Tile Service") {
|
|
42
|
+
itemTemplate.item.url = itemTemplate.item.url
|
|
43
|
+
? common.checkUrlPathTermination(common.placeholder(common.SERVER_NAME)) + WEBMAP_APP_URL_PART + itemTemplate.item.id
|
|
44
|
+
: itemTemplate.item.url; // templatized id
|
|
45
|
+
}
|
|
46
|
+
// Extract dependencies
|
|
47
|
+
_extractDependencies(itemTemplate, srcAuthentication).then((results) => {
|
|
48
|
+
itemTemplate.dependencies = results.dependencies;
|
|
49
|
+
// Templatize the map layer ids after we've extracted them as dependencies
|
|
50
|
+
if (itemTemplate.data) {
|
|
51
|
+
const baseMapLayers = itemTemplate.data.baseMap?.baseMapLayers;
|
|
52
|
+
if (baseMapLayers) {
|
|
53
|
+
itemTemplate.data.baseMap.baseMapLayers =
|
|
54
|
+
baseMapLayers.filter(layer => layer.styleUrl !== unsupportedTileLayerUrl);
|
|
55
|
+
_templatizeWebmapLayerIdsAndUrls(itemTemplate.data.baseMap.baseMapLayers, results.urlHash, templateDictionary);
|
|
56
|
+
}
|
|
57
|
+
const operationalLayers = itemTemplate.data.operationalLayers;
|
|
58
|
+
if (operationalLayers) {
|
|
59
|
+
itemTemplate.data.operationalLayers =
|
|
60
|
+
operationalLayers.filter(layer => layer.styleUrl !== unsupportedTileLayerUrl);
|
|
61
|
+
_templatizeWebmapLayerIdsAndUrls(itemTemplate.data.operationalLayers, results.urlHash, templateDictionary);
|
|
62
|
+
}
|
|
63
|
+
_templatizeWebmapLayerIdsAndUrls(itemTemplate.data.tables, results.urlHash, templateDictionary);
|
|
64
|
+
// Exclude intialState
|
|
65
|
+
_excludeInitialState(itemTemplate.data);
|
|
66
|
+
}
|
|
67
|
+
resolve(itemTemplate);
|
|
68
|
+
}, e => reject(common.fail(e)));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Gets the ids of the dependencies of an AGOL webmap item.
|
|
73
|
+
*
|
|
74
|
+
* @param itemTemplate A webmap item whose dependencies are sought
|
|
75
|
+
* @param authentication Credentials for any requests
|
|
76
|
+
* @returns List of dependencies ids and url/itemId hash
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
export function _extractDependencies(itemTemplate, authentication) {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const dependencies = [];
|
|
82
|
+
if (itemTemplate.data) {
|
|
83
|
+
const basemapLayers = itemTemplate.data.baseMap?.baseMapLayers || [];
|
|
84
|
+
const opLayers = itemTemplate.data.operationalLayers || [];
|
|
85
|
+
const tables = itemTemplate.data.tables || [];
|
|
86
|
+
const layersAndTables = basemapLayers.concat(opLayers).concat(tables);
|
|
87
|
+
_getLayerIds(layersAndTables, dependencies, authentication).then(results => {
|
|
88
|
+
resolve(results);
|
|
89
|
+
}, e => reject(common.fail(e)));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
resolve({
|
|
93
|
+
dependencies: dependencies,
|
|
94
|
+
urlHash: {}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Remove the initialState prop from webmaps saved from the new map viewer.
|
|
101
|
+
* This allows the map to use the item extent property that we templatize.
|
|
102
|
+
*
|
|
103
|
+
* Added for issue #662
|
|
104
|
+
*
|
|
105
|
+
* @param data the data for the web maps item template
|
|
106
|
+
* @returns void
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
export function _excludeInitialState(data) {
|
|
110
|
+
common.deleteProp(data, "initialState");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Extracts the AGOL itemId for each layer or table object in a list using the url.
|
|
114
|
+
*
|
|
115
|
+
* @param layerList List of map layers or tables; supported vector tile layers have their styleUrls templatized
|
|
116
|
+
* @param dependencies Current list of dependencies
|
|
117
|
+
* @param authentication Credentials for any requests
|
|
118
|
+
* @returns Updated list of dependencies ids, url/itemId hash (for feature layers),
|
|
119
|
+
* and id/styleUrl hash (for vector tile layers)
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
export function _getLayerIds(layerList, dependencies, authentication) {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
const urlHash = {};
|
|
125
|
+
const options = {
|
|
126
|
+
f: "json",
|
|
127
|
+
authentication: authentication
|
|
128
|
+
};
|
|
129
|
+
const layerPromises = [];
|
|
130
|
+
const layerChecks = {};
|
|
131
|
+
const layers = layerList.filter(layer => {
|
|
132
|
+
// Test for Vector Tile Layers
|
|
133
|
+
if (layer.itemId && layer.layerType === "VectorTileLayer") {
|
|
134
|
+
// Fetch the item so that we can check if it has the typeKeyword "Vector Tile Style Editor", which ensures
|
|
135
|
+
// that the user has edited the style and it is something that could be reasonably be packaged with the
|
|
136
|
+
// solution
|
|
137
|
+
layerPromises.push(common.getItemBase(layer.itemId, authentication));
|
|
138
|
+
return true;
|
|
139
|
+
// Handle a feature server layer
|
|
140
|
+
}
|
|
141
|
+
else if (layer.url && layer.url.indexOf("{{velocityUrl}}") < 0) {
|
|
142
|
+
const results = /.+FeatureServer/g.exec(layer.url);
|
|
143
|
+
const baseUrl = Array.isArray(results) && results.length > 0 ? results[0] : undefined;
|
|
144
|
+
if (baseUrl) {
|
|
145
|
+
// avoid redundant checks when we have a layer with subLayers
|
|
146
|
+
if (Object.keys(layerChecks).indexOf(baseUrl) < 0) {
|
|
147
|
+
layerChecks[baseUrl] = common.rest_request(layer.url, options);
|
|
148
|
+
}
|
|
149
|
+
layerPromises.push(layerChecks[baseUrl]);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
// This layer is not a dependency
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
// We have a mix of Vector Tile Layer item base requests and Feature Server info requests
|
|
162
|
+
if (layerPromises.length > 0) {
|
|
163
|
+
Promise.all(layerPromises).then((responses) => {
|
|
164
|
+
responses.forEach((response, i) => {
|
|
165
|
+
if (layers[i].layerType === "VectorTileLayer") {
|
|
166
|
+
const typeKeywords = common.getProp(response, "typeKeywords");
|
|
167
|
+
if (typeKeywords && typeKeywords.includes("Vector Tile Style Editor")) {
|
|
168
|
+
// Vector tiles edited by the style editor
|
|
169
|
+
if (dependencies.indexOf(response.id) < 0) {
|
|
170
|
+
dependencies.push(response.id);
|
|
171
|
+
}
|
|
172
|
+
// Templatize the URL to the style resource
|
|
173
|
+
const iSuffix = layers[i].styleUrl.indexOf(response.id) + response.id.length;
|
|
174
|
+
layers[i].styleUrl = common.templatizeTerm(layers[i].styleUrl.replace(layers[i].styleUrl.substring(0, iSuffix), response.id), response.id, ".itemUrl");
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// Unsupported vector tiles
|
|
178
|
+
layers[i].styleUrl = unsupportedTileLayerUrl;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (common.getProp(response, "serviceItemId")) {
|
|
182
|
+
// Feature Service
|
|
183
|
+
const id = response.serviceItemId;
|
|
184
|
+
if (dependencies.indexOf(id) < 0) {
|
|
185
|
+
dependencies.push(id);
|
|
186
|
+
}
|
|
187
|
+
urlHash[layers[i].url] = id;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
resolve({
|
|
191
|
+
dependencies,
|
|
192
|
+
urlHash
|
|
193
|
+
});
|
|
194
|
+
}, e => reject(common.fail(e)));
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
resolve({
|
|
198
|
+
dependencies,
|
|
199
|
+
urlHash
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Templatizes the url and item id for layers or tables within the webmap.
|
|
206
|
+
*
|
|
207
|
+
* @param layerList List of map layers or tables
|
|
208
|
+
* @param urlHash Lookup object for analysis layers; hash from URL to AGO item id
|
|
209
|
+
* @param templateDictionary Hash of key details used for variable replacement
|
|
210
|
+
* @returns void
|
|
211
|
+
* @private
|
|
212
|
+
*/
|
|
213
|
+
export function _templatizeWebmapLayerIdsAndUrls(layerList = [], urlHash, templateDictionary) {
|
|
214
|
+
layerList.forEach((layer) => {
|
|
215
|
+
// Test for Vector Tile Layers
|
|
216
|
+
if (layer.itemId && layer.layerType === "VectorTileLayer") {
|
|
217
|
+
// No further test needed: we've already pruned out unsupported vector tile layers
|
|
218
|
+
layer.itemId = common.templatizeTerm(layer.itemId, layer.itemId, ".itemId");
|
|
219
|
+
// Handle a feature server layer
|
|
220
|
+
}
|
|
221
|
+
else if (layer.url) {
|
|
222
|
+
const layerId = layer.url.substr(layer.url.lastIndexOf("/") + 1);
|
|
223
|
+
const id = Object.keys(urlHash).indexOf(layer.url) > -1
|
|
224
|
+
? urlHash[layer.url]
|
|
225
|
+
: undefined;
|
|
226
|
+
if (id) {
|
|
227
|
+
common.cacheLayerInfo(layerId, id, layer.url, templateDictionary);
|
|
228
|
+
layer.url = common.templatizeTerm(id, id, ".layer" + layerId + ".url");
|
|
229
|
+
layer.itemId = common.templatizeTerm(id, id, ".layer" + layerId + ".itemId");
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Templatize field references.
|
|
236
|
+
*
|
|
237
|
+
* @param solutionTemplate The solution item template
|
|
238
|
+
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
239
|
+
* @returns The solutionTemplate with templatized field references
|
|
240
|
+
*/
|
|
241
|
+
export function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
|
|
242
|
+
const paths = [
|
|
243
|
+
"data.operationalLayers",
|
|
244
|
+
"data.tables",
|
|
245
|
+
"data.applicationProperties.viewing.search.layers"
|
|
246
|
+
];
|
|
247
|
+
paths.forEach(p => _templatizeProperty(solutionTemplate, datasourceInfos, p));
|
|
248
|
+
return solutionTemplate;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Templatize field references.
|
|
252
|
+
*
|
|
253
|
+
* @param solutionTemplate The solution item template
|
|
254
|
+
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
255
|
+
* @param path A string path to the object property to templatize
|
|
256
|
+
* @private
|
|
257
|
+
*/
|
|
258
|
+
export function _templatizeProperty(solutionTemplate, datasourceInfos, path) {
|
|
259
|
+
const objs = common.getProp(solutionTemplate, path);
|
|
260
|
+
if (objs) {
|
|
261
|
+
common.setProp(solutionTemplate, path, _templatize(objs, datasourceInfos));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Templatize field references.
|
|
266
|
+
*
|
|
267
|
+
* @param objs Can be operationalLayers or tables or appProperties search layers
|
|
268
|
+
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
269
|
+
* @returns updated instances of the objects
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
export function _templatize(objs, datasourceInfos) {
|
|
273
|
+
objs.forEach(obj => {
|
|
274
|
+
const ds = _getDatasourceInfo(obj, datasourceInfos);
|
|
275
|
+
if (ds) {
|
|
276
|
+
const fieldNames = ds.fields.map(f => f.name);
|
|
277
|
+
common._templatizePopupInfo(obj, ds, ds.basePath, ds.itemId, fieldNames);
|
|
278
|
+
common._templatizeDefinitionEditor(obj, ds.basePath, fieldNames);
|
|
279
|
+
if (obj.layerDefinition) {
|
|
280
|
+
common._templatizeDrawingInfo(obj.layerDefinition, ds.basePath, fieldNames);
|
|
281
|
+
common._templatizeDefinitionExpression(obj.layerDefinition, ds.basePath, fieldNames);
|
|
282
|
+
}
|
|
283
|
+
// used for applicationProperties search layers
|
|
284
|
+
const fieldName = common.getProp(obj, "field.name");
|
|
285
|
+
if (fieldName) {
|
|
286
|
+
common.setProp(obj, "field.name", common._templatizeFieldName(fieldName, obj, ds.itemId, ds.basePath));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return objs;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Get datasourceInfo by map layer id
|
|
294
|
+
*
|
|
295
|
+
* @param obj Can be operationalLayer or table or appProperties search layer
|
|
296
|
+
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
297
|
+
* @returns datasourceInfo for the given object id
|
|
298
|
+
* @private
|
|
299
|
+
*/
|
|
300
|
+
export function _getDatasourceInfo(obj, datasourceInfos) {
|
|
301
|
+
let datasourceInfo;
|
|
302
|
+
datasourceInfos.some(ds => {
|
|
303
|
+
if (ds.ids.indexOf(obj.id) > -1) {
|
|
304
|
+
datasourceInfo = ds;
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
return datasourceInfo;
|
|
312
|
+
}
|
|
313
313
|
//# sourceMappingURL=webmap.js.map
|