File tree Expand file tree Collapse file tree 2 files changed +50
-4
lines changed Expand file tree Collapse file tree 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);
4343
4444const vectorLayer = computed (() => new VectorLayer (properties ));
4545
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+ );
4975
5076onMounted (() => {
5177 map ?.addLayer (vectorLayer .value );
Original file line number Diff line number Diff line change 11<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+
217 <ol-map
318 :loadTilesWhileAnimating =" true"
419 :loadTilesWhileInteracting =" true"
1227 :constrainRotation =" 16"
1328 />
1429
15- <ol-vector-layer background =" #1a2b39" ref =" vectorSourceRef" >
30+ <ol-vector-layer
31+ background =" #1a2b39"
32+ ref =" vectorSourceRef"
33+ :opacity =" opacity"
34+ >
1635 <ol-source-vector :url =" url" :format =" geoJson" >
1736 <ol-style :overrideStyleFunction =" styleFn" ></ol-style >
1837 </ol-source-vector >
@@ -35,6 +54,7 @@ import { shiftKeyOnly } from "ol/events/condition";
3554import { ref , inject } from " vue" ;
3655import type { DragBoxEvent } from " ol/interaction/DragBox" ;
3756
57+ const opacity = ref (1 );
3858const center = ref ([0 , 0 ]);
3959const projection = ref (" EPSG:4326" );
4060const zoom = ref (0 );
You can’t perform that action at this time.
0 commit comments