Moppel Posted December 1, 2022 Share Posted December 1, 2022 (edited) I'd like to implement a snap-to-grid feature and would like for this to manipulate the coordinates of mouse events. My current implementation is like this: Interface: Interaction (has nothing to do with Pixis Interaction classes) with a handleEvent function (return type event) which either does nothing and returns the original event or returns a new event object. Snap-to-grid implements that interface. Then there is a class 'Map' derived from Pixi.Container which will be inserted as a child of the pixi-viewport and does not much besides from offering functions: addInteraction(interaction), removeInteraction(interaction) and internally hold an Pixi.EventBoundary object. My hope now is that the event boundary can somehow look for certain events on the viewport object and delegate them to the handleEvent methods of its registered interactions (cascading through them) such that in the end my implementations of mouse/pointer-tools (for creating polygons etc) which are listening to events like 'pointermove' that map-container receive the manipulated events (if the mouse cursor is close to some snappable object). If an object is snappable is determined in the handleEvent method. From the API documentation I dont quite understand if EventBoundaries are actually usable for my use-case and what happens to events that I'm not looking for (I'd like them to just pass through). Version: Pixi 6.5.8 (Cant go to 7 because pixi-viewport is not updated yet) Thanks alot Edited December 1, 2022 by Moppel Quote Link to comment Share on other sites More sharing options...
Moppel Posted December 22, 2022 Author Share Posted December 22, 2022 (edited) Alright, I figured out a solution by implementing it as a custom EventBoundary and setting it on Application wide level. My custom boundary allows to register plugins which can be turned on/off externally. The actual implementation of the snap feature follow roughly what openLayers did in theirs but I'm gonna add more fancy stuff ontop. Unfortunately, I am not allowed to share the code (written for a commercial customer) cheers 🙂 Edited December 22, 2022 by Moppel Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.