hi team!
Just found this annoying bug in the latest v23. I can confirm that v21 doesn't have this problem.
In my very simple test code, I create two polygon GeometryInstances in two slightly different ways: the blue one with extrudedHeight=0 and the red one with extrudedHeight=1. You can see the two polygons located in Tasmania, Australia.
I tested the code in Chrome Version 31.0.1650.57 on windows 7. only clicking on the red polygon can give you an expected "===== hit something" output in the console. The blue polygon whose extrudedHeight is set to 0 just cannot be picked.
I traced to "\Core\PolygonGeometry.js" line 722 : "if (extrude) .... else{...}" and believed the "else" part is the trouble maker.
The ugly workaround could replacing the entire codes within the "else" branch with following:
"
for (i = 0; i < polygons.length; i++) {
geometry = createGeometryFromPositionsExtruded(ellipsoid, polygons[i], granularity, polygonHierarchy[i], perPositionHeight);
if (defined(geometry)) {
topAndBottom = geometry.topAndBottom;
topAndBottom.geometry = PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(topAndBottom.geometry, height, extrudedHeight, ellipsoid, perPositionHeight);
topAndBottom.geometry = computeAttributes(vertexFormat, topAndBottom.geometry, outerPositions, ellipsoid, stRotation, true, false);
geometries.push(topAndBottom);
}}
", it is absolutely ugly and it doubles the geometry size by creating both top and bottom sides.
Could anyone have a look at this issue and pull me out. tons of thanks in advance!
Cheers,
Benny
======== codes start ========
//my pick implementation
mainViewer.screenSpaceEventHandler.setInputAction(function(e) {
var pickedObj = mainScene.pick(e.position);
if(typeof pickedObj === "undefined") {console.log("===== hit nothing");}
else{console.log("===== hit something");}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
//create geometries
var mainViewer = new Cesium.Viewer('cesiumContainer');
var mainScene = mainViewer.scene;
var mainCentralBody = mainViewer.centralBody;
var primitives = mainScene.getPrimitives();
var ellipsoid = mainCentralBody.getEllipsoid();
var gin_cannot_hit = new Cesium.GeometryInstance({
geometry : new Cesium.PolygonGeometry({
polygonHierarchy : {
positions : ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(146.661499, -42.950541),
Cesium.Cartographic.fromDegrees(146.967777, -42.950541),
Cesium.Cartographic.fromDegrees(146.967777, -42.656823),
Cesium.Cartographic.fromDegrees(146.661499, -42.656823)])
},
height: 0,
extrudedHeight: 0
}),
id: "cannothit",
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.BLUE)
}
});
var gin_can_hit = new Cesium.GeometryInstance({
geometry : new Cesium.PolygonGeometry({
polygonHierarchy : {
positions : ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(146.586527, -42.402568),
Cesium.Cartographic.fromDegrees(146.748423, -42.402568),
Cesium.Cartographic.fromDegrees(146.748423, -42.161753),
Cesium.Cartographic.fromDegrees(146.586527, -42.161753)])
},
height: 0,
extrudedHeight: 1
}),
id: "canhit",
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED)
}
});
var wfsLayerPrimitive = new Cesium.Primitive({
geometryInstances : [gin_cannot_hit, gin_can_hit],
appearance : new Cesium.PerInstanceColorAppearance({
translucent : true,
closed : true
})
});
mainScene.getPrimitives().add(wfsLayerPrimitive);
======== codes end ========