devicePixelRatio for camera.pickEllipsoid

1. A concise explanation of the problem you’re experiencing.

I want to determine if a screen point is on the sphere by

var position = viewer.scene.camera.pickEllipsoid(screenPoint, viewer.scene.globe.ellipsoid),

the result is correct when the position not equal undefined,but I get the error result when I change the window.devicePixelRatio in chrome browser.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var canvas = document.createElement(‘canvas’);

canvas.width = viewer.scene.canvas.width;

canvas.height = viewer.scene.canvas.height;

canvas.style.position = ‘absolute’;

canvas.style.top = ‘0px’;

canvas.style.left = ‘0px’;

canvas.style[‘pointer-events’] = ‘none’;

viewer.scene.canvas.parentNode.appendChild(canvas);

var sceneContext = canvas.getContext(‘2d’);

sceneContext.fillStyle = 'rgba(255, 0, 0, ’ + 0.7 + ‘)’;

render();

console.log(window.devicePixelRatio);

function render(){

var i=0;

var j=0;

var screenPoint,position;

for(;i<canvas.height;i++){

for(j=0;j<canvas.width;j++){

screenPoint = new Cesium.Cartesian2(j, i);

position = viewer.scene.camera.pickEllipsoid(screenPoint, viewer.scene.globe.ellipsoid);

if(position){

sceneContext.fillRect(j,i,1,1);

}

}

}

}

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

4. The Cesium version you’re using, your operating system and browser.

Cesium 1.64

chrome browser

window.devicePixelRatio=1.25

You could scale up your canvas context before doing the fillRects: sceneContext.scale(window.devicePixelRatio, window.devicePixelRatio);

https://codesandbox.io/s/frosty-banzai-n7blj

@Jonathan, I don’t know why my answers was deleted,so I can only replay by this way.
I set the scale for canvas and then change the devicePixelRatio in browser , but it’s still get error when devicePixelRatio less then 1.

在 2019年12月17日星期二 UTC+8下午12:02:07,pollux写道:

What do you mean with ‘change the devicePixelRatio in browser’? I don’t see it in the screenshot… (In CodeSandbox you can just save the code and copy the url of the window)

I usually change devicePixelRatio in browser setting,now I change browser scale equal 50%,and the devicePixelRatio become 0.5.
this is the reuslt image.

scale.png

在 2019年12月18日星期三 UTC+8下午4:10:09,Jonathan写道: