Skip to content

Commit 96d5251

Browse files
authored
Merge pull request #18 from reearth/docs/plugin-development
docs: add docs for plugin development
2 parents 06c5318 + 5e8d900 commit 96d5251

22 files changed

+410
-117
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
22
title: Getting Started
33
description: Getting Started
4+
sidebar:
5+
badge:
6+
text: WIP
7+
variant: default
48
---
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
22
title: Contributing
33
description: Contributing
4+
sidebar:
5+
badge:
6+
text: WIP
7+
variant: default
48
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Authentication
3+
description: Authentication
4+
sidebar:
5+
order: 5
6+
badge:
7+
text: WIP
8+
variant: default
9+
---

src/content/docs/core-concepts/layer-system.mdx

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ title: Layer System
33
description: Layer System
44
sidebar:
55
order: 2
6+
badge:
7+
text: WIP
8+
variant: default
69
---

src/content/docs/core-concepts/plugin-system.mdx

+102
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,105 @@ description: Plugin System
44
sidebar:
55
order: 3
66
---
7+
8+
Re:Earth Visualizer features a robust plugin system, enabling users to develop custom UI components and logics.
9+
10+
A plugin can include one or more `Extension`, which are collections of UI components and logic. Extensions come in three types:
11+
12+
- **Widget:** This type of extension can be placed in the main view of the Visualizer. Users can arrange its position using the Widget Align System.
13+
14+
- **InfoboxBlock:** This extension can be added to the infobox of a layer and is displayed when a feature of that layer is selected. It is typically used to enhance the presentation of additional information about the feature.
15+
16+
- **StoryBlock:** This extension can be added to a story page to enrich the content, such as by including custom charts or other visual elements to provide more detailed information about the story.
17+
18+
## How plugins work
19+
20+
It is never easy to make plug-ins work on a web browser, and there are various technical issues that need to be resolved before they can be developed. Therefore, plug-in developers need to accept the unique constraints that are different from the usual HTML and JavaScript implementations before developing plug-ins.
21+
22+
The plugin can be implemented in JavaScript, but it is divided into two parts: the part that works on WebAssembly and the part that works on iframe.
23+
24+
Both of them can safely execute third-party JavaScript code, but they have their advantages and disadvantages, so Re:Earth Visualizer uses a hybrid method.
25+
26+
WebAssembly can run code synchronously and fast, and can access Re:Earth Visualizer data, but it cannot use the APIs and UIs supported by web browsers. iframe can use all the APIs supported by web browsers, and can display UIs in HTML. But it cannot access Re:Earth Visualizer data directly and runs asynchronously.
27+
28+
The WebAssembly part and the iframe can exchange messages through [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). This allows you to send only the necessary data from Re:Earth Visualizer to the iframe, rewrite HTML in the iframe, and retrieve server information. You can also pass the retrieved information to the WebAssembly part.
29+
30+
### WebAssembly side
31+
32+
This is the entry point that is executed when the plugin is first loaded, and runs synchronously in the same thread as Re:Earth Visualizer.
33+
34+
#### Capabilities:
35+
36+
- **Execute JavaScript code:** JavaScript execution is powered by QuickJS, ensuring compatibility with `ECMAScript 2020`, independent of browser support.
37+
- **Call Re:Earth Visualizer plugin API:**
38+
- Access the current scene data.
39+
- Partially modify the Re:Earth Visualizer scene.
40+
- Subscribe to events.
41+
- Facilitate data exchange between the plugin and the IFrame.
42+
43+
#### Limitations:
44+
45+
- **UI Rendering:** Directly rendering HTML or other UI elements is not supported and must be handled on the IFrame side.
46+
- **Browser APIs:** Most browser-provided APIs are unavailable, except for a few, such as `console.log`.
47+
- **External Communication:** HTTP communication with external servers is not permitted.
48+
49+
### IFrame side
50+
51+
#### Capabilities
52+
53+
- **HTML Rendering:** Render HTML as you would on a standard web page.
54+
- **Browser APIs:** Utilize any API provided by web browsers, including window and DOM APIs.
55+
- **External Server Communication:** Send HTTP requests via fetch or XHRRequest to external servers, provided the server's response includes a properly configured CORS header (Access-Control-Allow-Origin: \*).
56+
- **Interprocess Communication:** Exchange messages with the WebAssembly side using `parent.postMessage` and `window.addEventListener("message", () => {})`.
57+
58+
#### Limitations
59+
60+
The following actions are restricted:
61+
62+
- **Restricted Server Communication:** Communication with external servers that do not include the Access-Control-Allow-Origin: \* header is prohibited due to the sandboxed nature of the iframe (its origin is set to null).
63+
- **Direct Back-End Communication:** Direct interaction with the Re:Earth Visualizer back-end is not allowed.
64+
- **Re:Earth Visualizer Data Access:** You cannot directly access or modify Re:Earth Visualizer data. This requires communication via postMessage with the WebAssembly side.
65+
- **Local Storage:** Access to local storage is unavailable because the iframe is sandboxed with a null origin. (However, Re:Earth Plugin API provides a storage API to store data)
66+
67+
## You mean?
68+
69+
| | | |
70+
| ---------------------------------------------------------------- | ---------------- | ----------- |
71+
| Name | WebAssembly side | IFrame side |
72+
| Sandboxed |||
73+
| Entrypoint (first executed) |||
74+
| Access to Re:Earth Visualizer plugin API |||
75+
| Render HTML |||
76+
| Use web API (DOM API, Canvas API, AJAX... without local storage) |||
77+
| Communicate with the other side via "postMessage" |||
78+
79+
## Limitations
80+
81+
**postMessage Limitations:** Objects that cannot be serialized as JSON, such as ArrayBuffer and Blob, cannot be sent. To send binaries, encode them with base64 or similar methods. Expanding supported object types is under consideration for future updates.
82+
83+
**Plugin Size Restriction:** Installable plugins are limited to zip files of 10MB or less.
84+
85+
**Static Asset Handling:** Non-JavaScript files (e.g., images) cannot be packaged as plugins. Static assets like HTML, images, or CSS must either be embedded in JavaScript as strings or hosted on a publicly accessible server and referenced via URLs.
86+
87+
## What's next?
88+
89+
import { LinkCard } from "@astrojs/starlight/components";
90+
91+
Explore the Re:Earth Visualizer Plugin Playground to gain hands-on experience in developing plugins.
92+
93+
<LinkCard
94+
title="Plugin Playground"
95+
href="/plugin-development/plugin-playground/"
96+
/>
97+
98+
Learn more about plugin development with our detailed guides and comprehensive API references.
99+
100+
<LinkCard
101+
title="Plugin Development Guide"
102+
href="/plugin-development/about-plugin/"
103+
/>
104+
<LinkCard title="Plugin API Reference" href="/plugin-api/overview" />
105+
106+
Learn more about the Re:Earth Visualizer Marketplace.
107+
108+
<LinkCard title="Marketplace" href="/plugin-development/marketplace/" />

src/content/docs/core-concepts/system-architecture.mdx

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ title: System Architecture
33
description: System Architecture
44
sidebar:
55
order: 1
6+
badge:
7+
text: WIP
8+
variant: default
69
---

src/content/docs/core-concepts/widget-align-system.mdx

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ title: Widget Align System
33
description: Widget Align System
44
sidebar:
55
order: 4
6+
badge:
7+
text: WIP
8+
variant: default
69
---
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
22
title: Getting Started
33
description: Getting Started
4+
sidebar:
5+
badge:
6+
text: WIP
7+
variant: default
48
---
+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
22
title: Re:Earth Visualizer
33
description: Re:Earth Visualizer is a 3D geospatial data visualization tool that allows you to create and share interactive 3D maps.
4+
sidebar:
5+
badge:
6+
text: WIP
7+
variant: default
48
---

src/content/docs/introduction/quick-start.mdx

+70-50
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,99 @@ description: Quick Start
55

66
This guide provides a step-by-step tutorial on how to start Re:Earth Visualizer locally
77

8-
## Before You Begin
8+
import { Steps } from "@astrojs/starlight/components";
99

10-
Before starting the development process, ensure you have the following prerequisites:
10+
### Before Start
1111

12-
- **Go**: Download and install Go from the official site: <a href="https://golang.org/dl/" target="_blank"> Download Go</a>.
12+
<Steps>
1313

14-
- **Docker**: Install Docker by following these instructions: <a href="https://docs.docker.com/engine/install/" target="_blank"> Install Docker</a>.
14+
1. Inorder to run Re:Earth Visualizer server and database, ensure you have the following prerequisites:
1515

16-
## Prepare the Code
16+
- **Go**: Download and install Go from the official site: <a href="https://golang.org/dl/" target="_blank"> Download Go</a>.
17+
- **Docker**: Install Docker by following these instructions: <a href="https://docs.docker.com/engine/install/" target="_blank"> Install Docker</a>.
1718

18-
Open your terminal (or PowerShell if you're on Windows) and navigate to your desired working directory, for example, your desktop:
19+
2. Prepare the code:
1920

20-
```bash
21-
cd Desktop
22-
git clone https://github.com/reearth/reearth-visualizer
23-
```
21+
Open your terminal (or PowerShell if you're on Windows) and navigate to your desired working directory.
2422

25-
## Setup Server and Database
23+
```bash
24+
cd your-working-directory
25+
git clone https://github.com/reearth/reearth-visualizer
26+
```
27+
28+
</Steps>
29+
30+
### Setup Server and Database
2631

2732
Make sure Docker is properly installed and running on your machine.
2833

29-
From your cloned directory, navigate to the server folder and set up the database:
34+
<Steps>
35+
36+
1. From your cloned directory, navigate to the server folder and set up the database:
37+
38+
```bash
39+
cd server
40+
make run-db
41+
```
42+
43+
2. Create and configure the `.env` file in the server directory to use mock authentication.
44+
45+
```bash
46+
touch .env
47+
echo "REEARTH_MOCKAUTH=true" >> .env
48+
```
49+
50+
3. Start the backend server.
51+
52+
```bash
53+
make run-app
54+
```
3055

31-
```bash
32-
cd server
33-
make run-db
34-
```
56+
4. Register a new mockuser.
3557

36-
Create and configure the `.env` file in the server directory to use mock authentication.
58+
```bash
59+
make mockuser
60+
```
3761

38-
```bash
39-
touch .env
40-
echo "REEARTH_MOCKAUTH=true" >> .env
41-
```
62+
:::note
63+
Re:Earth Visualizer supports multiple authentication providers. For more information, refer to the [Authentication](/docs/core-concepts/authentication) documentation.
64+
:::
4265

43-
Start the backend server.
66+
</Steps>
4467

45-
```bash
46-
make run-app
47-
```
68+
### Setup Web
4869

49-
Register a new mockuser.
70+
<Steps>
5071

51-
```bash
52-
make mockuser
53-
```
72+
1. Navigate to the web directory of your visualizer project and set up local .env file.
5473

55-
## Setup Web
74+
```bash
75+
cd web
76+
touch .env
77+
```
5678

57-
Navigate to the web directory of your visualizer project and set up local .env file.
79+
2. Add the following environment variables to the `.env` file:
5880

59-
```bash
60-
cd web
61-
touch .env
62-
```
81+
```plaintext
82+
// .env
83+
REEARTH_WEB_API=http://localhost:8080/api
84+
REEARTH_WEB_PLUGINS=http://localhost:8080/plugins
85+
REEARTH_WEB_CESIUM_ION_ACCESS_TOKEN=your_cesium_ion_access_token_here
86+
REEARTH_WEB_AUTH_PROVIDER=mock
87+
```
6388

64-
Add the following environment variables to the `.env` file:
89+
:::note
90+
Please follow <a href="https://cesium.com/learn/ion/cesium-ion-access-tokens/" target="_blank">this document</a> to create your own Cesium Ion Access Token.
91+
:::
6592

66-
```plaintext
67-
REEARTH_WEB_API=http://localhost:8080/api
68-
REEARTH_WEB_PLUGINS=http://localhost:8080/plugins
69-
REEARTH_WEB_CESIUM_ION_ACCESS_TOKEN=your_cesium_ion_access_token_here
70-
REEARTH_WEB_AUTH_PROVIDER=mock
71-
```
93+
3. Install dependencies and start the frontend server.
7294

73-
:::note
74-
Please follow <a href="https://cesium.com/learn/ion/cesium-ion-access-tokens/" target="_blank">this document</a> to create your own Cesium Ion Access Token.
75-
:::
95+
```bash
96+
yarn && yarn start
97+
```
7698

77-
Install dependencies and start the frontend server.
99+
</Steps>
78100

79-
```bash
80-
yarn && yarn start
81-
```
101+
### Done!
82102

83-
You should now be able to access the Re:Earth Visualizer locally at `http://localhost:3000/`.
103+
You should now be able to access the Re:Earth Visualizer locally at <a href="http://localhost:3000" target="_blank">`http://localhost:3000`</a>.

src/content/docs/plugin-api/layers.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: layers
2+
title: reearth.layers
33
description: API reference for `reearth.layers`.
44
---
55

src/content/docs/plugin-api/modal.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: modal
2+
title: reearth.modal
33
description: API reference for `reearth.modal`.
44
---
55

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Overview
3+
description: Overview of plugin API
4+
sidebar:
5+
order: 1
6+
---
7+
8+
import { LinkCard } from "@astrojs/starlight/components";
9+
10+
The Re:Earth Visualizer Plugin API is a collection of APIs designed for plugin extensions to interact seamlessly with the Re:Earth Visualizer. It provides access to Visualizer data and offers methods to manage various components such as the layers, viewer, camera, timeline, ui, and extensions etc..
11+
12+
## Plugin API
13+
14+
Re:Earth Visualizer Plugin API is wrapped in `reearth` object, which is available globally in the plugin [WebAssembly side](/core-concepts/plugin-system/#webassembly-side). The API is divided into several modules, each of which provides a set of properties and methods to interact with the Visualizer.
15+
16+
### System related
17+
18+
**reearth.version: `string`:** The version of the Re:Earth Visualizer.
19+
20+
**reearth.apiVersion: `string`:** The version of the Re:Earth Visualizer Plugin API.
21+
22+
**reearth.engine: `string`:** Current in-use engine of the Re:Earth Visualizer.
23+
24+
### Scene related
25+
26+
<LinkCard title="reearth.viewer" href="/plugin-api/viewer" />
27+
<LinkCard title="reearth.camera" href="/plugin-api/camera" />
28+
<LinkCard title="reearth.timeline" href="/plugin-api/timeline" />
29+
30+
### Layer related
31+
32+
<LinkCard title="reearth.layers" href="/plugin-api/layers" />
33+
<LinkCard title="reearth.sketch" href="/plugin-api/sketch" />
34+
35+
### Extension related
36+
37+
<LinkCard title="reearth.extension" href="/plugin-api/extension" />
38+
<LinkCard title="reearth.ui" href="/plugin-api/ui" />
39+
<LinkCard title="reearth.modal" href="/plugin-api/modal" />
40+
<LinkCard title="reearth.popup" href="/plugin-api/popup" />
41+
42+
### Data related
43+
44+
<LinkCard title="reearth.data" href="/plugin-api/data" />
45+
46+
## Want to have a try?
47+
48+
Explore the Re:Earth Visualizer Plugin Playground to access numerous examples demonstrating the use of these plugin APIs.
49+
50+
<LinkCard
51+
title="Plugin Playground"
52+
href="/plugin-development/plugin-playground/"
53+
/>

0 commit comments

Comments
 (0)