2023-03-28 15:11:58 +08:00
|
|
|
# ⚡ vite-plugin-earth
|
2022-02-10 13:08:07 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
[![npm](https://img.shields.io/npm/v/vite-plugin-earth.svg)](https://www.npmjs.com/package/vite-plugin-earth)
|
|
|
|
[![npm](https://img.shields.io/npm/dt/vite-plugin-earth)](https://www.npmjs.com/package/vite-plugin-earth)
|
2023-03-28 10:02:22 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
Easily set up a [`Cesium`] & [`Mars3D`] project in [`Vite`].
|
2022-02-10 13:08:07 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
[`cesium`]: https://cesium.com/platform/cesiumjs/
|
|
|
|
[`vite`]: https://vitejs.dev/
|
2023-06-06 13:37:10 +08:00
|
|
|
[`mars3d`]: http://mars3d.cn/
|
2023-03-28 10:02:22 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
## Cesium
|
2023-03-28 10:02:22 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
### Install
|
2022-02-10 13:08:07 +08:00
|
|
|
|
|
|
|
```bash
|
2023-03-28 15:11:58 +08:00
|
|
|
npm i cesium vite-plugin-earth vite -D
|
2022-02-10 13:08:07 +08:00
|
|
|
```
|
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
### Usage
|
2022-02-10 13:08:07 +08:00
|
|
|
|
|
|
|
add this plugin to `vite.config.js`
|
|
|
|
|
|
|
|
```js
|
|
|
|
import { defineConfig } from 'vite';
|
2023-06-06 13:37:10 +08:00
|
|
|
import { cesiumPlugin } from 'vite-plugin-earth';
|
2022-02-10 13:08:07 +08:00
|
|
|
export default defineConfig({
|
2023-06-06 13:37:10 +08:00
|
|
|
plugins: [cesiumPlugin()]
|
2022-02-10 13:08:07 +08:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
## Mars3D
|
|
|
|
|
|
|
|
### Install
|
2023-03-28 10:02:22 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
```bash
|
|
|
|
npm i mars3d mars3d-cesium vite-plugin-earth vite -D
|
2023-03-28 10:02:22 +08:00
|
|
|
```
|
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
### Usage
|
2023-03-28 10:02:22 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
add this plugin to `vite.config.js`
|
|
|
|
|
|
|
|
```js
|
|
|
|
import { defineConfig } from 'vite';
|
2023-06-06 13:37:10 +08:00
|
|
|
import { mars3dPlugin } from 'vite-plugin-earth';
|
2023-03-28 15:11:58 +08:00
|
|
|
export default defineConfig({
|
2023-06-06 13:37:10 +08:00
|
|
|
plugins: [mars3dPlugin()]
|
2023-03-28 15:11:58 +08:00
|
|
|
});
|
|
|
|
```
|
2023-03-28 10:02:22 +08:00
|
|
|
|
2022-07-14 14:51:49 +08:00
|
|
|
## Options
|
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
**useCDN**
|
2022-07-14 14:51:49 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
- **Type :** `object`
|
2023-06-06 13:37:10 +08:00
|
|
|
- **Default :** `{ mars3d: '3.5.4', mars3dCesium: '1.104.3', turf: '6.5.0' }`
|
2022-02-10 13:08:07 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
打包时使用 cdn 方式
|
2022-07-14 14:51:49 +08:00
|
|
|
|
|
|
|
```js
|
|
|
|
import { defineConfig } from 'vite';
|
2023-06-06 13:37:10 +08:00
|
|
|
import { mars3dPlugin } from 'vite-plugin-earth';
|
2022-07-14 14:51:49 +08:00
|
|
|
export default defineConfig({
|
|
|
|
plugins: [
|
2023-06-06 13:37:10 +08:00
|
|
|
mars3dPlugin({
|
|
|
|
useCDN: true
|
2022-07-14 14:51:49 +08:00
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
2022-02-10 13:08:07 +08:00
|
|
|
```
|
|
|
|
|
2023-03-28 10:02:22 +08:00
|
|
|
## Demo
|
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
### Cesium
|
|
|
|
|
|
|
|
```html
|
|
|
|
<div id="cesiumContainer"></div>
|
|
|
|
```
|
2022-02-10 13:08:07 +08:00
|
|
|
|
2023-03-28 10:02:22 +08:00
|
|
|
```js
|
|
|
|
import { Viewer } from 'cesium';
|
|
|
|
|
|
|
|
const viewer = new Viewer('cesiumContainer');
|
|
|
|
```
|
2022-02-10 13:08:07 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
### Mars3D
|
2023-03-28 10:02:22 +08:00
|
|
|
|
|
|
|
```html
|
2023-03-28 15:11:58 +08:00
|
|
|
<div id="mars3dContainer"></div>
|
2023-03-28 10:02:22 +08:00
|
|
|
```
|
2022-02-10 13:08:07 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
```js
|
|
|
|
import * as mars3d from 'mars3d';
|
|
|
|
import 'mars3d/dist/mars3d.css';
|
2022-02-10 13:08:07 +08:00
|
|
|
|
2023-03-28 15:11:58 +08:00
|
|
|
const map = new mars3d.Map('mars3dContainer', {});
|
2022-02-10 13:08:07 +08:00
|
|
|
```
|
2023-03-28 10:02:22 +08:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
MIT
|