Skip to content

Commit

Permalink
improve implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumbobeaty committed Nov 12, 2024
1 parent 2af0170 commit 1fde1c4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default ({ sceneId, onClose, onSubmit }: DataProps) => {
config: {
data: {
url: sourceType === "value" ? encodeUrl : value || undefined,
type: "czml",
type: "czml"
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default ({ sceneId, onClose, onSubmit }: DataProps) => {
config: {
data: {
url: sourceType === "value" ? encodeUrl : value || undefined,
type: "kml",
type: "kml"
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import generateRandomString from "@reearth/beta/utils/generate-random-string";

const isValidUrl = (string: string): boolean => {
const isValidUrl = (string: string): boolean => {
try {
new URL(string);
return true;
} catch (_) {
return false;
}
}
};

export const generateTitle = (url: string, layerName?: string): string => {
if (layerName && layerName.trim() !== "") return layerName;
Expand Down
1 change: 0 additions & 1 deletion web/src/beta/features/Visualizer/Crust/StoryPanel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export const formatDateToSting = (d: number) => {
return date.toISOString();
};


export const formatRangeDateAndTime = (data: string) => {
const lastIdx = data.lastIndexOf(" ");
const date = data.slice(0, lastIdx);
Expand Down
44 changes: 21 additions & 23 deletions web/src/beta/features/Visualizer/shared/hooks/useTimelineBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,20 @@ const calculateMidTime = (startTime: number, stopTime: number) => {
return (startTime + stopTime) / 2;
};

const TRANSITION_SPEED = 100;
const playSpeedOptions = [
{
timeString: "Not set",
seconds: 0
},
{ timeString: "1sec/sec", seconds: 1 },
{ timeString: "0.5min/sec", seconds: 30 },
{ timeString: "1min/sec", seconds: 60 },
{ timeString: "0.1hr/sec", seconds: 360 },
{ timeString: "0.5hr/sec", seconds: 1800 },
{ timeString: "1hr/sec", seconds: 3600 }
];

const TRANSITION_SPEED = 0;

const timeRange = (startTime?: number, stopTime?: number) => {
// To avoid out of range error in Cesium, we need to turn back a hour.
Expand All @@ -42,23 +55,6 @@ const timeRange = (startTime?: number, stopTime?: number) => {
export default (timelineValues?: TimelineValues) => {
const visualizerContext = useVisualizer();

const playSpeedOptions = useMemo(() => {
const speedOpt = [
{
timeString: "Not set",
seconds: 0
},
{ timeString: "1sec/sec", seconds: 1 },
{ timeString: "0.5min/sec", seconds: 30 },
{ timeString: "1min/sec", seconds: 60 },
{ timeString: "0.1hr/sec", seconds: 360 },
{ timeString: "0.5hr/sec", seconds: 1800 },
{ timeString: "1hr/sec", seconds: 3600 }
];

return speedOpt;
}, []);

const [speed, setSpeed] = useState(playSpeedOptions[0].seconds);

const [currentTime, setCurrentTime] = useState(
Expand Down Expand Up @@ -160,18 +156,20 @@ export default (timelineValues?: TimelineValues) => {
);

const handleOnSpeedChange = useCallback(
async (speed: number, committerId?: string) => {
(speed: number, committerId?: string) => {
try {
await onSpeedChange(TRANSITION_SPEED, committerId);
await onSpeedChange(speed, committerId);
setSpeed(speed);
onSpeedChange(TRANSITION_SPEED, committerId);
setTimeout(() => {
onSpeedChange(speed, committerId);
setSpeed(speed);
}, 0);
} catch (error) {
console.error("Error during speed change:", error);
setSpeed(playSpeedOptions[0].seconds);
throw error;
}
},
[onSpeedChange, playSpeedOptions]
[onSpeedChange]
);

useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export default defineConfig({
define: {
"process.env.QTS_DEBUG": "false", // quickjs-emscripten
__APP_VERSION__: JSON.stringify(pkg.version),
__REEARTH_COMMIT_HASH__: JSON.stringify(process.env.GITHUB_SHA || commitHash)
__REEARTH_COMMIT_HASH__: JSON.stringify(
process.env.GITHUB_SHA || commitHash
)
},
mode: NO_MINIFY ? "development" : undefined,
server: {
Expand Down

0 comments on commit 1fde1c4

Please sign in to comment.