Jump to content

Manipulating Events


Recommended Posts

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 by Moppel
Link to comment
Share on other sites

  • 3 weeks later...

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 by Moppel
Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...