Skip to content

Commit

Permalink
CADENZA-36520 feat: optionally zoom to provided geometries via cadenz…
Browse files Browse the repository at this point in the history
…a.js api (#35)

* CADENZA-36520 feat: optionally zoom to provided geometries via cadenza.js api

* CADENZA-36520 feat: optionally zoom to provided geometries via cadenza.js api

* CADENZA-36520 refactor: wording

---------

Co-authored-by: deitel <[email protected]>
  • Loading branch information
qulol and deitel authored Aug 14, 2024
1 parent f25cc26 commit f3b6a46
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
19 changes: 15 additions & 4 deletions sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@
parts,
layers,
simplifiedOperationMode,
useMapSrs
useMapSrs,
zoomToGeometry
}) {
return {
disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(','),
Expand All @@ -235,7 +236,8 @@
parts: parts && parts.split(','),
...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
layers: layers ? JSON.parse(layers) : undefined,
useMapSrs: useMapSrs === 'on'
useMapSrs: useMapSrs === 'on',
zoomTarget: zoomToGeometry === 'on' ? { type: 'geometry' } : undefined
};
}

Expand Down Expand Up @@ -442,7 +444,7 @@
</div>
</template>

<template data-action="showMap" data-common="map,showWorkbook,filter,show">
<template data-action="showMap" data-common="zoomTo,map,showWorkbook,filter,show">
<div>
<label for="embeddingTargetId">Embedding target ID of the map view *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
Expand Down Expand Up @@ -477,7 +479,7 @@
</div>
</template>

<template data-action="editGeometry" data-common="map,filter">
<template data-action="editGeometry" data-common="zoomTo,map,filter">
<div>
<label for="embeddingTargetId">Embedding target ID of the map view *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
Expand Down Expand Up @@ -555,6 +557,15 @@
</div>
</template>

<template id="common-zoomTo">
<div>
<label>
<input type="checkbox" name="zoomToGeometry">
Zoom to geometry
</label>
</div>
</template>

<template data-action="downloadData" data-common="data,filter">
<div>
<label for="embeddingTargetId">Embedding target ID *</label>
Expand Down
31 changes: 28 additions & 3 deletions src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ globalThis.cadenza = Object.assign(
*/
/** @typedef {[number,number,number,number]} Extent - An array of numbers representing an extent: [minx, miny, maxx, maxy] */

/**
* @typedef {GeometryZoomTarget} ZoomTarget - An object describing a target to zoom to
*/
/**
* @typedef GeometryZoomTarget - Instructs Cadenza to zoom to a provided {@Link Geometry}
* @property {'geometry'} type The type of the zoom target
*/

/**
* @typedef {'csv' | 'excel' | 'json' | 'pdf' | 'png'} DataType - A data type
*
Expand Down Expand Up @@ -344,6 +352,7 @@ export class CadenzaClient {
* @param {Extent} [options.mapExtent] - A map extent to set
* @param {OperationMode} [options.operationMode] - The mode in which a workbook should be operated
* @param {boolean} [options.useMapSrs] - Whether the geometry and the extent are in the map's SRS (otherwise EPSG:4326 is assumed)
* @param {ZoomTarget} [options.zoomTarget] - A target Cadenza should zoom to
* @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 @@ -364,6 +373,7 @@ export class CadenzaClient {
mapExtent,
operationMode,
useMapSrs,
zoomTarget,
signal,
} = {},
) {
Expand All @@ -386,7 +396,10 @@ export class CadenzaClient {
});
await this.#show(resolvePath(mapView), params, signal);
if (geometry) {
this.#postEvent('setGeometry', { geometry });
this.#postEvent('setGeometry', {
geometry,
zoomToGeometry: zoomTarget?.type === 'geometry',
});
}
}

Expand Down Expand Up @@ -549,6 +562,7 @@ export class CadenzaClient {
* @param {Extent} [options.mapExtent] - A map extent to set
* @param {number} [options.minScale] - The minimum scale where the user should work on. A warning is shown when the map is zoomed out above the threshold.
* @param {boolean} [options.useMapSrs] - Whether the geometry is in the map's SRS (otherwise EPSG:4326 is assumed)
* @param {ZoomTarget} [options.zoomTarget] - A target Cadenza should zoom to
* @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 @@ -561,7 +575,15 @@ export class CadenzaClient {
async editGeometry(
backgroundMapView,
geometry,
{ filter, locationFinder, mapExtent, minScale, useMapSrs, signal } = {},
{
filter,
locationFinder,
mapExtent,
minScale,
useMapSrs,
zoomTarget,
signal,
} = {},
) {
this.#log('CadenzaClient#editGeometry', ...arguments);
assertValidGeometryType(geometry.type);
Expand All @@ -575,7 +597,10 @@ export class CadenzaClient {
});
await this.#show(resolvePath(backgroundMapView), params, signal);
if (geometry) {
this.#postEvent('setGeometry', { geometry });
this.#postEvent('setGeometry', {
geometry,
zoomToGeometry: zoomTarget?.type === 'geometry',
});
}
}

Expand Down

0 comments on commit f3b6a46

Please sign in to comment.