Skip to content

Commit 4646392

Browse files
committed
docs: update getting started section
1 parent bebdb01 commit 4646392

File tree

1 file changed

+56
-8
lines changed

1 file changed

+56
-8
lines changed

docs/get-started.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,79 @@ npm install ol ol-ext ol-contextmenu # install the peerDependencies
1818
npm install vue3-openlayers # install this library
1919
```
2020

21-
## Usage
21+
## Usage: As Plugin
2222

23-
To use `vue3-openlayers` in your application, you can import all components or just what you really need.
23+
To use `vue3-openlayers` in your application as a Plugin for global component availability,
24+
you can import all components (default export) or only parts of `vue3-openlayers` in your application (named exports).
2425

2526
```ts
2627
import { createApp } from "vue";
2728
import App from "./App.vue";
2829

29-
import OpenLayersMap from "vue3-openlayers";
30-
import "vue3-openlayers/styles.css"; // vue3-openlayers version < 1.0.0-*
30+
// The style are only needed for some map controls.
31+
// However, you can also style them by your own
32+
import "vue3-openlayers/styles.css";
33+
34+
// provide all components
35+
import OpenLayersMap from 'vue3-openlayers'
36+
// OR: just use the parts you need
37+
import { Map, Layers, Sources } from 'vue3-openlayers'
3138

3239
const app = createApp(App);
33-
app.use(OpenLayersMap /* options */);
40+
41+
// provide all components
42+
app.use(OpenLayersMap /*, options */);
43+
44+
// OR: just use the parts you need
45+
app.use(Map)
46+
app.use(Layers)
47+
app.use(Sources)
3448

3549
app.mount("#app");
3650
```
3751

52+
Now you can use the globally provided components like this:
53+
54+
```vue
55+
<script setup lang="ts"></script>
56+
57+
<template>
58+
<ol-map style="min-width: 400px; min-height: 400px">
59+
<ol-view :center="[40, 40]" :zoom="5" projection="EPSG:4326" />
60+
<ol-tile-layer>
61+
<ol-source-osm />
62+
</ol-tile-layer>
63+
</ol-map>
64+
</template>
65+
```
66+
67+
## Usage: Import where needed
68+
69+
You can also import and use components individually by importing them directly in your components.
70+
71+
```vue
72+
<script setup lang="ts">
73+
import { Map, Layers, Sources } from 'vue3-openlayers'
74+
</script>
75+
76+
<template>
77+
<Map.OlMap style="min-width: 400px; min-height: 400px">
78+
<Map.OlView :center="[40, 40]" :zoom="5" projection="EPSG:4326" />
79+
<Layers.OlTileLayer>
80+
<Sources.OlSourceOSM />
81+
</Layers.OlTileLayer>
82+
</Map.OlMap>
83+
</template>
84+
```
85+
3886
## Debug Mode
3987

4088
You can activate the `debug` mode, to log events receiving from OpenLayers and props passed to OpenLayers on the console.
4189

90+
> Note: This is currently only possible when setting up vue3-openlayers globally.
91+
4292
```ts
43-
import OpenLayersMap, {
44-
type Vue3OpenlayersGlobalOptions,
45-
} from "vue3-openlayers";
93+
import OpenLayersMap, { type Vue3OpenlayersGlobalOptions } from "vue3-openlayers";
4694
// ...
4795

4896
const options: Vue3OpenlayersGlobalOptions = {

0 commit comments

Comments
 (0)