getScreenCTM / Zoom bug with svgs that are not positioned at the left top of the document
See original GitHub issueI had a problem with zooming to the mouse position when an svg isn’t rendered at the top left corner of the browser but somewhere else in the document. (See also #132, which contains an example of the current behavior)
I traced it down to the transformToScreen method, where getScreenCTM
is used. getScreenCTM
returns the offset of the svg to the top and left corner of the document and from there on calculates all positions using this offset.
But the “zero point” of the svg is still at 0/0 - the offset isn’t necessary and shouldn’t be used at all.
When replacing the value of the following lines with 0, everything works as expected:
https://github.com/anvaka/panzoom/blob/3c5734f9a0ab0958822c9f639e5ede82e6815c5e/index.js#L181
https://github.com/anvaka/panzoom/blob/3c5734f9a0ab0958822c9f639e5ede82e6815c5e/index.js#L182
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top GitHub Comments
This works like a charm. Thanks for the quick fix!
I’ll take a look later tonight (pacific time). If I recall correctly, that was done to make sure svgs with viewbox work correctly, which is obviously incorrect for the reasons you guys have mentioned.