You can get those values by simply reading the x, y, and viewport values of svgNode. Here is how you do it.
I am modifying the same code so that you can read all values.

function whatever()
{

        //reference to entire document
     var svgdoc = document.rootElement.getOwnerDocument();
     

         //reference to <svg......> tag
        var svgtag = svgdoc.getDocumentElement();

        /*******************************************/
        //CODE FOR GETTING VIEWPORT VALUES
        /*******************************************/
        var docX = svgtag.getAttribute("x");
        var docY = svgtag.getAttribute("y");
        var docWidth = svgtag.getAttribute("widht");
        var docWidth = svgtag.getAttribute("height");


        /*******************************************/
        //CODE FOR GETTING VIEWBOX VALUES
        /*******************************************/
        //returns viewBox value as string
     var vBox = svgtag.getAttribute("viewBox");

      //splits string into array separated by space
        var vBoxArray = vBox.split(/ /);
     var minX = parseInt(vBoxArray[0]);
     var minY = parseInt(vBoxArray[1]);

       
        //by adding width to minX you can get maxX
     var width = parseInt(vBoxArray[2]);

       
        //by adding hegith to minY you can getmaxY
       var height = parseInt(vBoxArray[3]);

}


Irfan Ali
Software Developer
Universal Map, Inc.
www.universalmap.com
Ph: (517)655-1759




"Christian Kindler" <[EMAIL PROTECTED]>

12/03/2002 03:59 AM
Please respond to "Batik Users"

       
        To:        "Batik Users" <[EMAIL PROTECTED]>
        cc:        
        Subject:        Antwort: Re: how to get the min/max coordinates of an SVG document




I mean the absolute top-left X, Y and bottom-right X, Y of the whole SVG
document
(including what is NOT visible on the screen).

Christian





Do you mean the top-left X, Y and bottom-right X, Y of SVG Document thats
visible on screen?

If yes all you need to do is read the viewBox values. Here is a little
javascript code that does this.

function whatever()
{
       var svgdoc = document.rootElement.getOwnerDocument(); //reference
to entire document
       var svgtag = svgdoc.getDocumentElement(); //reference to <svg
......> tag

       var vBox = svgtag.getAttribute("viewBox"); //returns viewBox value
as string
       var vBoxArray = vBox.split(/ /); //splits string into array
separated by space
       var minX = parseInt(vBoxArray[0]);
       var minY = parseInt(vBoxArray[1]);
       var width = parseInt(vBoxArray[2]); //by adding width to minX you
can get maxX
       var height = parseInt(vBoxArray[3]); //by adding hegith to minY you
can getmaxY
}

Hope this will help.

Irfan Ali
Software Developer
Universal Map, Inc.
www.universalmap.com
Ph: (517)655-1759




Hello,

I need to know the minimum and maximum coordinates of an SVG document or
in other words: what are the lowest and highest x and y values in a whole
document.
My only idea is to parse all the elements, get the coordinates and
calculate the
min and max values, but that seems very costly to me so how can I fetch
minX, minY,
maxX, maxY easier?

Christian






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]








---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to