svg-pan-zoom — Pan and zoom to same location in different browser sizes

后端 未结 1 948
粉色の甜心
粉色の甜心 2021-01-26 19:36

I am using the ariutta svg-pan-zoom library(https://github.com/ariutta/svg-pan-zoom). (Also using with jquery.layout.js panes and jquery-ui.js)

I would like to save the

相关标签:
1条回答
  • 2021-01-26 20:05

    Pan and zoom are relative to current container size. So what you want is to compute the center point of visible SVG's part. Then in new window compute what should be the new pan to have the that SVG's point (that was the center in previous case). As about the zoom it depends on how you want to make it work, but you could use the real zoom.

    To get container sizes and real zoom use instance.getSizes().

    So for example to compute x axis do:

    var s = instance.getSizes()
    var p = instance.getPan()
    var relativeX = s.width / 2 / (p.x + s.viewBox.width * s.realZoom)
    
    // After resize
    var s = instance.getSizes()
    var p = instance.getPan()
    var x = (s.width / 2 / relativeX) - s.viewBox.width * s.realZoom
    instance.pan({x: x, y: 0})
    

    Do the same for Y axis

    0 讨论(0)
提交回复
热议问题