Skip to content

Commit 783aef3

Browse files
authored
Merge pull request #1 from reearth-plugins/feat/try-3d-layout
feat: add-separated-widgets
2 parents aacc4ca + 5ca7173 commit 783aef3

File tree

28 files changed

+933
-211
lines changed

28 files changed

+933
-211
lines changed

README.md

Lines changed: 17 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,25 @@
1-
# Re:Earth Visualizer Plugin ShadCN Template
1+
# 30Day Map Challenge 2024 - Data: HDX
22

3-
This template provides a minimal setup to develop a Re:Earth Visualizer Plugin with Vite, React, ShadCN, and Tailwind CSS.
3+
This is a project to create a map for the [30Day Map Challenge 2024](https://30daymapchallenge.com/), topic Data: HDX.
44

5-
## Re:Earth Visualizer Plugin Structure
5+
## What's this code do?
66

7-
The structure of a Re:Earth Visualizer Plugin aligns with the definitions in `reearth.yml`. Specifically:
7+
This is a Re:Earth Visualizer Plugin. Provide several extensions that you can use in Re:Earth Visualizer.
88

9-
- A plugin can contain zero to multiple extensions.
10-
- Extensions come in three types: `widget` `storyBlock` and `infoboxBlock`. However, in terms of structure, these three types are essentially the same when developing extensions.
11-
- Each extension must correspond to a unique JavaScript script.
12-
- An extension can render its UI in three different locations: `main`, `modal`, and `popup`.
13-
- `main` refers to the primary view of the extension, typically a widget panel or block panel.
14-
- You can prepare multiple UIs for `main`, `modal`, and `popup`. Each UI will be rendered in a sandboxed iframe, effectively acting as an independent Single Page Application (SPA).
9+
## How to use?
1510

16-
## Demo
11+
1. Install plugin to Re:Earth Visualizer. You can find latest package in Release.
12+
2. Add widgets. There're two options each provide a different layout:
1713

18-
This template includes a simple demo of a plugin with a widget extension. The demo helps illustrate the file structure.
14+
- Use one single widget `Global Pandemic and Epidemic-Prone Disease Outbreaks`
15+
- Use separated widgets:
16+
- Intro Panel - Global Pandemic and Epidemic-Prone Disease Outbreaks
17+
- Credits Panel - Global Pandemic and Epidemic-Prone Disease Outbreaks
18+
- Year Selector Panel - Global Pandemic and Epidemic-Prone Disease Outbreaks
1919

20-
First, define the plugin YAML file `public/reearth.yml`:
20+
## Data Source
2121

22-
```yaml
23-
id: reearth-visualizer-plugin-shadcn-template
24-
name: Visualizer plugin shadcn template
25-
version: 1.0.0
26-
extensions:
27-
- id: demo
28-
type: widget
29-
name: Demo
30-
schema:
31-
groups:
32-
- id: appearance
33-
title: Appearance
34-
fields:
35-
- id: primary_color
36-
title: Primary color
37-
type: string
38-
ui: color
39-
```
40-
41-
As shown, it contains a single extension `demo` of type `widget`.
42-
43-
Then, review the structure of the project:
44-
45-
```planttext
46-
my-project/
47-
├── node_modules/
48-
├── public/
49-
│ └── reearth.yml // Plugin definition
50-
├── src/
51-
│ ├── extensions/
52-
│ │ └── demo/ // Extension folder, naming by extension ID
53-
│ │ ├── main/ // UI project for the main view
54-
│ │ └── demo.ts // Extension script
55-
│ └── shared/
56-
│ ├── components/ // Shared components of ShadCN
57-
│ ├── lib/ // Shared lib of ShanCN
58-
│ ├── reearthTypes/ // Shared Re:Earth Visualizer Plugin API types
59-
│ ├── global.css // Shared Global CSS of tailwind
60-
│ └── utils.ts
61-
├── dist/ // Output directory of the plugin build
62-
├── dist-ui/ // Output directory for the UI build
63-
├── package/ // Directory for packaging the plugin into a zip file
64-
├── configs/ // Vite configuration files for both extensions and UI
65-
├── scripts/
66-
├── package.json
67-
└── README.md
68-
```
69-
70-
## How to add a new extension
71-
72-
1. Update the `reearth.yml` file in the `public` folder.
73-
2. Create a new folder in `src/extensions` with the extension ID as the folder name.
74-
3. Create a new extension script file in the new folder with the extension ID as the file name.
75-
4. (Optional) Create a new UI project in the new extension folder if needed. You can refer to the `demo/main` for the structure.
76-
5. Update the scripts in `package.json` to build the new extension.
77-
78-
## Scripts
79-
80-
Refer to the scripts in `package.json`. Here are explanations for some of them:
81-
82-
```zsh
83-
yarn dev:demo:main
84-
```
85-
86-
Starts the development server for the `main` UI project of the `demo` extension.
87-
Ensure you check the environment variables being passed in so you can add your own scripts for different UI projects of different extensions.
88-
89-
```zsh
90-
yarn build:demo:main
91-
```
92-
93-
Builds the `main` UI project of the `demo` extension to `dist-ui/demo/main`.
94-
95-
```zsh
96-
yarn build:demo
97-
```
98-
99-
Builds the `demo` extension to `dist`. The `reearth.yml` file will also be copied to `dist`.
100-
101-
```zsh
102-
yarn build
103-
```
104-
105-
Builds the entire plugin (all extensions to `dist`), generating a zip file in the `package` folder.
106-
Note that `README.md` and `LICENSE` will be included in the zip. Update this script to include build commands for additional extensions as needed.
107-
108-
```zsh
109-
yarn preview
110-
```
111-
112-
Starts the preview server on port `5005`.
113-
114-
## Development Workflow with Re:Earth Visualizer
115-
116-
### Traditional Way
117-
118-
- Start a dev server for the UI project of the extension you are developing.
119-
- Develop the UI, checking it with the dev server.
120-
- Develop the extension script, with no immediate way to check the result.
121-
- Build the plugin and generate the plugin zip file.
122-
- Go to Re:Earth Visualizer, install the plugin via the zip file, and add the widget or block.
123-
- Check the result.
124-
125-
This process is lengthy and results in low development efficiency.
126-
127-
### Improved Way
128-
129-
We are working on adding a new feature to Re:Earth Visualizer to improve the development experience (DX) for plugins. Follow these steps:
130-
131-
0. Preparation:
132-
- Run Re:Earth Visualizer locally. Only the front-end is required; you can use any backend, such as the OSS backend.
133-
- Update the plugin code. You can test with the demo.
134-
135-
1. Run script:
136-
137-
```zsh
138-
yarn dev-build
139-
```
140-
it will:
141-
- Start a dev server for the UI project as usual (usually you don't need to use this).
142-
- Automatically build the UI upon edits.
143-
- Automatically build the extension.
144-
- Start a preview server at `http://localhost:5005`.
145-
146-
2. Set environment variables in the Re:Earth Visualizer front-end project: `REEARTH_WEB_DEV_PLUGIN_URLS='["http://localhost:5005"]'`. The server will automatically restart after .env changes.
147-
148-
Done. Now Re:Earth Visualizer will offer two icon buttons in the editor header:
149-
- `Install Dev Plugins` ![image](https://github.com/user-attachments/assets/aa5cf46c-019e-4df6-82f7-c18aa18fe108)
150-
151-
- This fetches plugin files from the plugin preview, automatically zips, and installs them.
152-
- Click this only when initially setting up and after modifying `reearth.yml`.
153-
- `Reload Dev Plugin Extensions` ![image](https://github.com/user-attachments/assets/493b1bf2-0ffa-43d7-9166-849b1e7a5e30)
154-
155-
- This reloads all extensions from the plugin preview.
156-
- Only the plugin reloads, which is much faster than reloading the entire page.
157-
158-
### Summary
159-
160-
Once everything is set up, the improved DX workflow will be:
161-
162-
- Make any changes to the plugin code.
163-
- Click `Reload Dev Plugin Extensions` on the local Re:Earth Visualizer webpage.
164-
165-
This workflow significantly improves development efficiency compared to the traditional method.
22+
- [Humanitarian Data Exchange](https://data.humdata.org/)
23+
- [Global Pandemic and Epidemic-Prone Disease Outbreaks](https://data.humdata.org/dataset/a-global-dataset-of-pandemic-and-epidemic-prone-disease-outbreaks)
24+
- Map tiles by Carto, under CC BY 3.0.
25+
- Admin 0 countries: [geojson.xyz](https://geojson.xyz/)

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@
1010
"build:diseaseoutbreaks:main": "cross-env EXTENSION_NAME=diseaseoutbreaks UI_NAME=main vite build -c configs/ui.ts",
1111
"build:diseaseoutbreaks:extension": "cross-env EXTENSION_NAME=diseaseoutbreaks vite build -c configs/extension.ts",
1212
"build:diseaseoutbreaks": "run-s build:diseaseoutbreaks:main build:diseaseoutbreaks:extension",
13-
"build": "run-s build:diseaseoutbreaks zip",
13+
"dev:intro:main": "cross-env EXTENSION_NAME=intro UI_NAME=main vite -c configs/ui.ts",
14+
"build:intro:main": "cross-env EXTENSION_NAME=intro UI_NAME=main vite build -c configs/ui.ts",
15+
"build:intro:extension": "cross-env EXTENSION_NAME=intro vite build -c configs/extension.ts",
16+
"build:intro": "run-s build:intro:main build:intro:extension",
17+
"dev:credits:main": "cross-env EXTENSION_NAME=credits UI_NAME=main vite -c configs/ui.ts",
18+
"build:credits:main": "cross-env EXTENSION_NAME=credits UI_NAME=main vite build -c configs/ui.ts",
19+
"build:credits:extension": "cross-env EXTENSION_NAME=credits vite build -c configs/extension.ts",
20+
"build:credits": "run-s build:credits:main build:credits:extension",
21+
"dev:year:main": "cross-env EXTENSION_NAME=year UI_NAME=main vite -c configs/ui.ts",
22+
"build:year:main": "cross-env EXTENSION_NAME=year UI_NAME=main vite build -c configs/ui.ts",
23+
"build:year:extension": "cross-env EXTENSION_NAME=year vite build -c configs/extension.ts",
24+
"build:year": "run-s build:year:main build:year:extension",
25+
"build": "run-s build:diseaseoutbreaks build:intro build:credits build:year zip",
1426
"preview": "vite preview --port 5005 --strict-port",
1527
"zip": "node ./scripts/zip.mjs",
1628
"lint": "eslint .",
1729
"fix": "eslint --fix .",
1830
"format": "prettier --write .",
19-
"dev-build": "concurrently 'yarn dev:diseaseoutbreaks:main' 'yarn build:diseaseoutbreaks:main --watch' 'yarn build:diseaseoutbreaks:extension --watch' 'vite preview --port 5005 --strict-port'",
31+
"dev-build": "concurrently 'yarn build:diseaseoutbreaks:main --watch' 'yarn build:diseaseoutbreaks:extension --watch' 'yarn build:intro:main --watch' 'yarn build:intro:extension --watch' 'yarn build:credits:main --watch' 'yarn build:credits:extension --watch' 'yarn build:year:main --watch' 'yarn build:year:extension --watch' 'vite preview --port 5005 --strict-port'",
2032
"data": "node ./scripts/data.mjs"
2133
},
2234
"dependencies": {

public/reearth.yml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
id: global-pandemic-and-epidemic-prone-diseaseoutbreaks
2-
name: Global Pandemic- and Epidemic-Prone Disease Outbreaks
2+
name: Global Pandemic and Epidemic-Prone Disease Outbreaks
33
version: 1.0.0
44
extensions:
55
- id: diseaseoutbreaks
66
type: widget
7-
name: Global Pandemic- and Epidemic-Prone Disease Outbreaks
7+
name: Global Pandemic and Epidemic-Prone Disease Outbreaks
88
widgetLayout:
99
extendable:
1010
horizontally: true
1111
defaultLocation:
1212
zone: outer
1313
section: center
1414
area: bottom
15-
schema:
16-
groups:
17-
- id: appearance
18-
title: Appearance
19-
fields:
20-
- id: primary_color
21-
title: Primary color
22-
type: string
23-
ui: color
15+
- id: intro
16+
type: widget
17+
name: Intro Panel - Global Pandemic and Epidemic-Prone Disease Outbreaks
18+
widgetLayout:
19+
defaultLocation:
20+
zone: inner
21+
section: left
22+
area: top
23+
- id: credits
24+
type: widget
25+
name: Credits Panel - Global Pandemic and Epidemic-Prone Disease Outbreaks
26+
widgetLayout:
27+
defaultLocation:
28+
zone: inner
29+
section: right
30+
area: bottom
31+
- id: year
32+
type: widget
33+
name: Year Selector Panel - Global Pandemic and Epidemic-Prone Disease Outbreaks
34+
widgetLayout:
35+
defaultLocation:
36+
zone: inner
37+
section: left
38+
area: bottom

src/extensions/credits/credits.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import html from "@distui/credits/main/index.html?raw";
2+
3+
import { GlobalThis } from "@/shared/reearthTypes";
4+
5+
const reearth = (globalThis as unknown as GlobalThis).reearth;
6+
reearth.ui.show(html, { extended: true });
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Source from "./components/Source";
2+
3+
function App() {
4+
return (
5+
<div className="flex gap-2 p-4 text-slate-700">
6+
<Source />
7+
</div>
8+
);
9+
}
10+
11+
export default App;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
html,
2+
body {
3+
width: 380px;
4+
}
5+
6+
:root {
7+
--background: "transparent"; /* Define the initial value of your CSS variable */
8+
}
9+
10+
.lato-thin {
11+
font-family: "Lato", sans-serif;
12+
font-weight: 100;
13+
font-style: normal;
14+
}
15+
16+
.lato-light {
17+
font-family: "Lato", sans-serif;
18+
font-weight: 300;
19+
font-style: normal;
20+
}
21+
22+
.lato-regular {
23+
font-family: "Lato", sans-serif;
24+
font-weight: 400;
25+
font-style: normal;
26+
}
27+
28+
.lato-bold {
29+
font-family: "Lato", sans-serif;
30+
font-weight: 700;
31+
font-style: normal;
32+
}
33+
34+
.lato-black {
35+
font-family: "Lato", sans-serif;
36+
font-weight: 900;
37+
font-style: normal;
38+
}
39+
40+
.lato-thin-italic {
41+
font-family: "Lato", sans-serif;
42+
font-weight: 100;
43+
font-style: italic;
44+
}
45+
46+
.lato-light-italic {
47+
font-family: "Lato", sans-serif;
48+
font-weight: 300;
49+
font-style: italic;
50+
}
51+
52+
.lato-regular-italic {
53+
font-family: "Lato", sans-serif;
54+
font-weight: 400;
55+
font-style: italic;
56+
}
57+
58+
.lato-bold-italic {
59+
font-family: "Lato", sans-serif;
60+
font-weight: 700;
61+
font-style: italic;
62+
}
63+
64+
.lato-black-italic {
65+
font-family: "Lato", sans-serif;
66+
font-weight: 900;
67+
font-style: italic;
68+
}
69+
70+
.color-picker {
71+
color: #ff0022;
72+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { FC } from "react";
2+
3+
const Source: FC = () => {
4+
return (
5+
<div className="flex flex-col items-end justify-end flex-1 gap-1 text-right text-slate-600">
6+
<p className="text-xs">
7+
<strong>Data source:</strong>{" "}
8+
<a
9+
className="underline"
10+
href="https://data.humdata.org/"
11+
target="_black"
12+
>
13+
Humanitarian Data Exchange
14+
</a>
15+
<br />
16+
<a
17+
className="underline"
18+
href="https://data.humdata.org/dataset/a-global-dataset-of-pandemic-and-epidemic-prone-disease-outbreaks"
19+
target="_black"
20+
>
21+
Global Pandemic- and Epidemic-Prone Disease Outbreaks
22+
</a>
23+
</p>
24+
<p className="text-xs">
25+
<strong>Map Tile:</strong> Map tiles by Carto, under CC BY 3.0.
26+
</p>
27+
<p className="text-xs">
28+
<strong>Admin 0 countries:</strong>{" "}
29+
<a className="underline" href="https://geojson.xyz/" target="_black">
30+
https://geojson.xyz/
31+
</a>
32+
</p>
33+
<p className="text-xs">
34+
<strong>App:</strong>{" "}
35+
<a className="underline" href="https://reearth.io/" target="_black">
36+
Re:Earth Visualizer
37+
</a>{" "}
38+
<a className="underline" href="https://cesium.com/" target="_black">
39+
Cesium
40+
</a>
41+
</p>
42+
</div>
43+
);
44+
};
45+
46+
export default Source;

0 commit comments

Comments
 (0)