Is it possible to use rxjs observables for cesium events?


Is it possible to use rxjs observables for cesium events? especially for camera events.

Thanks in advance!

Hello @Baruch_Levin :wave:

Have you tried to use the fromEvent RxJS operator such as:

fromEvent(, 'changed')

Thank you @Aristeidis_Bampakos for your answer!
I will try it.
A javascript question, why it will work? because Cesium use Event.js for events, which is a self implementation, i mean its not the regular DOM events…

@Baruch_Levin according to the RxJS documentation the parameter of the fromEvent should be an object with methods for registering event handler functions. The Event.js in Cesium actually implements such methods like the addEventListener so theoretically it should work. If not, let me know and I could have a more detailed view :smiley:.

@Aristeidis_Bampakos i tried, it doesnt work.
I tried ,

fromEvent(, 'changed') ;
fromEvent(, 'changed') ;

The error is:

Argument of type 'Camera' is not assignable to parameter of type 'FromEventTarget<unknown>' >. 
Property 'length' is missing in type 'Camera' but required in type 'ArrayLike<EventTargetLike<unknown>>'. ts(2345)
lib.es5.d.ts(1452, 14): 'length' is declared here. 

@Baruch_Levin unfortunately it does not because the camera object does not fall into any of the possible target types that are supported in fromEvent. However, you can create an observable wrapper of the camera events if you like.

1 Like