Skip to content

Commit

Permalink
Extend "selectObjects" method with "selectableLayers" parameter
Browse files Browse the repository at this point in the history
... to allow limiting selection to specific map layers.
  • Loading branch information
klinakerdisy authored Feb 8, 2024
1 parent 2fbd999 commit d7cd337
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
mapExtent,
minScale,
parts,
layers,
simplifiedOperationMode,
useMapSrs
}) {
Expand All @@ -205,6 +206,7 @@
minScale: minScale && Number(minScale),
parts: parts && parts.split(','),
...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
layers: layers && JSON.parse(layers),
useMapSrs: useMapSrs === 'on'
};
}
Expand Down Expand Up @@ -242,7 +244,7 @@
<option value="fetchData">Fetch data</option>
</select>
</div>

<button>Go!</button>
</div>

Expand Down Expand Up @@ -449,6 +451,10 @@
<label for="embeddingTargetId">Embedding target ID of the map view *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label for="layers">Layers to select objects from</label>
<input name="layers" id="layers" placeholder="[[&quot;layerGroupName&quot;,&quot;layerName&quot;],[&quot;layerName&quot;]]...">
</div>
</template>

<template data-action="downloadData" data-common="data">
Expand Down
10 changes: 9 additions & 1 deletion src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>} A `Promise` for when the iframe is loaded
* @throws For invalid arguments
Expand All @@ -421,14 +422,15 @@ export class CadenzaClient {
*/
selectObjects(
backgroundMapView,
{ locationFinder, mapExtent, useMapSrs, signal } = {},
{ locationFinder, mapExtent, useMapSrs, layers, signal } = {},
) {
this.#log('CadenzaClient#selectObjects', ...arguments);
const params = createParams({
action: 'selectObjects',
locationFinder,
mapExtent,
useMapSrs,
layers,
});
return this.#show(resolvePath(backgroundMapView), params, signal);
}
Expand Down Expand Up @@ -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}
*/
Expand All @@ -844,6 +847,7 @@ function createParams({
mapExtent,
minScale,
parts,
layers,
useMapSrs,
operationMode,
}) {
Expand Down Expand Up @@ -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' }),
});
}
Expand Down
14 changes: 14 additions & 0 deletions src/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ cadenzaClient.on('selectObjects:ok', (event) => {
});
```
#### Limit selection to specific map layers
<small>API: [CadenzaClient#selectObjects](./classes/CadenzaClient.html#selectObjects)</small>
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
<small>API: [CadenzaClient#show](./classes/CadenzaClient.html#show)</small>
Expand Down

0 comments on commit d7cd337

Please sign in to comment.