svn-gvsig-desktop / tags / v1_11_0_Build_1306 / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / fmap / layers / LayerScaleData.java @ 35731
History | View | Annotate | Download (5.81 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
package es.prodevelop.cit.gvsig.arcims.fmap.layers; |
44 |
|
45 |
import org.apache.log4j.Logger; |
46 |
|
47 |
import org.gvsig.remoteClient.arcims.ArcImsProtocolHandler; |
48 |
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags; |
49 |
|
50 |
import java.awt.Color; |
51 |
|
52 |
|
53 |
/**
|
54 |
* This class keeps a simple layer scale limits data.
|
55 |
*
|
56 |
* @author jldominguez
|
57 |
*
|
58 |
*/
|
59 |
public class LayerScaleData { |
60 |
private static Logger logger = Logger.getLogger(LayerScaleData.class.getName()); |
61 |
public static Color imagYesColor = new Color(43, 185, 35); |
62 |
public static Color featYesColor = new Color(1, 51, 236); |
63 |
public static Color imagNoColor = new Color(175, 215, 123); |
64 |
public static Color featNoColor = new Color(164, 182, 249); |
65 |
public static Color unknownColor = new Color(210, 255, 210); |
66 |
private final long Min_Allowed_Scale = 1; |
67 |
private final long Max_Allowed_Scale = 1000000000; |
68 |
private String name; |
69 |
private String id; |
70 |
private double maxSc; |
71 |
private double minSc; |
72 |
private String type; // LAYERTYPE_F, LAYERTYPE_I |
73 |
|
74 |
public LayerScaleData(String layerName, String layerId, long minScale, |
75 |
long maxScale, String theType) { |
76 |
name = layerName; |
77 |
id = layerId; |
78 |
maxSc = maxScale; |
79 |
minSc = minScale; |
80 |
|
81 |
if ((maxSc < 0.0) || (maxSc > Max_Allowed_Scale)) { |
82 |
maxSc = 1.0 * Max_Allowed_Scale;
|
83 |
} |
84 |
|
85 |
if ((minSc < 0.0) || (minSc < Min_Allowed_Scale)) { |
86 |
minSc = 1.0 * Min_Allowed_Scale;
|
87 |
} |
88 |
|
89 |
type = theType; |
90 |
} |
91 |
|
92 |
public String getId() { |
93 |
return id;
|
94 |
} |
95 |
|
96 |
public double getMaxSc() { |
97 |
return maxSc;
|
98 |
} |
99 |
|
100 |
public double getMinSc() { |
101 |
return minSc;
|
102 |
} |
103 |
|
104 |
public String getName() { |
105 |
return name;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Gets the color depending on the type of layer and whether
|
110 |
* the current scale is inside the limits or not.
|
111 |
*
|
112 |
* @param current current scale
|
113 |
* @return the color to be used when painting the limits
|
114 |
*/
|
115 |
public Color getColor(double current) { |
116 |
Color resp = unknownColor;
|
117 |
|
118 |
// LAYERTYPE_F, LAYERTYPE_I
|
119 |
if (type.compareTo(ServiceInfoTags.vLAYERTYPE_F) == 0) { |
120 |
if (between(minSc, current, maxSc)) {
|
121 |
resp = featYesColor; |
122 |
} |
123 |
else {
|
124 |
resp = featNoColor; |
125 |
} |
126 |
} |
127 |
|
128 |
if (type.compareTo(ServiceInfoTags.vLAYERTYPE_I) == 0) { |
129 |
if (between(minSc, current, maxSc)) {
|
130 |
resp = imagYesColor; |
131 |
} |
132 |
else {
|
133 |
resp = imagNoColor; |
134 |
} |
135 |
} |
136 |
|
137 |
return resp;
|
138 |
} |
139 |
|
140 |
public static Color darker(Color c) { |
141 |
int r = c.getRed();
|
142 |
int g = c.getGreen();
|
143 |
int b = c.getBlue();
|
144 |
|
145 |
float f = (float) 0.7; |
146 |
Color newcolor = new Color(Math.round(r * f), Math.round(g * f), |
147 |
Math.round(b * f));
|
148 |
|
149 |
return newcolor;
|
150 |
} |
151 |
|
152 |
public String getType() { |
153 |
return type;
|
154 |
} |
155 |
|
156 |
private boolean between(double a, double d, double b) { |
157 |
if ((a > b) && (d < b)) {
|
158 |
return false; |
159 |
} |
160 |
|
161 |
if ((a > b) && (d > a)) {
|
162 |
return false; |
163 |
} |
164 |
|
165 |
if ((a < b) && (d < a)) {
|
166 |
return false; |
167 |
} |
168 |
|
169 |
if ((a < b) && (d > b)) {
|
170 |
return false; |
171 |
} |
172 |
|
173 |
return true; |
174 |
} |
175 |
|
176 |
/**
|
177 |
* Computes real scale from unit-dependant scale and the dpi.
|
178 |
*
|
179 |
* @param rs unit-dependant scale
|
180 |
* @param units units used
|
181 |
* @param theDpi
|
182 |
* @return the real scale (the <i>x</i> in "1:<i>x</i>")
|
183 |
*/
|
184 |
public static long getTrueScaleFromRelativeScaleAndMapUnits(double rs, |
185 |
String units, int theDpi) { |
186 |
// decimal_degrees | feet | meters
|
187 |
double fromMetersPerPixelToTrueScale = theDpi / ArcImsProtocolHandler.INCHES;
|
188 |
double fromDegreesPerPixelToTrueScale = (fromMetersPerPixelToTrueScale * 40000000.0) / 360.0; |
189 |
double fromFeetPerPixelToTrueScale = fromMetersPerPixelToTrueScale * 0.3048; |
190 |
|
191 |
if (units.compareToIgnoreCase(ServiceInfoTags.vMAP_UNITS_FEET) == 0) { |
192 |
return Math.round(fromFeetPerPixelToTrueScale * rs); |
193 |
} |
194 |
|
195 |
if (units.compareToIgnoreCase(ServiceInfoTags.vMAP_UNITS_METERS) == 0) { |
196 |
return Math.round(fromMetersPerPixelToTrueScale * rs); |
197 |
} |
198 |
|
199 |
if (units.compareToIgnoreCase(
|
200 |
ServiceInfoTags.vMAP_UNITS_DECIMAL_DEGREES) == 0) {
|
201 |
return Math.round(fromDegreesPerPixelToTrueScale * rs); |
202 |
} |
203 |
|
204 |
logger.error( |
205 |
"Unable to compute true scale. Returned value: scale = 1:1");
|
206 |
|
207 |
return 1; |
208 |
} |
209 |
} |