Render entities


If you're working with vector data, icons on the map, or loose 3D models instead of a BIM or CAD file, you can render it through the library without having to create a project view.

This data is organized in Nextspace through entity types. This is a level of organization that also defines default styling, and the data schema for the records.

Listing and rendering

Below is how you can list what entity types you've got available to render. We can find the entityTypeId from here.

Typescript
Javascript
import { ENVIRONMENT, EntityType } from "bruce-models";
import * as Cesium from "cesium";
import { MenuItemCreator } from "bruce-cesium";

// Setup global defaults.
ENVIRONMENT.PARAMS = {
    ...ENVIRONMENT.PARAMS,
    accountId: "your-account-id"
};

/**
 * @Warning it is recommended to set a sessionId prior to making this request.
 * The GetList call will not include information on what Entity types were excluded due to permissions.
 */
EntityType.GetList({}).then((data) => {
    // You can use the ".Name" property and allow the user to select what they'd like to render.
    console.log("Entity types", data.entityTypes);
}).catch((e) => {
    console.error(e);
});

// Cannot be null in real use!
// Check earlier docs for initialization of the Cesium viewer.
const viewer: Cesium.Viewer = null;

MenuItemCreator.RenderEntityTypes({
    entityTypeIds: ["some-type-id"],
    viewer: viewer
});

Specific records

The above JSFiddle example shows how to render and remove records dynamically.


If you know one or many specific entity records you'd like to render then you can do so like so:

Typescript
Javascript
import * as Cesium from "cesium";
import { MenuItemCreator } from "bruce-cesium";
import { Bounds, ENVIRONMENT, Entity, MenuItem, ObjectUtils } from "bruce-models";

// Setup global defaults.
ENVIRONMENT.PARAMS = {
    ...ENVIRONMENT.PARAMS,
    accountId: "your-account-id"
};

// Cannot be null in real use!
// Check earlier docs for initialization of the Cesium viewer.
const viewer: Cesium.Viewer = null;

MenuItemCreator.RenderEntities({
    entityIds: ["some-entity-id"],
    viewer: viewer
});

// If you have reasons to avoid touching the Nextspace database you can provide the JSON directly.
// This is an advanced feature which is why you'll have to create the Menu Item definition yourself instead of using a helper.
// Below is an example.

const myFakeEntity: Entity.IEntity = {
    Bruce: {
        // ID must be supplied.
        ID: ObjectUtils.UId(),
        "EntityType.ID": null,
        Location: {
            longitude: 174.764975,
            latitude: -36.843922,
            altitude: 200
        }
    }
};
myFakeEntity.boundaries = Bounds.FromEntity(myFakeEntity);

MenuItemCreator.RenderMenuItems({
    menuItems: [
        {
            // ID must be supplied.
            id: ObjectUtils.UId(),
            Caption: "Preloaded data",
            BruceEntity: {
                // Populate this with your Entity JSON data.
                Entities: [
                    myFakeEntity
                ]
            },
            Type: MenuItem.EType.EntitiesLoaded
        }
    ],
    viewer
});

Custom filter

If you are familiar with the filter syntax, you can also use that to filter the records you'd like to render.

Typescript
Javascript
import { ENVIRONMENT, EntityType } from "bruce-models";
import * as Cesium from "cesium";
import { MenuItemCreator } from "bruce-cesium";

// Setup global defaults.
ENVIRONMENT.PARAMS = {
    ...ENVIRONMENT.PARAMS,
    accountId: "your-account-id"
};

// Cannot be null in real use!
// Check earlier docs for initialization of the Cesium viewer.
const viewer: Cesium.Viewer = null;

MenuItemCreator.RenderEntityFilter({
    attrFilter: {
        entityTypeId: "some-entity-type-id",
        "some-attribute-path": {
            "equals": "some-value"
        } as any // Typing is wrong so we'll override it!
    },
    viewer: viewer
});