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

Using one element to pan/zoom another? #54

Closed
stodge opened this issue Nov 26, 2013 · 14 comments
Closed

Using one element to pan/zoom another? #54

stodge opened this issue Nov 26, 2013 · 14 comments
Labels
question Thanks for your question! Even if closed, feel free to continue discussion.

Comments

@stodge
Copy link

stodge commented Nov 26, 2013

I have a strange use case where I have a custom map. I can successfully use panzoom to pan the map but I have a background rectangle element that I want users to also interact with. Users should be able to drag the background - but it won't pan the background element. Instead I want to use a callback to pan the map group instead, if this makes sense. Is there anyway in your plugin to do this? Thanks

@timmywil
Copy link
Owner

Let me see if I understand the use case. You would like to move the background element in conjunction with the panzoom element? If so, I'd suggest using the panzoomchange event to set the background element transform as the panzoom element moves. Does that help?

@stodge
Copy link
Author

stodge commented Nov 27, 2013

I'm sorry - my description was dreadful. I need a "delegate" pattern, where dragging on one element transforms another.

@timmywil
Copy link
Owner

I see! In that case, I suggest assigning the element that panzoom changes to the delegate element. You can do this like so:

var panzoom = $('#custom-map').panzoom();
var $delegate = $('#background-elem');
panzoom.$elem = $delegate;
panzoom.elem = $delegate[0];

The events will be bound to the custom map, but the transforms will be set on the background.

@stodge
Copy link
Author

stodge commented Nov 28, 2013

Thanks, alternatively, could I use callbacks to get events when a user drags an element? This way I could manage the pan/zoom myself and just let your plugin handle the eventing.

@stodge
Copy link
Author

stodge commented Nov 29, 2013

Ok - how would I use delegate to add events for both "#map" and "#background" SVG elements, but I only want to move "#map"? Is there an efficient way? Thanks again.

@stodge
Copy link
Author

stodge commented Nov 29, 2013

I used this code, but when I drag the background, the background moves, not the map:

    this.mapPanZoom = $("#map").panzoom({
    });

    this.backgroundPanZoom = $("#background").panzoom({
    });
    var $delegate = $("#map");
    this.backgroundPanZoom.$elem = $delegate;
    this.backgroundPanZoom.elem = $delegate[0];

Thanks

@stodge
Copy link
Author

stodge commented Nov 29, 2013

Sorry to be a pain - this delegation method doesn't work for me. I checked the event received in the onPan callback and the delegate and target are all the background element. So the following code didn't work:

    var $delegate = $("#map");
    this.backgroundPanZoom.$elem = $delegate;
    this.backgroundPanZoom.elem = $delegate[0];

@timmywil
Copy link
Owner

My guess is that the map covers the background, so only binding to one doesn't always trigger a move. Is that an accurate assessment? What about initializing panzoom on both, but delegating the transform settings from the background element to the map? Something like this:

http://codepen.io/timmywil/pen/rsJCy

@stodge
Copy link
Author

stodge commented Nov 30, 2013

This is all SVG, and the map partial covers the background. The background is visible. Thanks again.

@timmywil
Copy link
Owner

But the solution is sound, right? http://codepen.io/timmywil/pen/rsJCy

@stodge
Copy link
Author

stodge commented Nov 30, 2013

I'll try it out when I get back to work on Monday. I don't think I'll have time before then. Thanks.

@stodge
Copy link
Author

stodge commented Dec 2, 2013

The idea is ok but it won't work as I have lots of RECT elements that display object information on the map. So the solution of running panzoom on all RECT elements won't work. Thanks.

@timmywil
Copy link
Owner

timmywil commented Dec 2, 2013

@stodge You can adapt the solution to your needs. The selector itself is irrelevant. Thank you for your question!

@timmywil timmywil closed this as completed Dec 2, 2013
@barnettj7
Copy link

Say I had a instance where there are two images side by side. I would like the to both zoom and pan simultaneously. how would this be achieved?

@lock lock bot locked as resolved and limited conversation to collaborators Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Thanks for your question! Even if closed, feel free to continue discussion.
Projects
None yet
Development

No branches or pull requests

3 participants