From d7cd3370c86650c577ea42a329924f4c6516a4da Mon Sep 17 00:00:00 2001
From: Kevin Linaker <141227078+klinakerdisy@users.noreply.github.com>
Date: Thu, 8 Feb 2024 16:48:50 +0100
Subject: [PATCH] Extend "selectObjects" method with "selectableLayers"
parameter
... to allow limiting selection to specific map layers.
---
sandbox.html | 8 +++++++-
src/cadenza.js | 10 +++++++++-
src/docs.md | 14 ++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/sandbox.html b/sandbox.html
index 28fdf406..91862a66 100644
--- a/sandbox.html
+++ b/sandbox.html
@@ -186,6 +186,7 @@
mapExtent,
minScale,
parts,
+ layers,
simplifiedOperationMode,
useMapSrs
}) {
@@ -205,6 +206,7 @@
minScale: minScale && Number(minScale),
parts: parts && parts.split(','),
...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
+ layers: layers && JSON.parse(layers),
useMapSrs: useMapSrs === 'on'
};
}
@@ -242,7 +244,7 @@
-
+
@@ -449,6 +451,10 @@
+
+
+
+
diff --git a/src/cadenza.js b/src/cadenza.js
index cda8998f..ebd9db9c 100644
--- a/src/cadenza.js
+++ b/src/cadenza.js
@@ -411,6 +411,7 @@ export class CadenzaClient {
* @param {string} [options.locationFinder] - A search query for the location finder
* @param {Extent} [options.mapExtent] - A map extent to set
* @param {boolean} [options.useMapSrs] - Whether the geometry is in the map's SRS (otherwise EPSG:4326 is assumed)
+ * @param {WorkbookLayerPath[]} [options.layers] - Paths of the layers to select objects from
* @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
* @return {Promise} A `Promise` for when the iframe is loaded
* @throws For invalid arguments
@@ -421,7 +422,7 @@ export class CadenzaClient {
*/
selectObjects(
backgroundMapView,
- { locationFinder, mapExtent, useMapSrs, signal } = {},
+ { locationFinder, mapExtent, useMapSrs, layers, signal } = {},
) {
this.#log('CadenzaClient#selectObjects', ...arguments);
const params = createParams({
@@ -429,6 +430,7 @@ export class CadenzaClient {
locationFinder,
mapExtent,
useMapSrs,
+ layers,
});
return this.#show(resolvePath(backgroundMapView), params, signal);
}
@@ -825,6 +827,7 @@ function assertSupportedDataType(
* @param {number} [params.minScale]
* @param {OperationMode} [params.operationMode]
* @param {TablePart[]} [params.parts]
+ * @param {WorkbookLayerPath[]} [params.layers]
* @param {boolean} [params.useMapSrs]
* @return {URLSearchParams}
*/
@@ -844,6 +847,7 @@ function createParams({
mapExtent,
minScale,
parts,
+ layers,
useMapSrs,
operationMode,
}) {
@@ -899,6 +903,10 @@ function createParams({
...(minScale && { minScale: String(minScale) }),
...(operationMode && operationMode !== 'normal' && { operationMode }),
...(parts && { parts: parts.join() }),
+ ...(layers &&
+ layers.length && {
+ layers: JSON.stringify(layers),
+ }),
...(useMapSrs && { useMapSrs: 'true' }),
});
}
diff --git a/src/docs.md b/src/docs.md
index 8403c1e0..3256de0d 100644
--- a/src/docs.md
+++ b/src/docs.md
@@ -223,6 +223,20 @@ cadenzaClient.on('selectObjects:ok', (event) => {
});
```
+#### Limit selection to specific map layers
+
+API: [CadenzaClient#selectObjects](./classes/CadenzaClient.html#selectObjects)
+
+Limit object selection to specific map layers. For layers in groups, pass the layer path.
+
+```javascript
+cadenzaClient.selectObjects('{embeddingTargetId}', {
+ layers: [
+ [ 'layerGroupName', 'layerName' ], [ 'layerName' ]
+ ]
+ });
+```
+
### Highlight an Item in the Navigator
API: [CadenzaClient#show](./classes/CadenzaClient.html#show)