@@ -10,9 +10,10 @@ import type { Size } from "ol/size";
1010import type { Pixel } from "ol/pixel" ;
1111import type BaseEvent from "ol/events/Event" ;
1212import type { SimpleGeometry } from "ol/geom" ;
13+ import usePropsAsObjectProperties from "./usePropsAsObjectProperties" ;
1314
1415export default function useView (
15- properties : Record < string , unknown > & {
16+ props : Record < string , unknown > & {
1617 projection : string | Options ;
1718 } ,
1819 emit : (
@@ -24,7 +25,8 @@ export default function useView(
2425 ...args : any [ ]
2526 ) => void
2627) {
27- const map = inject < Ref < Map > > ( "map" ) ;
28+ const map = inject < Map > ( "map" ) ;
29+ const { properties } = usePropsAsObjectProperties ( props ) ;
2830
2931 const createProp = ( ) => {
3032 return {
@@ -39,6 +41,21 @@ export default function useView(
3941 } ;
4042 const view = new View ( createProp ( ) ) ;
4143
44+ onMounted ( ( ) => {
45+ map ?. setView ( view ) ;
46+ } ) ;
47+
48+ view . on ( "change:center" , ( ) => {
49+ emit ( "centerChanged" , getCenter ( ) ) ;
50+ emit ( "zoomChanged" , getZoom ( ) ) ;
51+ } ) ;
52+
53+ view . on ( "change:resolution" , ( ) =>
54+ emit ( "resolutionChanged" , getResolution ( ) )
55+ ) ;
56+
57+ view . on ( "change:rotation" , ( ) => emit ( "rotationChanged" , getRotation ( ) ) ) ;
58+
4259 watch ( properties , ( ) => {
4360 const pr = createProp ( ) ;
4461 view . setProperties ( pr ) ;
@@ -106,21 +123,6 @@ export default function useView(
106123 const setRotation = ( rotation : number ) => view . setRotation ( rotation ) ;
107124 const setZoom = ( zoom : number ) => view . setZoom ( zoom ) ;
108125
109- onMounted ( ( ) => {
110- map ?. value ?. setView ( view ) ;
111- } ) ;
112-
113- view . on ( "change:center" , ( ) => {
114- emit ( "centerChanged" , getCenter ( ) ) ;
115- emit ( "zoomChanged" , getZoom ( ) ) ;
116- } ) ;
117-
118- view . on ( "change:resolution" , ( ) =>
119- emit ( "resolutionChanged" , getResolution ( ) )
120- ) ;
121-
122- view . on ( "change:rotation" , ( ) => emit ( "rotationChanged" , getRotation ( ) ) ) ;
123-
124126 return {
125127 view,
126128
0 commit comments