Skip to content

Commit

Permalink
CADENZA-36890 Add the object info to cadenza.js and sandbox.html (#36)
Browse files Browse the repository at this point in the history
* CADENZA-36890 Add the object info to cadenza.js and sandbox.html

* CADENZA-36890 Add documentation

* CADENZA-36890 Add to CHANGELOG.md

* CADENZA-36890 Fix the header creation

* use <> instead of {} for placeholders in docs to avoid confusion in JSON examples

* add support for dataType=pdf in CadenzaClient#downloadData and #fetchData

* chore: release v2.11.0

* include version

* CADENZA-36890 Add to CHANGELOG.md

* CADENZA-36890 Review changes

* CADENZA-36890 Review changes

* CADENZA-36890 changed the name of the feature id

* CADENZA-36890 layerPath is not optional for fetchObjectInfo

* CADENZA-36890 code format

---------

Co-authored-by: luebke <[email protected]>
Co-authored-by: kissel <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Andreas W. Bartels <[email protected]>
  • Loading branch information
5 people authored Aug 23, 2024
1 parent f3b6a46 commit 7683272
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- `CadenzaClient#fetchObjectInfo`

## 2.11.0 - 2024-07-12
### Added
Expand Down
47 changes: 37 additions & 10 deletions sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,21 @@
},
setFilter: data => cadenzaClient.setFilter(parseFilterVariables(data.filter)),
setLayerVisibility: data => cadenzaClient.setLayerVisibility(JSON.parse(data.layer), data.visibility === 'on'),
setSelection: data => cadenzaClient.setSelection(JSON.parse(data.layer), JSON.parse(data.values)),
addSelection: data => cadenzaClient.addSelection(JSON.parse(data.layer), JSON.parse(data.values)),
removeSelection: data => cadenzaClient.removeSelection(JSON.parse(data.layer), JSON.parse(data.values)),
setSelection: data => cadenzaClient.setSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
addSelection: data => cadenzaClient.addSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
removeSelection: data => cadenzaClient.removeSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
createGeometry: data => cadenzaClient.createGeometry(data.embeddingTargetId, data.geometryType, getOptions(data)),
editGeometry: ({ geometry, ...data }) => cadenzaClient.editGeometry(data.embeddingTargetId, JSON.parse(geometry), getOptions(data)),
selectObjects: data => cadenzaClient.selectObjects(data.embeddingTargetId, getOptions(data)),
fetchData: data => {
console.log('Inspect the fetchData() request in the devtools.');
cadenzaClient.fetchData(data.embeddingTargetId, data.dataType, getOptions(data));
},
fetchObjectInfo: data => {
console.log('Inspect the fetchObjectInfo() request in the devtools.');
cadenzaClient.fetchObjectInfo(data.embeddingTargetId, JSON.parse(data.layer), JSON.parse(data.objectIds), getOptions(data))
.then(oi => console.log(oi));
},
downloadData: data => cadenzaClient.downloadData(data.embeddingTargetId, data.dataType, getOptions(data))
};

Expand Down Expand Up @@ -217,6 +222,7 @@
layers,
simplifiedOperationMode,
useMapSrs,
fullGeometries,
zoomToGeometry
}) {
return {
Expand All @@ -237,6 +243,7 @@
...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
layers: layers ? JSON.parse(layers) : undefined,
useMapSrs: useMapSrs === 'on',
fullGeometries: fullGeometries === 'on',
zoomTarget: zoomToGeometry === 'on' ? { type: 'geometry' } : undefined
};
}
Expand Down Expand Up @@ -286,6 +293,7 @@
<optgroup label="Without Iframe">
<option value="downloadData">Download data</option>
<option value="fetchData">Fetch data</option>
<option value="fetchObjectInfo">Fetch Object Info</option>
</optgroup>
</select>
</div>
Expand Down Expand Up @@ -520,9 +528,9 @@
</div>
</template>

<template data-action="setSelection" data-common="layer,layer-selection"></template>
<template data-action="addSelection" data-common="layer,layer-selection"></template>
<template data-action="removeSelection" data-common="layer,layer-selection"></template>
<template data-action="setSelection" data-common="layer,object-ids"></template>
<template data-action="addSelection" data-common="layer,object-ids"></template>
<template data-action="removeSelection" data-common="layer,object-ids"></template>

<template data-action="reload">
<div>
Expand All @@ -534,12 +542,12 @@
</template>
<template data-action="closeMe">No Parameters needed.</template>

<template id="common-layer-selection">
<template id="common-object-ids">
<div>
<label for="values">List of Object IDs *</label>
<textarea name="values" id="values" rows="5" required></textarea>
<label for="objectids">List of object ID value lists *</label>
<textarea name="objectIds" id="objectids" rows="5" required></textarea>
<small>
<p>A JSON value like <code>["object1","object2"]</code></p>
<p>A JSON value like <code>[["&lt;object1-id&gt;"],["&lt;object2-id&gt;"]]</code></p>
</small>
</div>
</template>
Expand Down Expand Up @@ -584,6 +592,25 @@
</div>
</template>

<template data-action="fetchObjectInfo" data-common="layer,object-ids,filter">
<div>
<label for="embeddingTargetId">Embedding target ID *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label>
<input type="checkbox" name="useMapSrs">
Use map SRS
</label>
</div>
<div>
<label>
<input type="checkbox" name="fullGeometries">
Return the non-simplified geometries
</label>
</div>
</template>

<template data-action="getData">
<div>
<label for="dataType">Data type</label>
Expand Down
70 changes: 63 additions & 7 deletions src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ globalThis.cadenza = Object.assign(
* _Note:_ Since numbers in JavaScript are Double values ([more info on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#number_encoding)),
* for Long variables, the API is currently limited to the Double value range.
*/
/**
* @typedef Feature - A adapted [GeoJSON](https://geojson.org/) feature object.
* @property {any[]} objectId - The id of the feature
* @property {Geometry} geometry - The geometry
* @property {Record<string, string>} properties - The formated properties
* @property {number} [area] - The area of a `Polygon` feature
* @property {number} [length] - The area of a `LineString` feature
*/
/**
* @typedef FeatureCollection - A adapted [GeoJSON](https://geojson.org/) feature collection object
* @property {Feature[]} features - The features within this collection
*/

let hasCadenzaSession = false;

Expand Down Expand Up @@ -470,7 +482,7 @@ export class CadenzaClient {
*
* @hidden
* @param {WorkbookLayerPath | string} layer - The data view layer to set the selection in
* @param {unknown[]} values - The IDs of the objects to select
* @param {unknown[][]} values - The IDs of the objects to select
* @return {Promise<void>} A `Promise` for when the selection was set.
* @postMessage
*/
Expand All @@ -484,7 +496,7 @@ export class CadenzaClient {
*
* @hidden
* @param {WorkbookLayerPath | string} layer - The data view layer to change the selection in
* @param {unknown[]} values - The IDs of the objects to select
* @param {unknown[][]} values - The IDs of the objects to select
* @return {Promise<void>} A `Promise` for when the selection was changed.
* @postMessage
*/
Expand All @@ -498,7 +510,7 @@ export class CadenzaClient {
*
* @hidden
* @param {WorkbookLayerPath | string} layer - The data view layer to change the selection in
* @param {unknown[]} values - The IDs of the objects to unselect
* @param {unknown[][]} values - The IDs of the objects to unselect
* @return {Promise<void>} A `Promise` for when the selection was changed.
* @postMessage
*/
Expand Down Expand Up @@ -869,19 +881,63 @@ export class CadenzaClient {
return this.#fetch(resolvePath(source), params, signal);
}

/**
* Fetch object info from a workbook map view.
*
* @param {EmbeddingTargetId} source - The workbook view to fetch object info from.
* @param {(WorkbookLayerPath | string)[]} layerPath - Layer path to identify the layer
* (identified using layer paths or print names)
* @param {unknown[][]} objectIds - The IDs of the objects to select
* @param {object} [options] - Options
* @param {FilterVariables} [options.filter] - Filter variables
* @param {AbortSignal} [options.signal] - A signal to abort the data fetching
* @param {Boolean} [options.useMapSrs] - Use the map SRS instead of WGS84
* @param {Boolean} [options.fullGeometries] - Return non-simplified geometries
* @return {Promise<FeatureCollection>} A `Promise` for the fetch response
* @throws For invalid arguments
*/
fetchObjectInfo(
source,
layerPath,
objectIds,
{ filter, signal, useMapSrs, fullGeometries } = {},
) {
this.#log('CadenzaClient#fetchObjectInfo', ...arguments);
const params = createParams({
filter,
});
return this.#fetch(
resolvePath(source) + '/objectinfo',
params,
signal,
JSON.stringify({
objectIds,
layerPath: array(layerPath),
useMapSrs,
fullGeometries,
}),
).then((response) => response.json());
}

async #fetch(
/** @type string */ path,
/** @type URLSearchParams */ params,
/** @type AbortSignal | undefined */ signal,
/** @type String | undefined If body is set, the fetch will be a post.*/ body,
) {
const url = this.#createUrl(path, params);
this.#log('Fetch', url.toString());
const method = body ? 'POST' : undefined;
const headers = new Headers();
headers.set('X-Requested-With', 'XMLHttpRequest');
if (body) {
headers.set('Content-Type', 'application/json');
}
const res = await fetch(url, {
signal,
headers: {
// Make Cadenza return an error instead of showing an error page.
'X-Requested-With': 'XMLHttpRequest',
},
method,
headers,
body,
});
if (!res.ok) {
const errorType =
Expand Down
15 changes: 15 additions & 0 deletions src/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,21 @@ const tableData = await response.json();
...
```
### Fetch the Object Info from a Workbook Map View
<small>API: [CadenzaClient#fetchObjectInfo(./classes/CadenzaClient.html#fetchObjectInfo)</small>
Download the object info from a workbook map view in JSON format. The result contains all information, that is shown in the object info within cadenza.
```javascript
const response = await cadenzaClient.fetchObjectInfo('embeddingTargetId', 'layerPrintName', [['objectId']], {
useMapSrs: false,
fullGeometries: true
});
const objectInfo = await response;
```
### Download Data From a Workbook View
<small>API: [CadenzaClient#downloadData](./classes/CadenzaClient.html#downloadData)</small>
Expand Down

0 comments on commit 7683272

Please sign in to comment.