react-globe.gl icon indicating copy to clipboard operation
react-globe.gl copied to clipboard

Getting pixel value of globe radius

Open dendorferpatrick opened this issue 4 years ago • 3 comments

Hi, thanks for the nice package.

I am struggling to get the pixel length of the globe radius for a given width of the module and altitude. Can the radius somewhere be extracted?

dendorferpatrick avatar Jul 12 '21 22:07 dendorferpatrick

@dendorferpatrick thanks for reaching out. I'm not sure I'm following, can you give an example of what you're trying to achieve?

vasturiano avatar Jul 12 '21 22:07 vasturiano

Hi @vasturiano , thx for your response. So far, I understand, that I can set the width of the globe component (globe + background) and the altitude(zoom). Can I now extract the radius of the rendered globe?

dendorferpatrick avatar Jul 15 '21 06:07 dendorferpatrick

@dendorferpatrick thanks for clarifying.

Assuming the globe is not rotated vertically from its initial position, you could just measure the screen coords of the two poles. The y distance will give you the pixel diameter. Divide by 2 to get the radius. Something like:

// assuming myGlobeRef is tied to the globe component
const northPole = myGlobeRef.current.getScreenCoords(90, 0);
const southPole = myGlobeRef.current.getScreenCoords(-90, 0);
const globeRadiusPx = (southPole.y - northPole.y) / 2

vasturiano avatar Jul 15 '21 11:07 vasturiano