CesiumGS / CesiumGS/cesium

Entity position doesn't apply to polygons

Open
#7,180 5 comments 2 reactions 0 assignees View on GitHub
category - doc
Dominant language
JavaScript
Stars
15.8k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

This seems like such a fundamental thing that it must be an intended behavior, but I'm bringing it up here because I feel like it's confusing and I haven't found any issues discussing it.

Let's say you have a polygon entity:

```
var redPolygon = viewer.entities.add({
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,
-115.0, 32.0,
-107.0, 33.0,
-102.0, 31.0,
-102.0, 35.0]),
material : Cesium.Color.RED
}
});
```

Looks great. Let's say you wanted to move it just slightly, so you define a position offset:

```
var redPolygon = viewer.entities.add({
position : new Cesium.Cartesian3(100, 0, 0),
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,
-115.0, 32.0,
-107.0, 33.0,
-102.0, 31.0,
-102.0, 35.0]),
material : Cesium.Color.RED
}
});
```

This has no effect. This is confusing because the docs imply that this is the position of the entity, so the fact that it doesn't change anything is strange. This seems to be the case with other geometry types but not with models.

Of course it's possible to just offset every positions in `polygon.hierarchy`, but this seems like an inconsistent API. Why is `position` a property of the entity if it only applies to `model` ?

The fact that entities don't have a model matrix makes it so that there's no easy way to apply offsets like this. This came up while I was trying to show that [classification entities](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Classification%20Types.html) can be dynamic, and with invert classification you could do a cool thing where you can have a moving mask over your tileset. So it would have been nice to be able to just specify a position and move that rectangle anywhere.

I know this would be kind of a big API change, but at the very least something in the docs should say that entity.position doesn't apply to all geometry types.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the viewer.entities.add examples with polygon.hierarchy and position, then compare the behavior with entities using models. Review the Entity.position and polygon documentation to determine the intended scope. Done means either the requested offset behavior is supported consistently or the limitation and supported alternative are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.