Skip to content

Commit 45fb614

Browse files
authored
Merge pull request #11 from openglobus/og_update
OpenGlobus update
2 parents 7248f3e + 9c4f403 commit 45fb614

File tree

16 files changed

+49
-110
lines changed

16 files changed

+49
-110
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@openglobus/openglobus-react",
3-
"version": "0.1.5",
4-
"description": "Openglobus React Components",
3+
"version": "0.2.0",
4+
"description": "OpenGlobus React Components",
55
"main": "./dist/index.umd.cjs",
66
"private": false,
77
"module": "./dist/index.js",
@@ -28,7 +28,7 @@
2828
"author": "Pavel Sukhodolski",
2929
"license": "MIT",
3030
"dependencies": {
31-
"@openglobus/og": "^0.22.2",
31+
"@openglobus/og": "^0.25.7",
3232
"react": "^19.0.0"
3333
},
3434
"devDependencies": {

src/Globe/Globe.tsx

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import "@openglobus/og/styles";
2+
13
import * as React from "react";
24
import {useEffect, useRef, useState} from "react";
35
import {useGlobeContext} from "./GlobeContext";
4-
import {Globe as GlobusGlobe, GlobusTerrain, utils, XYZ} from "@openglobus/og";
5-
import {EventCallback} from "@openglobus/og/lib/js/Events";
6-
import {IGlobeParams} from "@openglobus/og/lib/js/Globe";
7-
import "@openglobus/og/css/og.css";
6+
import {Globe as GlobusGlobe, GlobusRgbTerrain, OpenStreetMap, Bing} from "@openglobus/og";
7+
import {EventCallback} from "@openglobus/og/lib/Events";
8+
import {IGlobeParams} from "@openglobus/og/lib/Globe";
89
import {Layer, Vector} from "@/layer";
910

1011
type LayerChildren = React.ReactElement<{ type: typeof Layer | typeof Vector }>;
@@ -35,12 +36,7 @@ const Globe: React.FC<GlobusProps> = ({children, onDraw, ...rest}) => {
3536
}, [rest.sunActive]);
3637
useEffect(() => {
3738
if (!gRef.current) {
38-
const osm = new XYZ('OpenStreetMap', {
39-
isBaseLayer: true,
40-
url: '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
41-
visibility: true,
42-
attribution: 'Data @ OpenStreetMap contributors, ODbL',
43-
});
39+
const osm = new OpenStreetMap("OSM");
4440

4541
function toQuadKey(x: number, y: number, z: number): string {
4642
var index = '';
@@ -54,29 +50,12 @@ const Globe: React.FC<GlobusProps> = ({children, onDraw, ...rest}) => {
5450
return index;
5551
}
5652

57-
const sat = new XYZ('sat', {
58-
isBaseLayer: true,
59-
subdomains: ['t0', 't1', 't2', 't3'],
60-
url: 'https://ecn.{s}.tiles.virtualearth.net/tiles/a{quad}.jpeg?n=z&g=7146',
61-
visibility: true,
62-
attribution: `<a href="http://www.bing.com" target="_blank"><img title="Bing Imagery" src="https://sandcastle.cesium.com/CesiumUnminified/Assets/Images/bing_maps_credit.png" alt="Bing"></a> © 2021 Microsoft Corporation`,
63-
maxNativeZoom: 19,
64-
defaultTextures: [{color: '#001522'}, {color: '#E4E6F3'}],
65-
shininess: 18,
66-
specular: [0.00063, 0.00055, 0.00032],
67-
ambient: 'rgb(100,100,140)',
68-
diffuse: 'rgb(450,450,450)',
69-
nightTextureCoefficient: 2.7,
70-
urlRewrite: function (s: any, u: string) {
71-
// @ts-ignore
72-
return utils.stringTemplate(u, {s: this._getSubdomain(), quad: toQuadKey(s.tileX, s.tileY, s.tileZoom)});
73-
},
74-
});
53+
const sat = new Bing("Microsoft Bing");
7554

7655
gRef.current = new GlobusGlobe({
7756
target: targetRef.current!,
7857
name: 'Earth',
79-
terrain: new GlobusTerrain(),
58+
terrain: new GlobusRgbTerrain(),
8059
layers: [osm, sat],
8160
autoActivate: true,
8261
atmosphereEnabled: true,

src/camera/PlanetCamera/PlanetCamera.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import {useEffect} from "react";
33
import {LonLat} from "@openglobus/og";
4-
import {IPlanetCameraParams} from "@openglobus/og/lib/js/camera/PlanetCamera";
4+
import {IPlanetCameraParams} from "@openglobus/og/lib/camera/PlanetCamera";
55
import {useGlobeContext} from "@/Globe";
66

77
export interface PlanetCameraParams extends IPlanetCameraParams {

src/entity/Billboard/Billboard.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as React from "react";
22
import {useEffect, useRef} from "react";
3-
import {Billboard as GlobusBillboard, Vec2, Vec3} from "@openglobus/og";
4-
import {IBillboardParams} from "@openglobus/og/lib/js/entity/Billboard";
5-
import {RADIANS} from "@openglobus/og/lib/js/math";
3+
import {Billboard as GlobusBillboard, Vec2, Vec3, IBillboardParams} from "@openglobus/og";
64

75
export interface BillboardParams extends IBillboardParams {
86
name?: string;
@@ -37,7 +35,7 @@ const Billboard: React.FC<BillboardParams> = ({
3735

3836
useEffect(() => {
3937
if (typeof rotation === 'number' && billboardRef.current) {
40-
billboardRef.current?.setRotation(rotation * RADIANS)
38+
billboardRef.current?.setRotation(rotation * Math.PI / 180)
4139
}
4240
}, [rotation]);
4341

@@ -74,7 +72,7 @@ const Billboard: React.FC<BillboardParams> = ({
7472
src,
7573
offset,
7674
visibility,
77-
rotation: rotation ? rotation * RADIANS : 0
75+
rotation: rotation ? rotation * Math.PI / 180 : 0
7876
});
7977
if (billboardRef.current && _addBillboard) {
8078
_addBillboard(billboardRef.current);

src/entity/Entity/Entity.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
Polyline as GlobusPolyline,
1212
Strip as GlobusStrip
1313
} from '@openglobus/og';
14-
import type {IEntityParams} from "@openglobus/og/lib/js/entity/Entity";
14+
import type {IEntityParams} from "@openglobus/og/lib/entity/Entity";
1515
import {VectorContext} from "@/layer/Vector/Vector";
16-
import {EventCallback} from "@openglobus/og/lib/js/Events";
17-
import {NumberArray3} from "@openglobus/og/lib/js/math/Vec3";
16+
import {EventCallback} from "@openglobus/og/lib/Events";
17+
import {NumberArray3} from "@openglobus/og/lib/math/Vec3";
1818
import {Billboard, Geometry, GeoObject, Label, Polyline, Strip} from "@/entity";
1919

2020
type EntityChildElement = React.ReactElement<

src/entity/GeoObject/GeoObject.stories.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ type Story = StoryObj<typeof meta>;
1717
export const Default: Story = {
1818
args: {
1919
visibility: true,
20-
yaw: 0,
21-
roll: 0,
22-
pitch: 0,
2320
scale: 10,
2421
tag: 'none',
2522
color: 'red',
2623
objSrc: 'https://raw.githubusercontent.com/pavletto/og_resources/main/geo_object/penguin.obj',
27-
textureSrc: 'https://raw.githubusercontent.com/pavletto/og_resources/main/geo_object/penguin.png',
2824
},
2925
render: (args: GeoObjectParams) => <GlobeContextProvider>
3026
<Globe>
@@ -42,7 +38,6 @@ export const Default: Story = {
4238
export const Untextured: Story = {
4339
args: {
4440
...Default.args,
45-
textureSrc: undefined
4641
},
4742
render: (args: GeoObjectParams) => <GlobeContextProvider>
4843
<Globe>
@@ -61,7 +56,6 @@ export const Untextured: Story = {
6156
export const Barrel: Story = {
6257
args: {
6358
...Default.args,
64-
textureSrc: 'https://raw.githubusercontent.com/PrincessGod/objTo3d-tiles/master/bin/barrel/barrel.png',
6559
objSrc: 'https://raw.githubusercontent.com/PrincessGod/objTo3d-tiles/master/bin/barrel/barrel.obj'
6660
},
6761
render: (args: GeoObjectParams) => <GlobeContextProvider>

src/entity/GeoObject/GeoObject.tsx

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import * as React from "react";
22
import {useEffect, useRef} from "react";
33
import {GeoObject as GlobusGeoObject, Vec4} from "@openglobus/og";
4-
import {IGeoObjectParams} from "@openglobus/og/lib/js/entity/GeoObject";
5-
import {RADIANS} from "@openglobus/og/lib/js/math";
4+
import {IGeoObjectParams} from "@openglobus/og/lib/entity/GeoObject";
65

76
export interface GeoObjectParams extends IGeoObjectParams {
87
readonly _addGeoObject?: (geoObject: GlobusGeoObject) => void,
98
readonly _removeGeoObject?: (geoObject: GlobusGeoObject) => void,
109
}
1110

1211
const GeoObject: React.FC<GeoObjectParams> = ({
13-
yaw,
14-
roll,
15-
pitch,
1612
color,
1713
objSrc,
18-
textureSrc,
1914
scale,
2015
visibility,
2116
_addGeoObject,
@@ -24,24 +19,6 @@ const GeoObject: React.FC<GeoObjectParams> = ({
2419
}) => {
2520
const geoObjectRef = useRef<GlobusGeoObject | null>(null);
2621

27-
useEffect(() => {
28-
if (typeof yaw === 'number' && geoObjectRef.current) {
29-
geoObjectRef.current?.setYaw(yaw * RADIANS)
30-
}
31-
}, [yaw]);
32-
33-
useEffect(() => {
34-
if (typeof roll === 'number' && geoObjectRef.current) {
35-
geoObjectRef.current?.setRoll(roll * RADIANS)
36-
}
37-
}, [roll]);
38-
39-
useEffect(() => {
40-
if (typeof pitch === 'number' && geoObjectRef.current) {
41-
geoObjectRef.current?.setPitch(pitch * RADIANS)
42-
}
43-
}, [pitch]);
44-
4522
useEffect(() => {
4623
if (scale && geoObjectRef.current) {
4724
geoObjectRef.current?.setScale(scale as number)
@@ -66,13 +43,6 @@ const GeoObject: React.FC<GeoObjectParams> = ({
6643
}
6744
}, [objSrc]);
6845

69-
70-
useEffect(() => {
71-
if (textureSrc && geoObjectRef.current) {
72-
geoObjectRef.current?.setTextureSrc(textureSrc)
73-
}
74-
}, [textureSrc]);
75-
7646
useEffect(() => {
7747
if (typeof visibility === 'boolean' && geoObjectRef.current) {
7848
geoObjectRef.current?.setVisibility(visibility)
@@ -81,7 +51,7 @@ const GeoObject: React.FC<GeoObjectParams> = ({
8151

8252
useEffect(() => {
8353
geoObjectRef.current = new GlobusGeoObject({
84-
yaw, roll, pitch, color, objSrc, textureSrc, scale, visibility, ...params
54+
color, objSrc, scale, visibility, ...params
8555
});
8656
if (geoObjectRef.current && _addGeoObject) {
8757
_addGeoObject(geoObjectRef.current);

src/entity/Geometry/Geometry.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {useEffect, useRef} from "react";
2-
import {Geometry as GlobusGeometry, Vec4} from "@openglobus/og";
3-
import {GeometryTypeEnum, GeometryTypeToCoordinates, IGeometryParams} from "@openglobus/og/lib/js/entity/Geometry";
4-
import {htmlColorToRgba} from "@openglobus/og/lib/js/utils/shared";
2+
import {Geometry as GlobusGeometry, Vec4, GeometryTypeEnum, GeometryTypeToCoordinates, IGeometryParams} from "@openglobus/og";
3+
import {utils} from "@openglobus/og";
54

65

76
export interface GeometryParamsExtended<T extends keyof typeof GeometryTypeEnum = keyof typeof GeometryTypeEnum> extends Omit<IGeometryParams, 'style'> {
@@ -42,8 +41,7 @@ const Geometry = <T extends keyof typeof GeometryTypeEnum>(params: GeometryParam
4241
strokeWidth,
4342
type, coordinates,
4443
_addGeometry,
45-
_removeGeometry,
46-
...geometryParams
44+
_removeGeometry
4745
} = params;
4846

4947
const geometryRef = useRef<GlobusGeometry | null>(null);
@@ -65,7 +63,7 @@ const Geometry = <T extends keyof typeof GeometryTypeEnum>(params: GeometryParam
6563
} else if (Array.isArray(fillColor)) {
6664
geometryRef.current.setFillColor(...fillColor);
6765
} else if (typeof fillColor === 'string' && geometryRef.current) {
68-
const fillColorVec = htmlColorToRgba(fillColor);
66+
const fillColorVec = utils.htmlColorToRgba(fillColor);
6967
geometryRef.current.setFillColor4v(fillColorVec);
7068
}
7169
}
@@ -78,7 +76,7 @@ const Geometry = <T extends keyof typeof GeometryTypeEnum>(params: GeometryParam
7876
} else if (Array.isArray(lineColor)) {
7977
geometryRef.current.setLineColor(...lineColor);
8078
} else if (typeof lineColor === 'string' && geometryRef.current) {
81-
const lineColorVec = htmlColorToRgba(lineColor);
79+
const lineColorVec = utils.htmlColorToRgba(lineColor);
8280
geometryRef.current.setLineColor4v(lineColorVec);
8381
}
8482
}
@@ -91,7 +89,7 @@ const Geometry = <T extends keyof typeof GeometryTypeEnum>(params: GeometryParam
9189
} else if (Array.isArray(strokeColor)) {
9290
geometryRef.current.setStrokeColor(...strokeColor);
9391
} else if (typeof strokeColor === 'string' && geometryRef.current) {
94-
const strokeColorVec = htmlColorToRgba(strokeColor);
92+
const strokeColorVec = utils.htmlColorToRgba(strokeColor);
9593
geometryRef.current.setStrokeColor4v(strokeColorVec);
9694
}
9795
}

src/entity/Label/Label.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as React from "react";
22
import {useEffect, useRef} from "react";
3-
import {Label as GlobusLabel, Vec2, Vec3} from "@openglobus/og";
4-
import {ILabelParams} from "@openglobus/og/lib/js/entity/Label";
5-
import {RADIANS} from "@openglobus/og/lib/js/math";
3+
import {Label as GlobusLabel, Vec2, Vec3, ILabelParams} from "@openglobus/og";
64

75
export interface LabelParams extends ILabelParams {
86
name?: string;
@@ -38,7 +36,7 @@ const Label: React.FC<LabelParams> = ({
3836

3937
useEffect(() => {
4038
if (typeof rotation === 'number' && labelRef.current) {
41-
labelRef.current?.setRotation(rotation * RADIANS)
39+
labelRef.current?.setRotation(rotation * Math.PI / 180)
4240
}
4341
}, [rotation]);
4442

@@ -122,7 +120,7 @@ const Label: React.FC<LabelParams> = ({
122120
opacity,
123121
offset,
124122
visibility,
125-
rotation: rotation ? rotation * RADIANS : 0
123+
rotation: rotation ? rotation * Math.PI / 180 : 0
126124
});
127125
if (labelRef.current && _addLabel) {
128126
_addLabel(labelRef.current);

0 commit comments

Comments
 (0)