gi-nx / createBlock
ts
function createBlock(block: {
description?: string;
features: (
| PreStackedPoint
| PreStackedLineString
| PreStackedPolygon<Record<string, any>>)[];
id: string;
keyWords?: string[];
name: string;
properties?: Record<string, any>;
}): void;Adds a new block definition to the project
Parameters
| Parameter | Type | Description |
|---|---|---|
block.description? | string | - |
block.features | ( | PreStackedPoint | PreStackedLineString | PreStackedPolygon<Record<string, any>>)[] | - |
block.id | string | - |
block.keyWords? | string[] | - |
block.name | string | - |
block.properties? | Record<string, any> | - |
Returns
void
Throws
If a block with the same id already exists.
Example
ts
await rpc.invoke("createBlock", [{
id: "94d84733617e4c2d91b87a4da6106e8a",
name: "My Cool Block",
features: [
{
type: "Feature",
geometry: {
type: "Polygon",
coordinates: [
[
[151.29106451, -33.80999498],
[151.29106451, -33.8103892],
[151.29160828, -33.8103892],
[151.29160828, -33.80999498],
[151.29106451, -33.80999498]
]
]
},
properties: {
id: "0uQcmfb4wcsEv8BRLjNd4",
usage: "Residential",
levels: 4,
layerId: "default"
},
_projected: [] // projected coordinates (optional)
}
],
keyWords: ["cool", "awesome"],
description: "This is my cool block. It has some awesome features and is very useful for my project."
}]);
const coords = (await rpc.invoke("drawPoint", [{ message: 'Click the map to place "' + block.name + '"' },]));
if (coords) {
const blockInstance = {
type: "Feature",
geometry: { type: "Point", coordinates: coords },
properties: {
blockId: block.id,
},
};
await rpc.invoke("createRawSection", [blockInstance]);
}