android and windows targets
This commit is contained in:
1 parent
c069b8945d
commit
1d974b42a1
58 files changed
+2601
-111
No files matched your search
@@ -1,27 +1,35 @@
|
||||
# cesiumjs
|
||||
|
||||
A Flutter plugin that embeds a [CesiumJS](https://cesium.com/platform/cesiumjs/)
|
||||
3D globe in Flutter **Linux desktop** apps.
|
||||
3D globe in Flutter apps on **Linux, Windows and Android**.
|
||||
|
||||
Flutter on Linux has no platform views, so the globe is a native WebKitGTK
|
||||
web view stacked above the Flutter surface and kept aligned with the
|
||||
`CesiumViewer` widget. WebKitGTK renders WebGL2 on the GPU, so Cesium runs at
|
||||
full frame rate.
|
||||
| Platform | Web engine | Integration | Status |
|
||||
|---|---|---|---|
|
||||
| Linux (X11) | WebKitGTK 4.1 | Native view stacked above the Flutter surface | Tested |
|
||||
| Android 7+ | System WebView (Chromium) | Platform view (`AndroidView`) | Tested (emulator, API 35) |
|
||||
| Windows 10/11 | WebView2 (Edge) | Native child window stacked above the Flutter view | Not yet tested |
|
||||
| Other platforms | — | The widget shows a "not supported" placeholder | — |
|
||||
|
||||
| Platform | Status |
|
||||
|---|---|
|
||||
| Linux (X11) | Supported |
|
||||
| Other platforms | The widget shows a "not supported" placeholder |
|
||||
On Linux and Windows the globe is a native web view kept aligned with the
|
||||
`CesiumViewer` widget's rectangle (Flutter has no platform views there). On
|
||||
Android it is a regular platform view, composed with the rest of the UI.
|
||||
All three engines render WebGL2 on the GPU.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Flutter ≥ 3.32 / Dart ≥ 3.13
|
||||
- WebKitGTK 4.1 development files at build time:
|
||||
- **Linux**: WebKitGTK 4.1 development files at build time:
|
||||
```sh
|
||||
sudo apt install libwebkit2gtk-4.1-dev
|
||||
```
|
||||
End users need the runtime library (`libwebkit2gtk-4.1-0`), which ships with
|
||||
most GTK desktops.
|
||||
- **Android**: `minSdk` 24. The plugin declares the `INTERNET` permission.
|
||||
- **Windows**: the WebView2 SDK is downloaded from NuGet by CMake on the
|
||||
first build (needs network access; SHA-256 pinned in
|
||||
`windows/CMakeLists.txt`). End users need the
|
||||
[WebView2 Runtime](https://developer.microsoft.com/microsoft-edge/webview2/),
|
||||
preinstalled on Windows 11 and up-to-date Windows 10.
|
||||
- Network access: CesiumJS is loaded from the jsDelivr CDN.
|
||||
- Optional: a [Cesium ion token](https://ion.cesium.com/tokens) for Bing
|
||||
aerial imagery and Cesium World Terrain. Without one the globe uses
|
||||
@@ -35,9 +43,10 @@ dependencies:
|
||||
path: ../cesiumjs # or a git: dependency
|
||||
```
|
||||
|
||||
No changes to your Linux runner are needed: on registration the plugin wraps
|
||||
the app's `FlView` in a `GtkOverlay`. If your runner already places the
|
||||
`FlView` inside a `GtkOverlay`, that overlay is used as is.
|
||||
No runner changes are needed on any platform. On Linux the plugin wraps the
|
||||
app's `FlView` in a `GtkOverlay` at registration (an existing `GtkOverlay`
|
||||
parent is reused). On Windows the web views are created as siblings of the
|
||||
Flutter view inside the runner's top-level window.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -80,7 +89,7 @@ class _GlobePageState extends State<GlobePage> {
|
||||
| `onReady` | Called once the Cesium viewer is initialised |
|
||||
| `onMessage` | Every message posted from JavaScript (`CesiumMessage`) |
|
||||
| `onError` | Page load failures, web process crashes and JS errors |
|
||||
| `visible` | Hides the native view without destroying it (keeps camera state) |
|
||||
| `visible` | Hides the web view without destroying it (keeps camera state) |
|
||||
|
||||
### `CesiumController`
|
||||
|
||||
@@ -93,7 +102,7 @@ class _GlobePageState extends State<GlobePage> {
|
||||
| `setTerrain(bool)` | Cesium World Terrain on/off (needs a token) |
|
||||
| `showFps(bool)` | Cesium's FPS overlay |
|
||||
| `runJavaScript(script)` | Runs arbitrary JS; `window.cesiumViewer` is the `Cesium.Viewer`. Returns the result as a string |
|
||||
| `openInspector()` | Opens the WebKit dev tools |
|
||||
| `openInspector()` | Opens the dev tools (WebKit inspector on Linux, Edge DevTools on Windows). On Android, debug builds can be inspected from `chrome://inspect` instead; this call does nothing |
|
||||
| `isReady`, `messages` | Ready flag and broadcast stream of `CesiumMessage`s |
|
||||
|
||||
Controller calls are only valid after `onReady` (or `isReady == true`).
|
||||
@@ -114,35 +123,41 @@ Your own scripts (via `runJavaScript`) can post custom types the same way.
|
||||
|
||||
## Limitations
|
||||
|
||||
- **Flutter widgets cannot be drawn over the globe**: the web view is a
|
||||
native window above the Flutter surface. Put controls around it, or set
|
||||
`visible: false` while a dialog, menu or drawer overlaps it. The view is
|
||||
hidden automatically when another route is pushed on top.
|
||||
- The widget is positioned in window coordinates; don't place it inside a
|
||||
scroll view that clips it.
|
||||
- **Linux and Windows: Flutter widgets cannot be drawn over the globe**: the
|
||||
web view is a native window above the Flutter surface. Put controls around
|
||||
it, or set `visible: false` while a dialog, menu or drawer overlaps it. The
|
||||
view is hidden automatically when another route is pushed on top. (Android
|
||||
has no such restriction.)
|
||||
- Linux and Windows: the widget is positioned in window coordinates; don't
|
||||
place it inside a scroll view that clips it.
|
||||
- One Flutter view per app (the default) is supported.
|
||||
- Tested on X11. Wayland is untested.
|
||||
- Linux: tested on X11. Wayland is untested.
|
||||
- Windows: written against WebView2 SDK 1.0.4314.35 but not yet compiled or
|
||||
run on a Windows machine.
|
||||
|
||||
## Example app
|
||||
|
||||
`example/` is a test app with places, imagery and terrain switches, markers
|
||||
and a camera readout.
|
||||
and a camera readout. On narrow screens (phones) the side panel becomes a drawer.
|
||||
|
||||
```sh
|
||||
cd example
|
||||
cp cesium_ion.example.json cesium_ion.json # then paste your token (optional)
|
||||
flutter run -d linux --dart-define-from-file=cesium_ion.json
|
||||
flutter run -d linux --dart-define-from-file=cesium_ion.json
|
||||
flutter run -d windows --dart-define-from-file=cesium_ion.json
|
||||
flutter run -d <android-device-id> --dart-define-from-file=cesium_ion.json
|
||||
```
|
||||
|
||||
`cesium_ion.json` is git-ignored. A VS Code launch configuration
|
||||
("example (linux)") is provided in `.vscode/launch.json`.
|
||||
`cesium_ion.json` is git-ignored. VS Code launch configurations
|
||||
("example (linux)", "example (android)", "example (windows)") are provided in
|
||||
`.vscode/launch.json`.
|
||||
|
||||
## Development
|
||||
|
||||
```sh
|
||||
flutter analyze
|
||||
flutter test
|
||||
cd example && flutter build linux
|
||||
cd example && flutter build linux # or: flutter build apk / flutter build windows
|
||||
```
|
||||
|
||||
Layout:
|
||||
@@ -150,11 +165,16 @@ Layout:
|
||||
```
|
||||
lib/
|
||||
cesiumjs.dart public API (barrel)
|
||||
src/cesium_viewer.dart CesiumViewer widget, reports its rect to native
|
||||
src/cesium_viewer.dart CesiumViewer widget (AndroidView on Android,
|
||||
reports its rect to native on desktop)
|
||||
src/cesium_controller.dart CesiumController, CesiumMessage, CesiumImagery
|
||||
src/cesium_html.dart HTML page hosting Cesium (CDN version pinned here)
|
||||
src/native_channel.dart `cesiumjs/webview` method channel wrapper
|
||||
linux/
|
||||
cesiumjs_plugin.cc WebKitGTK views in a GtkOverlay over the FlView
|
||||
android/src/main/kotlin/…/CesiumjsPlugin.kt
|
||||
android.webkit.WebView + platform view factory
|
||||
windows/
|
||||
cesiumjs_plugin.cpp WebView2 in child windows over the Flutter view
|
||||
example/ test / demo app
|
||||
```
|
||||
Reference in new issue
Block a user