Skip to content

Commit 9d8e913

Browse files
committed
v5.0.2
1 parent 00eb240 commit 9d8e913

11 files changed

Lines changed: 72 additions & 45 deletions

File tree

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## [5.0.2](https://github.com/chrisrzhou/react-globe/compare/v5.0.2...v5.0.1) (2020-08-08)
4+
5+
Various bugfixes.
6+
7+
- Fixed bug to allow `cameraDistanceRadiusScale` to affect the initial globe camera distance. This prop has the same exact behavior as `initialCameraDistanceRadiusScale`, which is now reserved as a useful semantic prop alias.
8+
- Fixed bug where the globe's glow was not removed when `options` is updated. This led to creation and attachment of increasing amounts of glow meshes, and also not honoring the `enableGlobeGlow` prop.
9+
- Remove `console.log`
10+
- Increase `cameraMaxDistanceRadiusScale` default value to better support the `initialCameraDistanceRadiusScale` prop.
11+
- Add names to three objects for easier development/debugging.
12+
313
## [5.0.1](https://github.com/chrisrzhou/react-globe/compare/v5.0.1...v5.0.1) (2020-08-08)
414

515
Add `delay` support to exported `tween` utility.

docs/usage/camera.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Use the playground code editor to play around with the respective camera options
1919
<Playground>
2020
<ReactGlobe
2121
options={{
22-
cameraDistanceRadiusScale: 5,
23-
cameraMaxDistanceRadiusScale: 15,
24-
cameraZoomSpeed: 2,
22+
cameraDistanceRadiusScale: 10,
23+
cameraMaxDistanceRadiusScale: 20,
24+
cameraZoomSpeed: 5,
2525
enableCameraZoom: true,
2626
}}
2727
/>
@@ -34,7 +34,7 @@ Use the playground code editor to play around with the respective camera options
3434
<Playground>
3535
<ReactGlobe
3636
options={{
37-
cameraAutoRotateSpeed: 1,
37+
cameraAutoRotateSpeed: 2,
3838
cameraMaxPolarAngle: (Math.PI * 9) / 16,
3939
cameraMinPolarAngle: (Math.PI * 7) / 16,
4040
cameraRotateSpeed: 0.5,

docs/usage/globe.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ You can set the `initialCameraDistanceRadiusScale` prop to control how far the c
7575

7676
<Playground>
7777
<ReactGlobe
78-
initialCameraDistanceRadiusScale={12}
78+
initialCameraDistanceRadiusScale={15}
7979
initialCoordinates={[29.7604, -95.3698]}
8080
/>
8181
</Playground>

lib/camera.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { PerspectiveCamera } from 'three';
22

3-
import { RADIUS } from './enums';
3+
import { CAMERA_FAR_RADIUS_SCALE, RADIUS } from './enums';
44
import { coordinatesToPosition } from './utils';
55

6-
const CAMERA_FAR = RADIUS * 100;
6+
const CAMERA_FAR = RADIUS * CAMERA_FAR_RADIUS_SCALE;
77
const CAMERA_FOV = 45;
88
const CAMERA_NEAR = 1;
99

@@ -12,6 +12,8 @@ export function createCamera(
1212
initialCameraDistanceRadiusScale,
1313
) {
1414
const camera = new PerspectiveCamera();
15+
16+
camera.name = 'camera';
1517
camera.far = CAMERA_FAR;
1618
camera.fov = CAMERA_FOV;
1719
camera.near = CAMERA_NEAR;

lib/component.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect, useRef } from 'react';
22

3+
import { defaultOptions } from './defaults';
34
import Globe from './globe';
45
import { resize } from './utils';
56

@@ -13,7 +14,7 @@ export default function ReactGlobe({
1314
initialCameraDistanceRadiusScale,
1415
initialCoordinates,
1516
markers,
16-
options,
17+
options = defaultOptions,
1718
width = '100%',
1819
onClickMarker,
1920
onDefocus,
@@ -32,10 +33,10 @@ export default function ReactGlobe({
3233
useEffect(() => {
3334
const canvasElement = canvasRef.current;
3435
const tooltipElement = tooltipRef.current;
35-
console.log(globeBackgroundTexture, globeTexture);
3636
const globe = new Globe({
3737
canvasElement,
38-
initialCameraDistanceRadiusScale,
38+
initialCameraDistanceRadiusScale:
39+
initialCameraDistanceRadiusScale || options.cameraDistanceRadiusScale,
3940
initialCoordinates,
4041
textures: {
4142
globeBackgroundTexture,
@@ -55,6 +56,7 @@ export default function ReactGlobe({
5556
globeCloudsTexture,
5657
globeTexture,
5758
initialCameraDistanceRadiusScale,
59+
options.cameraDistanceRadiusScale,
5860
initialCoordinates,
5961
onGetGlobe,
6062
]);

lib/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MarkerTypes } from './enums';
1+
import { BACKGROUND_RADIUS_SCALE, MarkerTypes } from './enums';
22

33
export const defaultCallbacks = {
44
onClickMarker: (_marker, _markerObject, _event) => {},
@@ -26,7 +26,7 @@ export const defaultOptions = {
2626
ambientLightIntensity: 0.8,
2727
cameraAutoRotateSpeed: 0.1,
2828
cameraDistanceRadiusScale: 3,
29-
cameraMaxDistanceRadiusScale: 4,
29+
cameraMaxDistanceRadiusScale: BACKGROUND_RADIUS_SCALE,
3030
cameraMaxPolarAngle: Math.PI,
3131
cameraMinPolarAngle: 0,
3232
cameraRotateSpeed: 0.2,

lib/earth.js

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,31 @@ import {
1313
defaultGlobeCloudsTexture,
1414
defaultGlobeTexture,
1515
} from './defaults';
16-
import { RADIUS } from './enums';
16+
import { BACKGROUND_RADIUS_SCALE, RADIUS } from './enums';
1717

18-
const BACKGROUND_RADIUS_SCALE = 10;
1918
const CLOUDS_RADIUS_OFFSET = 1;
2019
const GLOBE_SEGMENTS = 50;
2120

2221
export function createEarth() {
23-
const clouds = new Mesh();
2422
const globe = new Mesh();
23+
globe.geometry = new SphereGeometry(RADIUS, GLOBE_SEGMENTS, GLOBE_SEGMENTS);
24+
globe.name = 'earth';
25+
26+
const clouds = new Mesh();
27+
clouds.geometry = new SphereGeometry(
28+
RADIUS + CLOUDS_RADIUS_OFFSET,
29+
GLOBE_SEGMENTS,
30+
GLOBE_SEGMENTS,
31+
);
32+
clouds.name = 'clouds';
33+
2534
const background = new Mesh();
35+
background.name = 'background';
36+
background.geometry = new SphereGeometry(
37+
RADIUS * BACKGROUND_RADIUS_SCALE,
38+
GLOBE_SEGMENTS,
39+
GLOBE_SEGMENTS,
40+
);
2641

2742
return {
2843
clouds,
@@ -52,28 +67,24 @@ export function updateEarth(earth, { callbacks, options, textures }) {
5267
} = textures;
5368
let { clouds, globe, glow, background } = earth;
5469

55-
globe.children = [];
70+
if (enableGlobeGlow) {
71+
glow = createGlowMesh(globe.geometry, {
72+
backside: true,
73+
coefficient: globeGlowCoefficient,
74+
color: globeGlowColor,
75+
power: globeGlowPower,
76+
size: RADIUS * globeGlowRadiusScale,
77+
});
78+
glow.name = 'glow';
79+
}
5680

5781
if (globeTexture) {
5882
new TextureLoader().load(
5983
globeTexture,
6084
map => {
61-
globe.geometry = new SphereGeometry(
62-
RADIUS,
63-
GLOBE_SEGMENTS,
64-
GLOBE_SEGMENTS,
65-
);
6685
globe.material = new MeshLambertMaterial({ map });
67-
if (enableGlobeGlow) {
68-
glow = createGlowMesh(globe.geometry, {
69-
backside: true,
70-
coefficient: globeGlowCoefficient,
71-
color: globeGlowColor,
72-
power: globeGlowPower,
73-
size: RADIUS * globeGlowRadiusScale,
74-
});
75-
globe.add(glow);
76-
}
86+
globe.remove(globe.getObjectByName('glow'));
87+
globe.add(glow);
7788
onGlobeTextureLoaded();
7889
},
7990
() => {},
@@ -85,36 +96,28 @@ export function updateEarth(earth, { callbacks, options, textures }) {
8596
new TextureLoader().load(
8697
globeBackgroundTexture,
8798
map => {
88-
background.geometry = new SphereGeometry(
89-
RADIUS * BACKGROUND_RADIUS_SCALE,
90-
GLOBE_SEGMENTS,
91-
GLOBE_SEGMENTS,
92-
);
9399
background.material = new MeshBasicMaterial({ map, side: BackSide });
94100
onGlobeBackgroundTextureLoaded();
95101
},
96102
() => {},
97103
onGlobeBackgroundTextureLoaded,
98104
);
105+
globe.remove(globe.getObjectByName('background'));
99106
globe.add(background);
100107
}
101108

102109
if (globeCloudsTexture) {
103110
new TextureLoader().load(
104111
globeCloudsTexture,
105112
map => {
106-
clouds.geometry = new SphereGeometry(
107-
RADIUS + CLOUDS_RADIUS_OFFSET,
108-
GLOBE_SEGMENTS,
109-
GLOBE_SEGMENTS,
110-
);
111113
clouds.material = new MeshLambertMaterial({ map, transparent: true });
112114
clouds.material.opacity = globeCloudsOpacity;
113115
onGlobeCloudsTextureLoaded();
114116
},
115117
() => {},
116118
onGlobeCloudsTextureLoaded,
117119
);
120+
globe.remove(globe.getObjectByName('clouds'));
118121
globe.add(clouds);
119122
}
120123
}

lib/enums.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export const CAMERA_FAR_RADIUS_SCALE = 1000;
2+
export const BACKGROUND_RADIUS_SCALE = CAMERA_FAR_RADIUS_SCALE / 10;
13
export const RADIUS = 300;
24

35
export const MarkerTypes = {

lib/lights.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export function createLights() {
66
const ambient = new AmbientLight('white');
77
const point = new PointLight('white');
88

9+
ambient.name = 'ambientLight';
10+
point.name = 'pointLight';
11+
912
return {
1013
ambient,
1114
point,

lib/markers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ const MARKER_SEGMENTS = 10;
1818
const MARKER_UNIT_RADIUS_SCALE = 0.01;
1919

2020
export function createMarkerObjects() {
21-
return new Group();
21+
const markerObjects = new Group();
22+
markerObjects.name = 'markers';
23+
24+
return markerObjects;
2225
}
2326

2427
export function updateMarkerObjects(
@@ -155,6 +158,8 @@ function createMarkerObject(marker, options, size) {
155158
markerObject.position.set(...position);
156159
markerObject.lookAt(new Vector3(0, 0, 0));
157160

161+
markerObject.name = marker.id;
162+
158163
return markerObject;
159164
}
160165

0 commit comments

Comments
 (0)