You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Jean-Christophe Arnu <ar...@paratronic.fr> on 2005/06/22 12:20:53 UTC

getCurrentTranslate() getCurrentScale().... I'm confused!

Hi,
    on the confusing road of transforms (once again) I would like to 
know what is the coordinate system (element/user or viewport) I get 
while using getCurrentTranslate() getCurrentScale() methods on the 
document.getRootElement().

    If I'm logical this should be in "user" coordinate system.

    let's have an exemple :
   
    The SVG file :

 <?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN"
    
"http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd">
<svg xml:space="preserve" width="1024px" height="400px"
 viewBox="617621.000000 1782627.700000 413374.400000 358857.300000" >

<g id="Carte" style="font-size:12;" 
transform="matrix(1,0,0,-1,0,3924112.700000)" >
    <path id="GROUPMI2_departements_spcgd.MIF347" style="stroke:#000000; 
stroke-width:1pt; fill:#FFFFFF;"
    d="M  959623.800000 1993658.700000
    L 955234.300000 1995460.500000 L 949296.400000 1999757.000000 L 
948757.300000 2000779.400000
    L 948270.900000 2003277.200000 L 949176.900000 2005174.300000 L 
948661.900000 2007164.100000
    L 947876.400000 2011303.400000 L 942973.900000 2012090.400000 L 
941437.900000 2014017.500000
    L 939505.900000 2017164.300000 L 938962.000000 2018874.000000 L 
937748.800000 2021852.800000
    L 933878.700000 2022488.600000 L 932417.700000 2021047.300000 L 
928883.800000 2020497.200000
    L 927973.400000 2017042.300000 L 924260.500000 2014430.300000 L 
922952.400000 2015727.600000
    L 921750.700000 2015123.800000 L 920702.300000 2015901.600000 L 
917213.600000 2015931.800000
    L 917548.400000 2017193.600000 L 915345.200000 2020649.900000 L 
914143.600000 2020046.100000
    L 909364.300000 2021013.600000 L 906630.400000 2019064.600000 L 
906554.300000 2015932.300000
    L 904979.800000 2009383.400000 L 909955.900000 2007676.000000 L 
915118.700000 2007720.300000
    L 915526.700000 2004268.900000 L 917919.900000 2001733.800000 L 
917633.900000 2000222.000000
    L 918279.500000 1998532.700000 L 918070.800000 1992828.200000 L 
916236.000000 1991682.200000
    L 912867.900000 1994074.500000 L 909416.100000 1993644.600000 L 
907826.800000 1991508.800000
    L 905254.400000 1991982.000000 L 902630.700000 1991149.300000 L 
900107.200000 1991974.400000
    L 898829.200000 1990366.100000 L 894671.700000 1986829.400000 L 
891864.100000 1988618.500000
    L 890129.200000 1985518.400000 L 886047.300000 1984441.800000 L 
888285.100000 1982111.600000
    L 886137.300000 1981255.300000 L 885663.600000 1979973.800000 L 
883719.200000 1979063.200000
    L 880291.500000 1978093.500000 L 878763.800000 1978263.000000 L 
876591.800000 1979016.000000
    L 876703.000000 1976711.900000 L 875320.000000 1974157.000000 L 
875405.200000 1973224.400000
    L 876585.500000 1971371.500000 L 874978.000000 1969721.000000 L 
874012.800000 1967249.500000
    L 870732.700000 1968493.100000 L 870699.600000 1966682.500000 L 
869581.800000 1965984.400000
    L 865548.300000 1966887.600000 L 864766.400000 1966446.600000 L 
862410.100000 1966165.800000
    L 862230.700000 1964610.800000 L 862934.100000 1962235.200000 L 
862103.800000 1961547.100000
    L 860949.000000 1958562.900000 L 860121.700000 1957115.800000 L 
859001.200000 1954945.500000
    L 861160.300000 1953762.800000 L 862981.600000 1952085.300000 L 
864459.200000 1950330.700000
    L 863577.600000 1949887.700000 L 861760.100000 1949677.100000 L 
859773.000000 1945963.800000
    L 857243.300000 1946030.300000 L 853207.700000 1948464.100000 L 
851450.500000 1948341.700000
    L 848254.800000 1948846.700000 L 849014.300000 1946139.600000 L 
848301.500000 1945425.500000
    L 848870.500000 1943099.500000 L 851270.100000 1941711.200000 L 
849588.600000 1940803.500000
    L 845247.300000 1940431.800000 L 846490.800000 1939612.800000 L 
847244.900000 1935342.000000
    L 849212.400000 1934782.000000 L 849883.500000 1933124.500000 L 
851889.200000 1931771.700000
    L 853975.000000 1932989.000000 L 855694.400000 1932112.600000 L 
856631.100000 1931080.000000
    L 857610.300000 1931618.700000 L 862626.400000 1931706.000000 L 
861630.100000 1929067.600000
    L 863362.100000 1927926.900000 L 863293.700000 1925892.900000 L 
864641.700000 1924292.400000
    L 866003.200000 1925100.200000 L 867497.300000 1923988.300000 L 
866355.200000 1921701.700000
    L 867026.700000 1918252.800000 L 867586.000000 1916573.100000 L 
868482.500000 1915269.400000
    L 871710.800000 1916830.400000 L 875178.000000 1917321.400000 L 
877414.700000 1918439.200000
    L 880136.400000 1916914.500000 L 883061.100000 1916221.400000 L 
885368.100000 1916318.300000
    L 885851.800000 1917995.200000 L 884056.000000 1918493.800000 L 
882679.600000 1920578.200000
    L 879435.100000 1923731.300000 L 879413.800000 1924602.900000 L 
880026.300000 1928793.100000
    L 882412.700000 1926121.700000 L 882963.700000 1925717.300000 L 
886452.300000 1923774.100000
    L 886711.100000 1925516.700000 L 885751.600000 1927199.100000 L 
886872.600000 1927665.600000
    L 886590.800000 1928675.000000 L 886645.700000 1929744.800000 L 
885221.300000 1930257.300000
    L 885182.900000 1932635.200000 L 886480.700000 1933160.200000 L 
886698.800000 1933596.900000
    L 888355.500000 1938214.200000 L 889402.300000 1939695.900000 L 
890004.900000 1940869.300000
    L 892403.400000 1941671.500000 L 894249.100000 1943195.900000 L 
894515.700000 1944277.300000
    L 895929.900000 1945671.000000 L 896275.400000 1945680.200000 L 
897339.600000 1945446.300000
    L 896922.400000 1946792.700000 L 897787.700000 1948369.700000 L 
901187.800000 1948252.100000
    L 903694.600000 1947354.400000 L 903834.000000 1945702.900000 L 
904568.400000 1945069.600000
    L 905328.800000 1945133.300000 L 905829.300000 1943729.100000 L 
910501.700000 1939557.800000
    L 912305.000000 1942506.200000 L 910332.600000 1947418.200000 L 
912873.300000 1948020.800000
    L 914891.900000 1949513.600000 L 915881.800000 1948889.800000 L 
917524.000000 1948529.000000
    L 917946.300000 1951336.100000 L 918550.800000 1952535.200000 L 
920131.900000 1954716.000000
    L 920353.700000 1953712.800000 L 923767.600000 1951387.200000 L 
925022.900000 1949384.400000
    L 926224.800000 1950169.500000 L 927474.100000 1949303.600000 L 
928557.000000 1947744.100000
    L 930148.500000 1947935.600000 L 932262.300000 1947319.900000 L 
937002.000000 1947271.300000
    L 941986.100000 1947740.800000 L 942164.900000 1951945.300000 L 
944497.100000 1953929.300000
    L 945308.300000 1956967.400000 L 945011.800000 1958952.700000 L 
949606.300000 1960016.000000
    L 950941.300000 1961962.800000 L 952122.300000 1962317.600000 L 
953268.900000 1964799.700000
    L 954269.200000 1964268.200000 L 954526.700000 1965262.900000 L 
955638.900000 1965462.800000
    L 958130.500000 1966527.100000 L 960339.600000 1968394.100000 L 
961796.100000 1970742.200000
    L 965986.500000 1972206.900000 L 969461.300000 1976538.500000 L 
975359.100000 1976377.500000
    L 974651.600000 1979793.700000 L 971755.400000 1981349.600000 L 
969541.900000 1987478.500000
    L 970686.900000 1991641.500000 L 969660.900000 1992106.300000 L 
963274.200000 1995434.300000
    L 962548.100000 1994577.700000     z"/>
</g>
</svg>

I use then zoom + pan interactor to view a part of this document.
When I apply getCurrentTranslate() I get the following point :  
-6124.4717,-2116.2705
and getCurrentScale() : 7.4779873


What is the currentTranslate/scale coordinate system space?
How do I get real (cartographic) data (the one the viewBox is expressed 
in) from my translation and scale?

I guess scale is ok (real zoom)
But what about the translate? (IIRC, I have to make some calculation 
adding/substracting the viewBox coordinates). Are these translate/scale 
bound to the viewport size or is it independant?

Does screenCTM has some relations to this?


I'm quite confused, I hope someone could give me some path to follow to 
avoid asking such confused/dumb questions.

Thanks !

-- 
Jean-Christophe Arnu
Paratronic


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: getCurrentTranslate() getCurrentScale().... I'm confused!

Posted by Thomas DeWeese <Th...@Kodak.com>.
Jean-Christophe Arnu wrote:

>    on the confusing road of transforms (once again) I would like to know 
> what is the coordinate system (element/user or viewport) I get while 
> using getCurrentTranslate() getCurrentScale() methods on the 
> document.getRootElement().
> 
>    If I'm logical this should be in "user" coordinate system.

   Current scale/translate is roughly the mapping between screen
pixels and the width/height attributes on the root svg Element.

>      The SVG file: [...]
> <svg xml:space="preserve" width="1024px" height="400px"
> viewBox="617621.000000 1782627.700000 413374.400000 358857.300000" >

> I use then zoom + pan interactor to view a part of this document.
> When I apply getCurrentTranslate() I get the following point :  
> -6124.4717,-2116.2705
> and getCurrentScale() : 7.4779873
> 
> What is the currentTranslate/scale coordinate system space?
> How do I get real (cartographic) data (the one the viewBox is expressed 
> in) from my translation and scale?

    Use getScreenCTM on the root SVG element.  This will give you
the matrix from the userspace (after the application of the viewBox)
to screen pixels.  You can then use the inverse of this
(SVGMatrix.inverse()) to get the mapping from Screen to userspace.

> I guess scale is ok (real zoom)
> But what about the translate? (IIRC, I have to make some calculation 
> adding/substracting the viewBox coordinates). Are these translate/scale 
> bound to the viewport size or is it independant?

    It is independent you could roughly divide the translate by the
scale to get the translation in terms of the width and height of
the SVG element (so you would have been looking at the lower right
hand corner of the content).

> Does screenCTM has some relations to this?

    screenCTM is what you really want.  Most people don't need
to muck with currentScale/Translate other than to tie into the
UserAgent's pan/zoom facilities.

> I'm quite confused, I hope someone could give me some path to follow to 
> avoid asking such confused/dumb questions.

    Well all of this is explained in the SVG specification.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org