Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag on regular Raphael objects is translated as pan #4

Open
Nitrodist opened this issue Mar 26, 2012 · 11 comments
Open

Drag on regular Raphael objects is translated as pan #4

Nitrodist opened this issue Mar 26, 2012 · 11 comments

Comments

@Nitrodist
Copy link
Contributor

So, both events are firing in this case. I drag a square and it moves the square but it also pans the entire screen. Not a great case. Is there a way to disable this functionality when it knows that there's another drag event occurring or to register it in panZoom to not trigger it?

@escobar5
Copy link
Owner

escobar5 commented Apr 3, 2012

Is there a way in Raphael to check if a specific element is handling the drag event? I can't find it.

@Nitrodist
Copy link
Contributor Author

I don't think so. I'm not totally familiar with it. What I did to get around it was to call panzoom.disable when I'm moving the object and enable it when it's done dragging. It's a hack on my side, but it works...

@Nitrodist
Copy link
Contributor Author

Although, can't you hook into the call to the Raphael object's .drag? That way you can set your own function to be called when it starts dragging/moving/stops and then pass onto the correct start/move/drag callback...

Let me know if you think if this is the correct approach.

@escobar5
Copy link
Owner

escobar5 commented Apr 4, 2012

I'm going to check if that's possible. But I'm seeing a strange behavior when the paper is zoomed in, even if I disable the drag of raphael pan & zoom, the drag moves a larger distance than the mouse movement.

@Nitrodist
Copy link
Contributor Author

That's because dx, dy is the mouse's distance from its origin, not its distance from the point on the canvas. So if you're zoomed in 2x, then you move your mouse 10 pixels, then you've really moved it 10 pixels, so the element you're dragging will go twice as far (to you), but if you were zoomed out, it would be same distance.

You have to compensate for the zoom level that you're at with regards to dx, dy (some kind of modifier). I haven't delved into your zoomlevel stuff (no idea what level 0, 1, 2, 3, .etc, really mean), but this is the correct approach, I think.

@meecect
Copy link

meecect commented Aug 7, 2012

any hint on how to account for the zoomlevel? I tried simply dividing my 'dx' and 'dy' by the zoom level but that did not quite work. It's close, but now when zoomed in the object move a little 'less' that they should. Without the factor, they move more than they should.

Not sure what the issue is.

@Siyfion
Copy link

Siyfion commented Aug 14, 2012

I'm experiencing similar issues to those described here, I'm using the Raphael FreeTransform library (https://github.com/ElbertF/Raphael.FreeTransform) which is really awesome, but when I drag an element around it's also panning all over the place. I don't know if there's a better way to fix this other than the mentioned 'hack' that just disables and enables panZoom when the element drag event fires?

@Gubbi
Copy link

Gubbi commented Nov 21, 2012

By using panZoom.enable() and panZoom.disable() in the Raphael object event handlers, this can be prevented.

@yahyaKacem
Copy link

One possible way to fix this (in the same plunker I provided for the negative value issue) is to disable the pan on the objects so the pan can only be applied to the canvas.

@vipulsaluja
Copy link

Fix to this problem is to update dx and dy before applying translation to element

dx = dx - dx * panZoom.getCurrentZoom * zoomStep;
dy = dy - dy * panZoom.getCurrentZoom * zoomStep;

After this, dragging element in zoom works perfectly.

@achtan
Copy link

achtan commented Mar 21, 2015

@Siyfion hi i have same issue with pan-zoom + Free-transform... how exactly did you fixed it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants