- From: Karim Scheik <karim.scheik@prisma-solutions.at>
- Date: Fri, 8 Jul 2005 16:48:37 +0200
- To: <www-svg@w3.org>
Hi! Even after reading through the pile of threads with "currentScale" and so on, I still am unable to get it working correctly. I have a typical GIS viewbox (594910 -450500 225090 207000) in a freely resizable window (so no fixed width or height) and need to calculate the currently visible viewport in internal coordinates. To do so, one of the following functions would be necessary: *) a function that will translate screen pixels in internal coordinates - feed it with (0/0) and (getInnerWidth()/getInnerHeight()) and I should have the current viewport. Also handy for translating mouse position *) a function giving me the current center of the visible area, then add/sub half the translated width/height and have the rect *) etc. Currently I have a working attempt with the second idea, but it won't work on zooming, as I'm unable to properly factor currentScale in - thus it only works properly at 1x zoom. Basically this is what I'm currently doing: ----- viewbox = new String(svgdoc.getAttribute("viewBox")); viewboxes = viewbox.split(' '); centerX = Math.abs(parseFloat(viewboxes[0]) + parseFloat((viewboxes[2] / 2))); centerY = Math.abs(parseFloat(viewboxes[1]) + parseFloat((viewboxes[3] / 2))); transPixWidth = viewboxes[2] / getInnerWidth(); transPixHeight = viewboxes[3] / getInnerHeight(); // the / currentScale is just experimental and at least causes the calced viewport // to be statically offset wrongly factor = Math.max(transPixHeight, transPixWidth) / svgdoc.currentScale; // upper left corner centerX - (svgdoc.currentTranslate.getX() + getInnerWidth() / 2) * factor, centerY + (svgdoc.currentTranslate.getY() - getInnerHeight() / 2) * factor, // width and height getInnerWidth() * factor, getInnerHeight() * factor, ----- It works fine in 1x, but when you go to 2x the "center" becomes the bottom right corner, but at 0,5x the center moves left and up a bit (though not to the viewport corner). I guess one of you pros is able to sort it out quickly and would sincerly appreciate your help. Thanks a lot in advance, regards, Karim
Received on Sunday, 10 July 2005 10:06:03 UTC