Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / impl / CartographicSupportToolkit.java @ 40560

History | View | Annotate | Download (3.36 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl;
25

    
26
import org.gvsig.fmap.mapcontext.MapContext;
27
import org.gvsig.fmap.mapcontext.ViewPort;
28
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
29

    
30

    
31

    
32
/**
33
 * @author jaume dominguez faus - jaume.dominguez@iver.es
34
 */
35
public class CartographicSupportToolkit {
36

    
37
        /**
38
         * Calculates the distance in pixels corresponding to the provided length,
39
         * according to the current rendering context (output dpi, map scale, map units) and the
40
         * symbol cartographic settings (unit, size, and unit reference system).
41
         *
42
         * @param cartographicElement CartographicSupport object which contains the reference system
43
         * and the measuring units for the provided length
44
         * @param length The length to be computed in pixels. The length is supposed to be
45
         * provided in the units defined in the cartographicElement
46
         * @param viewPort The viewport, which defines the relationship between pixels and maps units
47
         * @param dpi The resolution (dots per inch) of the target display device
48
         * (printer, screen, etc)
49
         * @return The distance in pixels corresponding to the provided length
50
         */
51
        public static double getCartographicLength(CartographicSupport cartographicElement, double length, ViewPort viewPort, double dpi) {
52
                int unit = cartographicElement.getUnit();
53
                double lengthInPixel = length;
54

    
55
                if (unit != -1) {
56
                        double[] trans2Meter=MapContext.getDistanceTrans2Meter();
57
                        if (cartographicElement.getReferenceSystem() == CartographicSupport.WORLD) {
58
                                double dist1PixelInMeters = viewPort.getDist1pixel()*trans2Meter[viewPort.getMapUnits()];
59
                                double realWidthMeter = length*trans2Meter[unit];
60
                                lengthInPixel = realWidthMeter/dist1PixelInMeters;
61
                        } else if (cartographicElement.getReferenceSystem() == CartographicSupport.PAPER) {
62
                                double lengthInInches = 1/trans2Meter[7]*trans2Meter[unit]*length;
63
                                lengthInPixel = lengthInInches*dpi;
64
                        }
65
                } else{
66
                        double scale=dpi/72;
67
                        lengthInPixel=lengthInPixel*scale;
68
                }
69
                return  (lengthInPixel);
70

    
71
        }
72

    
73
        /**
74
         * The unit that will be used when creating new symbols.<br>
75
         * <b>Factory defaults to pixel.</b>
76
         */
77
        public static int DefaultMeasureUnit = -1;
78
        /**
79
         * The reference system that will be used when creating new symbols.<br>
80
         * <b>Factory defaults to pixel.</b>
81
         */
82
        public static int DefaultReferenceSystem = CartographicSupport.WORLD;
83

    
84
}
85

    
86