Skip to content

Commit

Permalink
CADENZA-37480 Doc, refactor: improving docs and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Isabel Vigil committed Oct 17, 2024
1 parent a8b3035 commit 9b29008
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@ export class CadenzaClient {
});
}

/**
* @typedef {Object} LayerDefinition
* @property {string} name - The layer's name.
* @property {'geojson'} type - The layer's type.
* @property {FeatureCollection} content - The layer's content in geojson format.
*/

/**
* Create a geometry.
*
Expand All @@ -555,7 +562,7 @@ export class CadenzaClient {
* @param {boolean} [options.useMapSrs] - Whether the created geometry should use the map's SRS (otherwise EPSG:4326 will be used)
* @param {OperationMode} [options.operationMode] - The mode in which a workbook should be operated
* @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
* @param {Object[]} [options.additionalLayers] - Layer definitions to be imported and shown in the background, as a basis for the drawing. Layer definition, with name, type and content (a Geojson featureCollection).
* @param {LayerDefinition[]} [options.additionalLayers] - Layer definitions to be imported and shown in the background, as a basis for the drawing.
* @return {Promise<void>} A `Promise` for when the iframe is loaded
* @throws For invalid arguments
* @fires
Expand Down Expand Up @@ -589,11 +596,10 @@ export class CadenzaClient {
useMapSrs,
operationMode,
});
console.log('createGeometry');
await this.#show(resolvePath(backgroundMapView), params, signal);
if (additionalLayers) {
additionalLayers.forEach((layer) =>
this.#postEvent('importLayers', layer),
this.#postEvent('importLayer', layer),
);
}
}
Expand Down Expand Up @@ -659,7 +665,7 @@ export class CadenzaClient {
}
if (additionalLayers) {
additionalLayers.forEach((layer) =>
this.#postEvent('importLayers', layer),
this.#postEvent('importLayer', layer),
);
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,16 @@ 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.
### Create a New Geometry with some reference layers on the background
Create a GeoJSON polygon geometry with a workbook map view and some additional layers in the background.
```javascript
cadenzaClient.createGeometry('<embeddingTargetId>', 'Polygon', {
additionalLayers: [{"name":"freiburg","type":"geojson","content":{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"coordinates":[[[7.965977481550681,47.93787211649922],[7.903787681150362,47.64741821336713],[8.310793134690243,47.70344757260733],[7.965977481550681,47.93787211649922]]],"type":"Polygon"}}]}},{"name":"rosenheim","type":"geojson","content":{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"coordinates":[[[12.061853294216718,47.88265668254172],[12.033589783268809,47.815710545402425],[12.228290018090604,47.80129096292583],[12.061853294216718,47.88265668254172]]],"type":"Polygon"}}]}},{"name":"munich","type":"geojson","content":{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"coordinates":[[[11.595409108141212,48.25674897671507],[11.380447444994104,48.06020449124574],[11.7399528472356,48.03248124662912],[11.595409108141212,48.25674897671507]]],"type":"Polygon"}}]}}]
});
cadenzaClient.on('editGeometry:ok', (event) => {
console.log('Geometry creation was completed', event.detail.geometry);
additionalLayers: [{"name":"layer_name_1","type":"geojson","content": {replace_with_geojson_FeatureCollection}},{"name":"layer_name_2","type":"geojson","content":{replace_with_geojson_FeatureCollection},{"name":"layer_name_3","type":"geojson","content":{replace_with_geojson_FeatureCollection}}]
});
```
Expand Down

0 comments on commit 9b29008

Please sign in to comment.