File tree 2 files changed +50
-4
lines changed
2 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,35 @@ const properties = usePropsAsObjectProperties(props);
43
43
44
44
const vectorLayer = computed (() => new VectorLayer (properties ));
45
45
46
- watch (properties , () => {
47
- vectorLayer .value .setProperties (properties );
48
- });
46
+ watch (
47
+ () => properties ,
48
+ (newValue ) => {
49
+ vectorLayer .value .setProperties (newValue );
50
+ for (const key in newValue ) {
51
+ const keyInObj = key as keyof typeof newValue ;
52
+ if (newValue [keyInObj ]) {
53
+ vectorLayer .value .set (key , newValue [keyInObj ]);
54
+ }
55
+ }
56
+ },
57
+ { deep: true },
58
+ );
59
+
60
+ watch (
61
+ () => props .visible ,
62
+ (newVisible : boolean ) => {
63
+ vectorLayer .value .setVisible (newVisible );
64
+ },
65
+ { immediate: true },
66
+ );
67
+
68
+ watch (
69
+ () => props .opacity ,
70
+ (newOpacity : number ) => {
71
+ vectorLayer .value .setOpacity (newOpacity );
72
+ },
73
+ { immediate: true },
74
+ );
49
75
50
76
onMounted (() => {
51
77
map ?.addLayer (vectorLayer .value );
Original file line number Diff line number Diff line change 1
1
<template >
2
+ <form >
3
+ <fieldset >
4
+ <label for =" opacity" >Layer Opacity</label >
5
+ <input
6
+ type =" range"
7
+ id =" opacity"
8
+ min =" 0"
9
+ max =" 1"
10
+ step =" 0.1"
11
+ v-model.number =" opacity"
12
+ />
13
+ <span class =" description" >{{ opacity }}</span >
14
+ </fieldset >
15
+ </form >
16
+
2
17
<ol-map
3
18
:loadTilesWhileAnimating =" true"
4
19
:loadTilesWhileInteracting =" true"
12
27
:constrainRotation =" 16"
13
28
/>
14
29
15
- <ol-vector-layer background =" #1a2b39" ref =" vectorSourceRef" >
30
+ <ol-vector-layer
31
+ background =" #1a2b39"
32
+ ref =" vectorSourceRef"
33
+ :opacity =" opacity"
34
+ >
16
35
<ol-source-vector :url =" url" :format =" geoJson" >
17
36
<ol-style :overrideStyleFunction =" styleFn" ></ol-style >
18
37
</ol-source-vector >
@@ -35,6 +54,7 @@ import { shiftKeyOnly } from "ol/events/condition";
35
54
import { ref , inject } from " vue" ;
36
55
import type { DragBoxEvent } from " ol/interaction/DragBox" ;
37
56
57
+ const opacity = ref (1 );
38
58
const center = ref ([0 , 0 ]);
39
59
const projection = ref (" EPSG:4326" );
40
60
const zoom = ref (0 );
You can’t perform that action at this time.
0 commit comments