Search code examples
cesiumjs

Cesium - Modify infobox contents


I have n polygons with ids "test-1-1", "test-1-2" .... "test-1-n" which represent a single logical entity. Format of id can be generalized as < entity_name>-< entity_id>-< i>, where i is added to distinguish ids of multiple polygons.

My query here is, I want to display only "test" when any of these polygons is clicked. Currently id of selected polygon is displayed in info-box.

Is there any cesium way to do this? I would not prefer manipulating the strings at runtime.


Solution

  • A Cesium Entity has three fields of interest to the InfoBox (the thing that pops up when an Entity is selected).

    • entity.id - Each entity in a dataSource is required to have a unique id (a GUID will be auto-generated if no ID is supplied at creation). It is an arbitrary string and does not need to be human-friendly.

    • entity.name - This is the human-friendly name of the Entity. It does not need to be unique, you may have as many duplicate names as you like. It is half a line or less of plain text (not HTML).

    • entity.description - This is a sandboxed HTML description of the entity, and can span multiple paragraphs or include tables and other styling.

    The InfoBox will attempt to show entity.name on its title bar by default, and will only fall back to show entity.id in the title bar if name is missing (because name is optional, id is not).

    The body of the InfoBox only appears below the title bar if entity.description is set (otherwise only the bar is shown). The description is rendered with a sandboxed iframe (to offer some resistance to cross-site scripting for apps that display user-supplied entity descriptions).

    I have n polygons with ids "test-1-1", "test-1-2" .... "test-1-n" ...

    For this case, I would keep the existing ids, and set name to be the string you wish to see in the InfoBox popup. Multiple entities can have the same name but not the same id.