Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geojson pick confusion when set perPositionHeight #10091

Open
znxd-wh opened this issue Feb 11, 2022 · 8 comments
Open

geojson pick confusion when set perPositionHeight #10091

znxd-wh opened this issue Feb 11, 2022 · 8 comments

Comments

@znxd-wh
Copy link

znxd-wh commented Feb 11, 2022

hello

I use GeoJsonDataSource to load geojson data, when i set the perPositionHeight=false,single click on the map to pickup a geojson feathure, it may return a wrong result.

image

when i set entity.polygon.perPositionHeight = false, it will happen,but if set entity.polygon.perPositionHeight = true, it works fine. this happens with cesium version 1.88, when change cesium version to 1.74,it works fine as well.

following is the code:

var promise = Cesium.GeoJsonDataSource.load('data/wenmiao.json', { clampToGround: true });
      promise.then(function (dataSource) {
        // viewer.dataSources.add(dataSource);
        var entities = dataSource.entities.values;
        for (var i = 0; i < entities.length; i++) {
          var entity = entities[i];
          entity.polygon.perPositionHeight = false;
          entity.polygon.classificationType = Cesium.ClassificationType.BOTH;
          entity.heightReference = Cesium.HeightReference.CLAMP_TO_GROUND
          entity.polygon.material= Cesium.Color.BLUE;
          viewer.entities.add(entity)
        }
      });
      viewer.flyTo(promise);
      var scene = viewer.scene;

      var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
      handler.setInputAction(function (movement) {
        var pick = viewer.scene.pick(movement.position);
        if(pick){
          selectedEntity = pick.id;
          pick.id.polygon.material = new Cesium.Color(255, 0, 0, 1)
        }
      }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
@ggetz
Copy link
Contributor

ggetz commented Feb 14, 2022

@ebogo1 Could you triage this issue by reproducing and seeing if you can find the probable cause?

@ebogo1
Copy link
Contributor

ebogo1 commented Feb 14, 2022

@znxd-wh I wasn't able to reproduce this with the GeoJson examples we have in our Sandcastle gallery. Are you able to share the data you were testing this with? Thanks!

@znxd-wh
Copy link
Author

znxd-wh commented Feb 15, 2022

@ebogo1 attach is my code with data, unzip it and publish with a web container such tomcat,iis,nginx. visit the index.html page,you will see the problem. click a feather several times, different feature will be picked.
image

cesium 1.88 does not work,but 1.74 works fine. but if i don't set entity.polygon.perPositionHeight = false,both version work well,when i set entity.polygon.perPositionHeight = false,only version 1.74 works.

look forward to your response and thanks

geojson.zip

@ebogo1
Copy link
Contributor

ebogo1 commented Feb 16, 2022

This looks like a regression in 1.80 from #9399. I think something is going wrong with the first logDepthOrDepth != 0.0 check added in the ShadowVolumeAppearance frag shader -

#ifdef CULL_FRAGMENTS
// When classifying translucent geometry, logDepthOrDepth == 0.0
// indicates a region that should not be classified, possibly due to there
// being opaque pixels there in another buffer.
// Check for logDepthOrDepth != 0.0 to make sure this should be classified.
if (0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0 || logDepthOrDepth != 0.0) {
gl_FragColor.a = 1.0; // 0.0 alpha leads to discard from ShaderSource.createPickFragmentShaderSource
czm_writeDepthClamp();
}

@znxd-wh
Copy link
Author

znxd-wh commented Feb 17, 2022

hi @ebogo1

did you mean this bug has appeared since version 1.80?so do you have any idea to fix it? or i do not set the perPositionHeight parameter, but can you please tell me a method to let geojson polygon clamp on 3dtiles model?like the below effect.
image

@ebogo1
Copy link
Contributor

ebogo1 commented Feb 21, 2022

@znxd-wh Yeah, this bug was introduced in 1.80. I edited my first comment with more details. The shader affects all classification types so it's tricky to work out a quick fix. If we have a chance to revisit the issue we'll post updates here.

@ShenWeiQun
Copy link
Contributor

I've also had this issue recently
For the time being, you can consider the following ways to solve the problem

handler.setInputAction(function (movement) {
-  var pick = viewer.scene.pick(movement.position);
-  if (pick) {
-    selectedEntity = pick.id;
-    pick.id.polygon.material = new Cesium.Color(255, 0, 0, 1)
-  }
+  const pickedObjects = scene.drillPick(movement.position);
+  if (pickedObjects) {
+    var pick = pickedObjects.pop();
+    selectedEntity = pick.id;
+    pick.id.polygon.material = new Cesium.Color(255, 0, 0, 1)
+  }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

@JiaoJianing
Copy link
Contributor

I've also met this issue and this is the live demo.
When setting clampToGround to false everything seems well.It does seems to be the shadowVolume issue.
I just provide my geojson data and demo for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants