@@ -18,31 +18,79 @@ npm install ol ol-ext ol-contextmenu # install the peerDependencies
18
18
npm install vue3-openlayers # install this library
19
19
```
20
20
21
- ## Usage
21
+ ## Usage: As Plugin
22
22
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).
24
25
25
26
``` ts
26
27
import { createApp } from " vue" ;
27
28
import App from " ./App.vue" ;
28
29
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'
31
38
32
39
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 )
34
48
35
49
app .mount (" #app" );
36
50
```
37
51
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
+
38
86
## Debug Mode
39
87
40
88
You can activate the ` debug ` mode, to log events receiving from OpenLayers and props passed to OpenLayers on the console.
41
89
90
+ > Note: This is currently only possible when setting up vue3-openlayers globally.
91
+
42
92
``` ts
43
- import OpenLayersMap , {
44
- type Vue3OpenlayersGlobalOptions ,
45
- } from " vue3-openlayers" ;
93
+ import OpenLayersMap , { type Vue3OpenlayersGlobalOptions } from " vue3-openlayers" ;
46
94
// ...
47
95
48
96
const options: Vue3OpenlayersGlobalOptions = {
0 commit comments