-
-
Notifications
You must be signed in to change notification settings - Fork 773
feat(cesium): native KML, terrain profiles, and control events #2356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
673d9a8
fix(cesium): restore startup and forward control events
giswqs 0bc1d30
feat(cesium): load native KML and sample elevation profiles
giswqs 1ffcf07
fix(cesium): fade KML labels and align Python tool coverage
giswqs 0383c13
fix(cesium): avoid MapLibre placeholder warnings on native layers
giswqs af9e107
Address review feedback
giswqs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
apps/geolibre-desktop/src/components/layout/add-data/sources/KmlSource.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { createCesiumKmlLayer } from "@geolibre/core"; | ||
| import { Button, Input, Label } from "@geolibre/ui"; | ||
| import { useState } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { openLocalDataFileWithFallback } from "../../../../lib/tauri-io"; | ||
| import { errorMessage, layerNameFromPath } from "../helpers"; | ||
| import { AddDataSourceForm, useAddDataSource } from "../shared"; | ||
|
|
||
| /** Preserve the original KML document or KMZ archive in the project. */ | ||
| export function KmlSource({ initialUrl }: { initialUrl?: string }) { | ||
| const { t } = useTranslation(); | ||
| const [defaultName] = useState(() => t("addData.kml.defaultName")); | ||
| const source = useAddDataSource(defaultName); | ||
| const [url, setUrl] = useState(initialUrl ?? ""); | ||
| const [file, setFile] = useState<{ path: string; data: string } | null>(null); | ||
| const chooseFile = async () => { | ||
| source.setError(null); | ||
| try { | ||
| const picked = await openLocalDataFileWithFallback({ | ||
| filters: [{ name: "KML / KMZ", extensions: ["kml", "kmz"] }], | ||
| accept: ".kml,.kmz", | ||
| readText: true, | ||
| binaryExtensions: ["kmz"], | ||
| }); | ||
| if (!picked) return; | ||
| let data = picked.text ?? ""; | ||
| if (picked.data) { | ||
| data = await new Promise<string>((resolve, reject) => { | ||
| const reader = new FileReader(); | ||
| reader.onload = () => resolve(String(reader.result)); | ||
| reader.onerror = () => reject(reader.error); | ||
| reader.readAsDataURL( | ||
| new Blob([picked.data!], { type: "application/vnd.google-earth.kmz" }), | ||
| ); | ||
| }); | ||
| } | ||
| if (!data.trim()) throw new Error(t("addData.kml.errorSource")); | ||
| setFile({ path: picked.path, data }); | ||
| setUrl(""); | ||
| source.setLayerName((current) => | ||
| current.trim() && current !== defaultName | ||
| ? current | ||
| : layerNameFromPath(picked.path, defaultName), | ||
| ); | ||
| } catch (error) { | ||
| source.setError(errorMessage(error, t("addData.shared.addError"))); | ||
| } | ||
| }; | ||
| const submit = source.runSubmit(() => { | ||
| if (!file && !url.trim()) throw new Error(t("addData.kml.errorSource")); | ||
| source.addAndClose( | ||
| createCesiumKmlLayer({ | ||
| name: source.layerName.trim() || defaultName, | ||
| url: url.trim(), | ||
| data: file?.data, | ||
| sourcePath: file?.path, | ||
| }), | ||
| ); | ||
| }); | ||
| return ( | ||
| <AddDataSourceForm | ||
| layerName={source.layerName} | ||
| onLayerNameChange={source.setLayerName} | ||
| beforeLayerId={source.beforeLayerId} | ||
| onBeforeLayerIdChange={source.setBeforeLayerId} | ||
| onSubmit={submit} | ||
| error={source.error} | ||
| submitDisabled={source.isSubmitting} | ||
| > | ||
| <div className="space-y-3"> | ||
| <div className="space-y-1.5"> | ||
| <Label htmlFor="kml-url">{t("addData.kml.url")}</Label> | ||
| <Input | ||
| id="kml-url" | ||
| value={url} | ||
| placeholder="https://example.com/map.kmz" | ||
| onChange={(event) => { | ||
| setUrl(event.target.value); | ||
| setFile(null); | ||
| }} | ||
| /> | ||
| </div> | ||
| <div className="flex items-center gap-2"> | ||
| <Button type="button" variant="outline" onClick={chooseFile}> | ||
| {t("addData.common.chooseFile")} | ||
| </Button> | ||
| <span className="truncate text-xs text-muted-foreground"> | ||
| {file?.path ?? t("addData.common.noFileSelected")} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </AddDataSourceForm> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A locally-picked
.kmzis read fully into memory and base64-encoded into a data URL with no size ceiling. KMZ archives commonly bundle textures/models/overlay imagery and can be tens of MB; base64 inflates that by ~4/3 again before it lands inlayer.source.kmlData, which is written verbatim into the saved.geolibre.json.This is the same failure mode
embedLocalGltf(apps/geolibre-desktop/src/lib/local-gltf.ts) explicitly guards against withMAX_LOCAL_GLTF_BYTES("a future rewrite... hang the tab and produce an unusable project file"). Worth adding an analogous size check here before theFileReader/readAsDataURLconversion.Confidence: medium — real-world impact depends on how large a KMZ users typically pick, but the guard already exists once elsewhere in this codebase for exactly this reason.