svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / symbol / SymbolUtils.java @ 45526
History | View | Annotate | Download (1.94 KB)
1 | 40911 | jldominguez | package org.gvsig.labeling.symbol; |
---|---|---|---|
2 | |||
3 | import org.gvsig.fmap.mapcontext.MapContext; |
||
4 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
5 | import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
||
6 | |||
7 | public class SymbolUtils { |
||
8 | |||
9 | /**
|
||
10 | * Calculates the distance in pixels corresponding to the provided length,
|
||
11 | * according to the current rendering context (output dpi, map scale, map units) and the
|
||
12 | * symbol cartographic settings (unit, size, and unit reference system).
|
||
13 | *
|
||
14 | * @param cartographicElement CartographicSupport object which contains the reference system
|
||
15 | * and the measuring units for the provided length
|
||
16 | * @param length The length to be computed in pixels. The length is supposed to be
|
||
17 | * provided in the units defined in the cartographicElement
|
||
18 | * @param viewPort The viewport, which defines the relationship between pixels and maps units
|
||
19 | * @param dpi The resolution (dots per inch) of the target display device
|
||
20 | * (printer, screen, etc)
|
||
21 | * @return The distance in pixels corresponding to the provided length
|
||
22 | */
|
||
23 | public static double getCartographicLength( |
||
24 | CartographicSupport cartographicElement, |
||
25 | double length, ViewPort viewPort, double dpi) { |
||
26 | |||
27 | int unit = cartographicElement.getUnit();
|
||
28 | double lengthInPixel = length;
|
||
29 | |||
30 | if (unit != -1) { |
||
31 | double[] trans2Meter=MapContext.getDistanceTrans2Meter(); |
||
32 | if (cartographicElement.getReferenceSystem() == CartographicSupport.WORLD) {
|
||
33 | double dist1PixelInMeters = viewPort.getDist1pixel()*trans2Meter[viewPort.getMapUnits()];
|
||
34 | double realWidthMeter = length*trans2Meter[unit];
|
||
35 | lengthInPixel = realWidthMeter/dist1PixelInMeters; |
||
36 | } else if (cartographicElement.getReferenceSystem() == CartographicSupport.PAPER) { |
||
37 | double lengthInInches = 1/trans2Meter[7]*trans2Meter[unit]*length; |
||
38 | lengthInPixel = lengthInInches*dpi; |
||
39 | } |
||
40 | } else{
|
||
41 | double scale=dpi/72; |
||
42 | lengthInPixel=lengthInPixel*scale; |
||
43 | } |
||
44 | return (lengthInPixel);
|
||
45 | |||
46 | } |
||
47 | } |