|
1 | | -# Re:Earth Visualizer Plugin ShadCN Template |
| 1 | +# 30Day Map Challenge 2024 - Data: HDX |
2 | 2 |
|
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. |
4 | 4 |
|
5 | | -## Re:Earth Visualizer Plugin Structure |
| 5 | +## What's this code do? |
6 | 6 |
|
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. |
8 | 8 |
|
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? |
15 | 10 |
|
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: |
17 | 13 |
|
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 |
19 | 19 |
|
20 | | -First, define the plugin YAML file `public/reearth.yml`: |
| 20 | +## Data Source |
21 | 21 |
|
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`  |
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`  |
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/) |
0 commit comments