import { action } from "storybook/actions"; import { Meta, StoryObj } from "@storybook/react"; import { Color, KmlDataSource as CesiumKmlDataSource } from "cesium"; import { Suspense } from "react"; import { events } from "../core/storybook"; import Viewer from "../Viewer"; import KmlDataSource from "./KmlDataSource"; type Story = StoryObj; export default { title: "KmlDataSource", component: KmlDataSource, } as Meta; const kml = ` Portland -122.681944,45.52,0 Rio de Janeiro -43.196389,-22.908333,0 Istanbul 28.976018,41.01224,0 Reykjavik -21.933333,64.133333,0 Simple Polygon -122.681944,45.52,0 -43.196389,-22.908333,0 28.976018,41.01224,0 -21.933333,64.133333,0 -122.681944,45.52,0 `.trim(); const data = new DOMParser().parseFromString(kml, "text/xml"); const onLoadAction = action("onLoad"); const onLoad = (k: CesiumKmlDataSource) => { // You can process the data source here const p = k.entities.values[4].polygon; if (p) { p.material = Color.RED as any; } onLoadAction(k); }; export const Basic: Story = { args: { show: true }, render: args => ( ), }; // A real URL is required for the suspense prop to take effect. KML/KMZ is fetched // as a Blob. A blob URL keeps this story self-contained (no external network). const dataUrl = URL.createObjectURL( new Blob([kml], { type: "application/vnd.google-earth.kml+xml" }), ); const Loading = () => (
Loading…
); export const SuspenseStory: Story = { name: "Suspense", args: { show: true }, render: args => ( }> ), };