svn-gvsig-desktop / trunk / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / fmap / layers / LayerScaleData.java @ 8707
History | View | Annotate | Download (3.8 KB)
1 |
package es.prodevelop.cit.gvsig.arcims.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
|
5 |
import org.apache.log4j.Logger; |
6 |
import org.gvsig.remoteClient.arcims.ArcImsProtocolHandler; |
7 |
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags; |
8 |
|
9 |
/**
|
10 |
* This class keeps a simple layer scale limits data.
|
11 |
*
|
12 |
* @author jldominguez
|
13 |
*
|
14 |
*/
|
15 |
public class LayerScaleData { |
16 |
|
17 |
private static Logger logger = Logger.getLogger(LayerScaleData.class.getName()); |
18 |
|
19 |
private final long Min_Allowed_Scale = 1; |
20 |
private final long Max_Allowed_Scale = 1000000000; |
21 |
|
22 |
public static Color imagYesColor = new Color(43, 185, 35); |
23 |
public static Color featYesColor = new Color(1, 51, 236); |
24 |
|
25 |
public static Color imagNoColor = new Color(175, 215, 123); |
26 |
public static Color featNoColor = new Color(164, 182, 249); |
27 |
|
28 |
public static Color unknownColor = new Color(210, 255, 210); |
29 |
|
30 |
private String name; |
31 |
private String id; |
32 |
private double maxSc; |
33 |
private double minSc; |
34 |
private String type; // LAYERTYPE_F, LAYERTYPE_I |
35 |
|
36 |
public LayerScaleData(String layerName, String layerId, long minScale, |
37 |
long maxScale, String theType) { |
38 |
|
39 |
name = layerName; |
40 |
id = layerId; |
41 |
maxSc = maxScale; |
42 |
minSc = minScale; |
43 |
if ((maxSc < 0.0) || (maxSc > Max_Allowed_Scale)) maxSc = 1.0 * Max_Allowed_Scale; |
44 |
if ((minSc < 0.0) || (minSc < Min_Allowed_Scale)) minSc = 1.0 * Min_Allowed_Scale; |
45 |
type = theType; |
46 |
} |
47 |
|
48 |
public String getId() { |
49 |
return id;
|
50 |
} |
51 |
|
52 |
public double getMaxSc() { |
53 |
return maxSc;
|
54 |
} |
55 |
|
56 |
public double getMinSc() { |
57 |
return minSc;
|
58 |
} |
59 |
|
60 |
public String getName() { |
61 |
return name;
|
62 |
} |
63 |
|
64 |
/**
|
65 |
* Gets the color depending on the type of layer and whether
|
66 |
* the current scale is inside the limits or not.
|
67 |
*
|
68 |
* @param current current scale
|
69 |
* @return the color to be used when painting the limits
|
70 |
*/
|
71 |
public Color getColor(double current) { |
72 |
|
73 |
Color resp = unknownColor;
|
74 |
// LAYERTYPE_F, LAYERTYPE_I
|
75 |
if (type.compareTo(ServiceInfoTags.vLAYERTYPE_F) == 0) { |
76 |
if (between(minSc, current, maxSc)) {
|
77 |
resp = featYesColor; |
78 |
} else {
|
79 |
resp = featNoColor; |
80 |
} |
81 |
} |
82 |
if (type.compareTo(ServiceInfoTags.vLAYERTYPE_I) == 0) { |
83 |
if (between(minSc, current, maxSc)) {
|
84 |
resp = imagYesColor; |
85 |
} else {
|
86 |
resp = imagNoColor; |
87 |
} |
88 |
} |
89 |
return resp;
|
90 |
} |
91 |
|
92 |
public static Color darker(Color c) { |
93 |
int r = c.getRed();
|
94 |
int g = c.getGreen();
|
95 |
int b = c.getBlue();
|
96 |
|
97 |
float f = (float) 0.7; |
98 |
Color newcolor = new Color( Math.round(r*f), Math.round(g*f),Math.round(b*f) ); |
99 |
return newcolor;
|
100 |
} |
101 |
|
102 |
public String getType() { |
103 |
return type;
|
104 |
} |
105 |
|
106 |
private boolean between(double a, double d, double b) { |
107 |
if ((a > b) && (d < b))
|
108 |
return false; |
109 |
if ((a > b) && (d > a))
|
110 |
return false; |
111 |
if ((a < b) && (d < a))
|
112 |
return false; |
113 |
if ((a < b) && (d > b))
|
114 |
return false; |
115 |
return true; |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Computes real scale from unit-dependant scale and the dpi.
|
120 |
*
|
121 |
* @param rs unit-dependant scale
|
122 |
* @param units units used
|
123 |
* @param theDpi
|
124 |
* @return the real scale (the <i>x</i> in "1:<i>x</i>")
|
125 |
*/
|
126 |
public static long getTrueScaleFromRelativeScaleAndMapUnits(double rs, String units, int theDpi) { |
127 |
// decimal_degrees | feet | meters
|
128 |
double fromMetersPerPixelToTrueScale = theDpi / ArcImsProtocolHandler.INCHES;
|
129 |
double fromDegreesPerPixelToTrueScale = fromMetersPerPixelToTrueScale * 40000000.0 / 360.0; |
130 |
double fromFeetPerPixelToTrueScale = fromMetersPerPixelToTrueScale * 0.3048; |
131 |
if (units.compareToIgnoreCase(ServiceInfoTags.vMAP_UNITS_FEET) == 0) { |
132 |
return Math.round( fromFeetPerPixelToTrueScale * rs ); |
133 |
} |
134 |
if (units.compareToIgnoreCase(ServiceInfoTags.vMAP_UNITS_METERS) == 0) { |
135 |
return Math.round( fromMetersPerPixelToTrueScale * rs ); |
136 |
} |
137 |
if (units.compareToIgnoreCase(ServiceInfoTags.vMAP_UNITS_DECIMAL_DEGREES) == 0) { |
138 |
return Math.round( fromDegreesPerPixelToTrueScale * rs ); |
139 |
} |
140 |
logger.error("Unable to compute true scale. Returned value: scale = 1:1");
|
141 |
return 1; |
142 |
} |
143 |
|
144 |
} |