From 3e05d125d1691a646f7bc4c8d196cbf9402f3390 Mon Sep 17 00:00:00 2001 From: bartels Date: Mon, 29 Jan 2024 10:31:19 +0100 Subject: [PATCH 01/35] 404 reponse, if embedding target do not match the embeded target type --- src/cadenza.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cadenza.js b/src/cadenza.js index ebd9db9c..df4d9cdd 100644 --- a/src/cadenza.js +++ b/src/cadenza.js @@ -300,6 +300,7 @@ export class CadenzaClient { operationMode, useMapSrs, }); + params.append('targetType', 'MAP'); await this.#show(resolvePath(mapView), params, signal); if (geometry) { this.#postEvent('setGeometry', { geometry }); From 0c7ccb2e9779551ecc5e3cf1ae5d3efa0668ae6a Mon Sep 17 00:00:00 2001 From: bartels Date: Tue, 30 Jan 2024 11:26:25 +0100 Subject: [PATCH 02/35] Added set selection method, to select objects of a map layer by object id. --- sandbox.html | 11 +++++++++++ src/cadenza.js | 15 +++++++++++++++ src/docs.md | 1 + 3 files changed, 27 insertions(+) diff --git a/sandbox.html b/sandbox.html index 91862a66..70b3548d 100644 --- a/sandbox.html +++ b/sandbox.html @@ -140,6 +140,7 @@ 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)), + setSelection: data => cadenzaClient.setSelection(JSON.parse(data.layerPath), JSON.parse(data.values)), fetchData: data => { console.log('Inspect the fetchData() request in the devtools.'); cadenzaClient.fetchData(data.embeddingTargetId, data.dataType, getOptions(data)); @@ -240,6 +241,7 @@ + @@ -457,6 +459,15 @@ + + @@ -460,6 +470,23 @@
+ + A JSON array of arrays. Each top level array element is a layer path, represented by an array of strings composed of layer print names. + +
+ + + diff --git a/src/cadenza.js b/src/cadenza.js index 2059b1b2..145e90eb 100644 --- a/src/cadenza.js +++ b/src/cadenza.js @@ -479,6 +479,21 @@ export class CadenzaClient { return this.#show(resolvePath(backgroundMapView), params, signal); } + /** + * Set the visibility of a layer in an embedded map view. The map view must be shown prior to calling this. + * For layers in groups, the layer path contains the ancestors also. When making a layer visible, its ancestors will + * be made visible also. When hiding a layer, the ancestors are not affected. The operation is asynchronous and its + * completion is signaled by an event of type 'setLayerVisibility:success' or 'setLayerVisibility:error'. + * + * @param {WorkbookLayerPath} layer - The layer to show or hide, identified by its path + * @param {boolean} visible - The visibility state of the layer + * @return {Promise} A `Promise` for when the layer visibility change is actually complete. + */ + setLayerVisibility(layer, visible) { + this.#log('CadenzaClient#setLayerVisibility', ...arguments); + return this.#postRequest('setLayerVisibility', { layer, visible }); + } + #show( /** @type string */ path, /** @type URLSearchParams */ params, diff --git a/src/docs.md b/src/docs.md index 413a9186..5ac6683d 100644 --- a/src/docs.md +++ b/src/docs.md @@ -231,6 +231,17 @@ cadenzaClient.on('selectObjects:ok', (event) => { }); ``` +### Change visibility of Layers in a Workbook Map + +API: [CadenzaClient#setLayerVisibility](./classes/CadenzaClient.html#setLayerVisibility) + +To change the visibility of a layer in an already shown map view, pass the layer path and the desired visibility. +The operation is asynchronous and returns a Promise. + +```javascript +cadenzaClient.setLayerVisibility([ '{layerGroupPrintName}', '{layerPrintName}' ], false); +``` + ### Highlight an Item in the Navigator API: [CadenzaClient#show](./classes/CadenzaClient.html#show) From 7843ad7d862cadc74460ce25ad3e22e8eb877ae4 Mon Sep 17 00:00:00 2001 From: kissel Date: Thu, 15 Feb 2024 19:40:14 +0100 Subject: [PATCH 14/35] group actions in sandbox for better overview --- sandbox.html | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/sandbox.html b/sandbox.html index c917e132..15e4a19b 100644 --- a/sandbox.html +++ b/sandbox.html @@ -236,20 +236,26 @@
From adc09a6c56dc0000a4eaa240d42547040e567eae Mon Sep 17 00:00:00 2001 From: kissel Date: Thu, 15 Feb 2024 20:03:20 +0100 Subject: [PATCH 15/35] improve input of layer path in sandbox --- sandbox.html | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sandbox.html b/sandbox.html index 15e4a19b..831282ac 100644 --- a/sandbox.html +++ b/sandbox.html @@ -190,7 +190,7 @@ mapExtent, minScale, parts, - layers, + layer, simplifiedOperationMode, useMapSrs }) { @@ -210,7 +210,7 @@ minScale: minScale && Number(minScale), parts: parts && parts.split(','), ...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }), - layers: layers && JSON.parse(layers), + layers: layer && [ JSON.parse(layer) ], useMapSrs: useMapSrs === 'on' }; } @@ -474,24 +474,22 @@
- - - - A JSON array of arrays. Each top level array element is a layer path, represented by an array of strings composed of layer print names. - + + + A JSON array with the print names of the layer and its ancestors, e.g. ["layerGroupName","layerName"]
From 88421b45c5a31f76cd53c41afa51b0a50eb77332 Mon Sep 17 00:00:00 2001 From: kissel Date: Thu, 15 Feb 2024 20:15:35 +0100 Subject: [PATCH 16/35] simplify setLayerVisibility docs --- src/cadenza.js | 12 ++++++------ src/docs.md | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cadenza.js b/src/cadenza.js index 145e90eb..ca064198 100644 --- a/src/cadenza.js +++ b/src/cadenza.js @@ -480,14 +480,14 @@ export class CadenzaClient { } /** - * Set the visibility of a layer in an embedded map view. The map view must be shown prior to calling this. - * For layers in groups, the layer path contains the ancestors also. When making a layer visible, its ancestors will - * be made visible also. When hiding a layer, the ancestors are not affected. The operation is asynchronous and its - * completion is signaled by an event of type 'setLayerVisibility:success' or 'setLayerVisibility:error'. + * Set the visibility of a layer in the currently shown workbook map view. * - * @param {WorkbookLayerPath} layer - The layer to show or hide, identified by its path + * When making a layer visible, its ancestors will be made visible, too. + * When hiding a layer, the ancestors are not affected. + * + * @param {WorkbookLayerPath} layer - The layer to show or hide * @param {boolean} visible - The visibility state of the layer - * @return {Promise} A `Promise` for when the layer visibility change is actually complete. + * @return {Promise} A `Promise` for when the layer visibility is set. */ setLayerVisibility(layer, visible) { this.#log('CadenzaClient#setLayerVisibility', ...arguments); diff --git a/src/docs.md b/src/docs.md index 5ac6683d..962613e1 100644 --- a/src/docs.md +++ b/src/docs.md @@ -212,7 +212,7 @@ cadenzaClient.on('editGeometry:ok', (event) => { _Note:_ Under the hood, creating a geometry is similar to editing a geometry. That's why the events use the `editGeometry` prefix. -### Select Objects in a Workbook Map +### Select Objects in a Workbook Map View API: [CadenzaClient#selectObjects](./classes/CadenzaClient.html#selectObjects) @@ -231,12 +231,11 @@ cadenzaClient.on('selectObjects:ok', (event) => { }); ``` -### Change visibility of Layers in a Workbook Map +### Set the Visibility of a Workbook Map View Layer API: [CadenzaClient#setLayerVisibility](./classes/CadenzaClient.html#setLayerVisibility) -To change the visibility of a layer in an already shown map view, pass the layer path and the desired visibility. -The operation is asynchronous and returns a Promise. +To set the visibility of a layer in the currently shown map, pass the layer path and the desired visibility. ```javascript cadenzaClient.setLayerVisibility([ '{layerGroupPrintName}', '{layerPrintName}' ], false); From 8bde324ea89d70401038de6d3a5062e37f085f16 Mon Sep 17 00:00:00 2001 From: kissel Date: Fri, 16 Feb 2024 11:20:20 +0100 Subject: [PATCH 17/35] accept simple print names to identify layers --- sandbox.html | 22 ++++++++++++++++------ src/cadenza.js | 19 ++++++++++++++----- src/docs.md | 4 ++-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/sandbox.html b/sandbox.html index 831282ac..79abdcce 100644 --- a/sandbox.html +++ b/sandbox.html @@ -190,7 +190,7 @@ mapExtent, minScale, parts, - layer, + layers, simplifiedOperationMode, useMapSrs }) { @@ -210,7 +210,7 @@ minScale: minScale && Number(minScale), parts: parts && parts.split(','), ...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }), - layers: layer && [ JSON.parse(layer) ], + layers: layers ? JSON.parse(layers) : undefined, useMapSrs: useMapSrs === 'on' }; } @@ -474,9 +474,14 @@
- - - A JSON array with the print names of the layer and its ancestors, e.g. ["layerGroupName","layerName"] + + + +

+ A JSON value like ["layerPrintName",...] or + [["layerGroupPrintName","layerPrintName"],...] +

+
@@ -484,7 +489,12 @@
- A JSON array with the print names of the layer and its ancestors, e.g. ["layerGroupName","layerName"] + +

+ A JSON value like "layerPrintName" or + ["layerGroupPrintName","layerPrintName"] +

+
@@ -555,5 +569,14 @@ + + diff --git a/src/cadenza.js b/src/cadenza.js index abf458ec..6adcfdd7 100644 --- a/src/cadenza.js +++ b/src/cadenza.js @@ -95,7 +95,7 @@ globalThis.cadenza = Object.assign( /** @typedef {[number,number,number,number]} Extent - An array of numbers representing an extent: [minx, miny, maxx, maxy] */ /** - * @typedef {'csv' | 'excel' | 'json' | 'pdf'} DataType - A data type + * @typedef {'csv' | 'excel' | 'json' | 'pdf' | 'png'} DataType - A data type * * See [JSON Representation of Cadenza Object Data](../index.html#md:json-representation-of-cadenza-object-data) for JSON data. */ @@ -650,17 +650,20 @@ export class CadenzaClient { * * It is guaranteed that a response refers to a specific request, * even if multiple request are executed in parallel. + * @template [T=void] + * @param {string} type + * @param {unknown} [detail] + * @returns {Promise} */ - #postRequest(/** @type string */ type, /** @type unknown */ detail) { + #postRequest(type, detail) { const { port1, port2 } = new MessageChannel(); - /** @type {Promise} */ const promise = new Promise((resolve, reject) => { port1.onmessage = ( /** @type MessageEvent> */ event, ) => { const cadenzaEvent = event.data; if (cadenzaEvent.type === `${type}:success`) { - resolve(); + resolve(cadenzaEvent.detail); } else if (cadenzaEvent.type === `${type}:error`) { reject(); } @@ -727,6 +730,21 @@ export class CadenzaClient { return res; } + /** + * Get data from the currently shown workbook view. + * + * Currently, only map views are supported. + * + * @template {DataType} T + * @param {T} type - The requested data type. Currently, only `"png"` is supported. + * @return {Promise} + */ + async getData(type) { + this.#log('CadenzaClient#getData', ...arguments); + assertSupportedDataType(type, ['png']); + return this.#postRequest('getData', { type }); + } + /** * Download data from a workbook view. * diff --git a/src/docs.md b/src/docs.md index 6ecf2425..263896c5 100644 --- a/src/docs.md +++ b/src/docs.md @@ -309,6 +309,20 @@ button.textContent = 'Download Excel'; button.onclick = () => cadenzaClient.downloadData('{embeddingTargetId}', 'excel'); ``` +### Request Data From a Workbook View + +API: [CadenzaClient#getData](./classes/CadenzaClient.html#getData) + +Request data from a workbook view. +Supported DataTypes: +- png: return Blob with the image of the currently displayed map + +```javascript +const canvas = document.querySelector('canvas'); +const data = await cadenzaClient.getData('png'); +canvas.drawImage(await createImageBitmap(data), 0, 0); +``` + ## The Development Sandbox The development sandbox is a simple custom application (in fact a single `.html` file) for playing with Cadenza JS. From 54aef9157ab30d26f61828b5c01f3ac470c3f53c Mon Sep 17 00:00:00 2001 From: kissel Date: Wed, 21 Feb 2024 10:19:51 +0100 Subject: [PATCH 31/35] improve order of sandbox actions and examples in the docs --- sandbox.html | 47 +++++++++++++++++----------------- src/cadenza.js | 68 +++++++++++++++++++++++++------------------------- src/docs.md | 46 ++++++++++++++++------------------ 3 files changed, 80 insertions(+), 81 deletions(-) diff --git a/sandbox.html b/sandbox.html index a1cfae70..6e89cda3 100644 --- a/sandbox.html +++ b/sandbox.html @@ -134,10 +134,19 @@ const actionHandlers = { show: data => cadenzaClient.show(data.embeddingTargetId, getOptions(data)), showPage: data => cadenzaClient.show({ page: data.page }, getOptions(data)), - expandNavigator: data => cadenzaClient.expandNavigator(data.expandNavigator === 'on'), showMap: data => cadenzaClient.showMap(data.embeddingTargetId, getOptions(data)), - setLayerVisibility: data => cadenzaClient.setLayerVisibility(JSON.parse(data.layer), data.visibility === 'on'), + expandNavigator: data => cadenzaClient.expandNavigator(data.expandNavigator === 'on'), + getData: async data => { + const dataType = data.dataType; + const result = await cadenzaClient.getData(dataType); + if (dataType === 'png') { + const url = URL.createObjectURL(result); + iframe.src = url; + URL.revokeObjectURL(url); + } + }, setFilter: data => cadenzaClient.setFilter(parseFilterVariables(data.filter)), + setLayerVisibility: data => cadenzaClient.setLayerVisibility(JSON.parse(data.layer), data.visibility === 'on'), 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)), @@ -148,18 +157,7 @@ console.log('Inspect the fetchData() request in the devtools.'); cadenzaClient.fetchData(data.embeddingTargetId, data.dataType, getOptions(data)); }, - downloadData: data => cadenzaClient.downloadData(data.embeddingTargetId, data.dataType, getOptions(data)), - getData: async data => { - const result = await cadenzaClient.getData(data.dataType); - if (data.dataType === 'png') { - const url = URL.createObjectURL(result); - try { - iframe.src = url; - } finally { - URL.revokeObjectURL(url); - } - } - } + downloadData: data => cadenzaClient.downloadData(data.embeddingTargetId, data.dataType, getOptions(data)) }; const form = document.getElementById('form'); @@ -247,11 +245,14 @@
@@ -368,7 +366,6 @@ -
@@ -571,10 +568,14 @@ diff --git a/src/cadenza.js b/src/cadenza.js index 6adcfdd7..54fe18b7 100644 --- a/src/cadenza.js +++ b/src/cadenza.js @@ -334,6 +334,21 @@ export class CadenzaClient { this.#postEvent('expandNavigator', { expandNavigator: Boolean(expanded) }); } + /** + * Get data from the currently shown workbook view. + * + * Currently, only map views are supported. + * + * @template {DataType} T + * @param {T} dataType - The requested data type. Currently, only `"png"` is supported. + * @return {Promise} + */ + async getData(dataType) { + this.#log('CadenzaClient#getData', ...arguments); + assertSupportedDataType(dataType, ['png']); + return this.#postRequest('getData', { dataType }); + } + /** * Set filter variables in the currently shown workbook. * @@ -345,6 +360,25 @@ export class CadenzaClient { return this.#postRequest('setFilter', { filter }); } + /** + * Set the visibility of a layer in the currently shown workbook map view. + * + * When making a layer visible, its ancestors will be made visible, too. + * When hiding a layer, the ancestors are not affected. + * + * @param {WorkbookLayerPath | string} layer - The layer to show or hide + * (identified using a layer path or a print name) + * @param {boolean} visible - The visibility state of the layer + * @return {Promise} A `Promise` for when the layer visibility is set. + */ + setLayerVisibility(layer, visible) { + this.#log('CadenzaClient#setLayerVisibility', ...arguments); + return this.#postRequest('setLayerVisibility', { + layer: array(layer), + visible, + }); + } + /** * Set Selection in the currently shown map view. * @@ -500,25 +534,6 @@ export class CadenzaClient { return this.#show(resolvePath(backgroundMapView), params, signal); } - /** - * Set the visibility of a layer in the currently shown workbook map view. - * - * When making a layer visible, its ancestors will be made visible, too. - * When hiding a layer, the ancestors are not affected. - * - * @param {WorkbookLayerPath | string} layer - The layer to show or hide - * (identified using a layer path or a print name) - * @param {boolean} visible - The visibility state of the layer - * @return {Promise} A `Promise` for when the layer visibility is set. - */ - setLayerVisibility(layer, visible) { - this.#log('CadenzaClient#setLayerVisibility', ...arguments); - return this.#postRequest('setLayerVisibility', { - layer: array(layer), - visible, - }); - } - #show( /** @type string */ path, /** @type URLSearchParams */ params, @@ -730,21 +745,6 @@ export class CadenzaClient { return res; } - /** - * Get data from the currently shown workbook view. - * - * Currently, only map views are supported. - * - * @template {DataType} T - * @param {T} type - The requested data type. Currently, only `"png"` is supported. - * @return {Promise} - */ - async getData(type) { - this.#log('CadenzaClient#getData', ...arguments); - assertSupportedDataType(type, ['png']); - return this.#postRequest('getData', { type }); - } - /** * Download data from a workbook view. * diff --git a/src/docs.md b/src/docs.md index 263896c5..bca0b4ee 100644 --- a/src/docs.md +++ b/src/docs.md @@ -157,6 +157,28 @@ cadenzaClient.showMap('{embeddingTargetId}', { }); ``` +### Set the Visibility of a Layer in the Currently Shown Workbook Map View + +API: [CadenzaClient#setLayerVisibility](./classes/CadenzaClient.html#setLayerVisibility) + +To set the visibility of a layer in the currently shown map, pass the layer path or print name and the desired visibility. + +```javascript +cadenzaClient.setLayerVisibility('{layerPrintName}', false); +``` + +### Get the Image of the Currently Shown Workbook Map View + +API: [CadenzaClient#getData](./classes/CadenzaClient.html#getData) + +The method may support multiple data types in the future. Currently, only `"png"` is supported to get the image of a workbook map view. + +```javascript +const canvas = document.querySelector('canvas'); +const data = await cadenzaClient.getData('png'); +canvas.drawImage(await createImageBitmap(data), 0, 0); +``` + ### Edit an Existing Geometry API: [CadenzaClient#editGeometry](./classes/CadenzaClient.html#editGeometry), [CadenzaClient#on](./classes/CadenzaClient.html#on) @@ -231,16 +253,6 @@ cadenzaClient.on('selectObjects:ok', (event) => { }); ``` -### Set the Visibility of a Workbook Map View Layer - -API: [CadenzaClient#setLayerVisibility](./classes/CadenzaClient.html#setLayerVisibility) - -To set the visibility of a layer in the currently shown map, pass the layer path or print name and the desired visibility. - -```javascript -cadenzaClient.setLayerVisibility('{layerPrintName}', false); -``` - ### Highlight an Item in the Navigator API: [CadenzaClient#show](./classes/CadenzaClient.html#show) @@ -309,20 +321,6 @@ button.textContent = 'Download Excel'; button.onclick = () => cadenzaClient.downloadData('{embeddingTargetId}', 'excel'); ``` -### Request Data From a Workbook View - -API: [CadenzaClient#getData](./classes/CadenzaClient.html#getData) - -Request data from a workbook view. -Supported DataTypes: -- png: return Blob with the image of the currently displayed map - -```javascript -const canvas = document.querySelector('canvas'); -const data = await cadenzaClient.getData('png'); -canvas.drawImage(await createImageBitmap(data), 0, 0); -``` - ## The Development Sandbox The development sandbox is a simple custom application (in fact a single `.html` file) for playing with Cadenza JS. From 7fdc276a57baa1f7678a6161d4b9c65e60c4a811 Mon Sep 17 00:00:00 2001 From: kissel Date: Wed, 21 Feb 2024 10:35:19 +0100 Subject: [PATCH 32/35] handle targetType in createParams --- src/cadenza.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cadenza.js b/src/cadenza.js index 54fe18b7..4497b661 100644 --- a/src/cadenza.js +++ b/src/cadenza.js @@ -315,9 +315,9 @@ export class CadenzaClient { locationFinder, mapExtent, operationMode, + targetType: 'MAP', useMapSrs, }); - params.append('targetType', 'MAP'); await this.#show(resolvePath(mapView), params, signal); if (geometry) { this.#postEvent('setGeometry', { geometry }); @@ -928,6 +928,7 @@ function assertSupportedDataType( * @param {number} [params.minScale] * @param {OperationMode} [params.operationMode] * @param {TablePart[]} [params.parts] + * @param {'MAP'} [params.targetType] * @param {boolean} [params.useMapSrs] * @return {URLSearchParams} */ @@ -949,6 +950,7 @@ function createParams({ minScale, operationMode, parts, + targetType, useMapSrs, }) { if (disabledUiFeatures) { @@ -1007,6 +1009,7 @@ function createParams({ ...(minScale && { minScale: String(minScale) }), ...(operationMode && operationMode !== 'normal' && { operationMode }), ...(parts && { parts: parts.join() }), + ...(targetType && { targetType }), ...(useMapSrs && { useMapSrs: 'true' }), }); } From 8f38b7f42fb9c0362ae597ea66f2c93b2798e74c Mon Sep 17 00:00:00 2001 From: kissel Date: Wed, 21 Feb 2024 10:55:24 +0100 Subject: [PATCH 33/35] improve docs of #setSelection, #addSelection, #removeSelection --- src/cadenza.js | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/src/cadenza.js b/src/cadenza.js index 4497b661..798925b4 100644 --- a/src/cadenza.js +++ b/src/cadenza.js @@ -369,7 +369,7 @@ export class CadenzaClient { * @param {WorkbookLayerPath | string} layer - The layer to show or hide * (identified using a layer path or a print name) * @param {boolean} visible - The visibility state of the layer - * @return {Promise} A `Promise` for when the layer visibility is set. + * @return {Promise} A `Promise` for when the layer visibility was set. */ setLayerVisibility(layer, visible) { this.#log('CadenzaClient#setLayerVisibility', ...arguments); @@ -380,47 +380,38 @@ export class CadenzaClient { } /** - * Set Selection in the currently shown map view. + * Set the selection in the currently shown workbook map view. * * @param {WorkbookLayerPath} layer - The data view layer to set the selection in - * @param {string[]} values - The variable values - * @return {Promise} A 'Promise' for when the selection was set. + * @param {string[]} values - The IDs of the objects to select + * @return {Promise} A `Promise` for when the selection was set. */ - setSelection( - /** @type WorkbookLayerPath */ layer, - /** @type string[] */ values, - ) { - this.#log('CadenzaClient#setSelection', layer, values); + setSelection(layer, values) { + this.#log('CadenzaClient#setSelection', ...arguments); return this.#postRequest('setSelection', { layer, values }); } /** - * Add Selection in the currently shown map view. + * Add to the selection in the currently shown workbook map view. * - * @param {WorkbookLayerPath} layer - The data view layer to add the selection in - * @param {string[]} values - The variable values - * @return {Promise} A 'Promise' for when the selection was added. + * @param {WorkbookLayerPath} layer - The data view layer to change the selection in + * @param {string[]} values - The IDs of the objects to select + * @return {Promise} A `Promise` for when the selection was changed. */ - addSelection( - /** @type WorkbookLayerPath */ layer, - /** @type string[] */ values, - ) { - this.#log('CadenzaClient#addSelection', layer, values); + addSelection(layer, values) { + this.#log('CadenzaClient#addSelection', ...arguments); return this.#postRequest('addSelection', { layer, values }); } /** - * Remove Selection in the currently shown map view. + * Remove from the selection in the currently shown workbook map view. * - * @param {WorkbookLayerPath} layer - The data view layer to remove the selection from - * @param {string[]} values - The variable values - * @return {Promise} A 'Promise' for when the selection was removed. + * @param {WorkbookLayerPath} layer - The data view layer to change the selection in + * @param {string[]} values - The IDs of the objects to unselect + * @return {Promise} A `Promise` for when the selection was changed. */ - removeSelection( - /** @type WorkbookLayerPath */ layer, - /** @type string[] */ values, - ) { - this.#log('CadenzaClient#removeSelection', layer, values); + removeSelection(layer, values) { + this.#log('CadenzaClient#removeSelection', ...arguments); return this.#postRequest('removeSelection', { layer, values }); } From 36e53dd2530f89cdff81334a948fa5fb0c6ffadf Mon Sep 17 00:00:00 2001 From: kissel Date: Wed, 21 Feb 2024 11:15:03 +0100 Subject: [PATCH 34/35] sandbox: add common-layer and common-layer-selection templates --- sandbox.html | 67 +++++++++++++++++++++----------------------------- src/cadenza.js | 15 ++++++----- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/sandbox.html b/sandbox.html index 6e89cda3..0b210305 100644 --- a/sandbox.html +++ b/sandbox.html @@ -81,6 +81,9 @@ label { font-weight: 600; } + hr:first-child { + display: none; + } select, input:is(:not([type]), [type=text], [type=number]), textarea, hr { display: block; width: 100% @@ -147,12 +150,12 @@ }, 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)), 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)), - setSelection: data => cadenzaClient.setSelection(JSON.parse(data.layerPath), JSON.parse(data.values)), - addSelection: data => cadenzaClient.addSelection(JSON.parse(data.layerPath), JSON.parse(data.values)), - removeSelection: data => cadenzaClient.removeSelection(JSON.parse(data.layerPath), JSON.parse(data.values)), fetchData: data => { console.log('Inspect the fetchData() request in the devtools.'); cadenzaClient.fetchData(data.embeddingTargetId, data.dataType, getOptions(data)); @@ -489,24 +492,14 @@

- A JSON value like ["layerPrintName",...] or - [["layerGroupPrintName","layerPrintName"],...] + A JSON value like ["{layerPrintName}",...] or + [["{layerGroupPrintName}","{layerPrintName}"],...]

-