Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CADENZA-36890 Add the object info to cadenza.js and sandbox.html #36

Merged
merged 17 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved

## 2.11.0 - 2024-07-12
### Added
Expand Down
51 changes: 39 additions & 12 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 @@ -216,7 +221,8 @@
parts,
layers,
simplifiedOperationMode,
useMapSrs
useMapSrs,
fullGeometries
}) {
return {
disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(','),
Expand All @@ -235,7 +241,8 @@
parts: parts && parts.split(','),
...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
layers: layers ? JSON.parse(layers) : undefined,
useMapSrs: useMapSrs === 'on'
useMapSrs: useMapSrs === 'on',
fullGeometries: fullGeometries === 'on'
};
}

Expand Down Expand Up @@ -284,6 +291,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 @@ -518,9 +526,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 @@ -532,12 +540,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 @@ -573,6 +581,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 @@ -133,6 +133,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 @@ -457,7 +469,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 @@ -471,7 +483,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 @@ -485,7 +497,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 @@ -844,19 +856,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;
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved
```

### Download Data From a Workbook View

<small>API: [CadenzaClient#downloadData](./classes/CadenzaClient.html#downloadData)</small>
Expand Down