Polyline material problem

viewer.entities.add({
polyline: {
positions: cartesians,
clampToGround: true,
width: 3,
material: new Cesium.PolylineDashMaterialProperty({
color: Cesium.Color.WHITE,
gapColor: Cesium.Color.BLACK,
phase: 10.0,
}),
},
})


I have provided a screenshot with two lines, both of which are black and white spaced at a ratio of 1:1

  1. The first line is a straight line with no other points in the middle, so its black-white ratio is 1:1.
  2. The second line is a broken line, and there are other points in the middle. The problem is that the ratio of black to white is unbalanced.
    May I ask how to solve this problem, so that the black and white ratio of the second line can be consistent?

It looks like you’re using CesiumJS (not Cesium for Unity), so I’ve moved your post to the CesiumJS forum.

Wow, I’m sorry it’s my fault. Thank you very much for your help

Hi @guanzheyuan,

I believe each line segment’s dashes are treated independently and in screenspace, which may explain the effect your seeing. However, I’m having trouble reproducing this exact issue with arbitrary positions. Could you please provide your full code example?

Thank you for replying to me。
This is the implementation code。
I want to solve this problem by making the skin color of the second line the same ratio as that of the first line。
viewer.entities.add({
polyline: {
positions: cartesians,
clampToGround: true,
width: 3,
material: new Cesium.PolylineDashMaterialProperty({
color: Cesium.Color.WHITE,
gapColor: Cesium.Color.BLACK,
phase: 10.0,
}),
},
})

I’m having trouble reproducing this exact issue with arbitrary positions. Could you please provide your full code example.

This is the implementation code。

A “full code example” usually refers to a Sandcastle, which can be used to quickly look at the issue. In your case, the most important part would be the cartesians that you are using to create the polyline.

But here’s an example with some made-up positions that already shows the effect:

I believe each line segment’s dashes are treated independently and in screenspace, which may explain the effect your seeing.

This indeed seems to be the case: The dashLength is 64, and when carefully moving the view, one can see the effect:

Cesium Polyline Dash

The pattern is applied to each segment, independently. Depending on the structure of the segments, this means that there could basically be a sequence of segments that all have “a length of 63.999 in screen space”, which would cause the whole polyline to be rendered in white (without a pattern).


@guanzheyuan

  1. You used some phase option there - this does not exist for PolylineDashMaterialProperty. Maybe you meant dashLength
  2. You should not open multiple threads to ask the same question - Problem with polyline material

You might actually come pretty close to the desired goal with a CheckerBoardMaterialProperty:

This is not in screen space, however. (The screen space will raise some questions in any case).