svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.image.extension / src / main / java / org / gvsig / arcims / image / fmap / layers / LayerScaleData.java @ 32321
History | View | Annotate | Download (6 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 Prodevelop S.L. main development
|
26 |
* http://www.prodevelop.es
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.arcims.image.fmap.layers; |
30 |
|
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
import org.gvsig.remoteclient.arcims.ArcImsProtocolHandler; |
34 |
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags; |
35 |
|
36 |
import java.awt.Color; |
37 |
|
38 |
|
39 |
/**
|
40 |
* This class keeps a simple layer scale limits data.
|
41 |
*
|
42 |
* @author jldominguez
|
43 |
*
|
44 |
*/
|
45 |
public class LayerScaleData { |
46 |
|
47 |
private static Logger logger = LoggerFactory.getLogger(LayerScaleData.class.getName()); |
48 |
public static Color imagYesColor = new Color(43, 185, 35); |
49 |
public static Color featYesColor = new Color(1, 51, 236); |
50 |
public static Color imagNoColor = new Color(175, 215, 123); |
51 |
public static Color featNoColor = new Color(164, 182, 249); |
52 |
public static Color unknownColor = new Color(210, 255, 210); |
53 |
private final long Min_Allowed_Scale = 1; |
54 |
private final long Max_Allowed_Scale = 1000000000; |
55 |
private String name; |
56 |
private String id; |
57 |
private double maxSc; |
58 |
private double minSc; |
59 |
private String type; // LAYERTYPE_F, LAYERTYPE_I |
60 |
|
61 |
/**
|
62 |
*
|
63 |
* @param layerName
|
64 |
* @param layerId
|
65 |
* @param minScale
|
66 |
* @param maxScale
|
67 |
* @param theType
|
68 |
*/
|
69 |
public LayerScaleData(String layerName, String layerId, long minScale, |
70 |
long maxScale, String theType) { |
71 |
name = layerName; |
72 |
id = layerId; |
73 |
maxSc = maxScale; |
74 |
minSc = minScale; |
75 |
|
76 |
if ((maxSc < 0.0) || (maxSc > Max_Allowed_Scale)) { |
77 |
maxSc = 1.0 * Max_Allowed_Scale;
|
78 |
} |
79 |
|
80 |
if ((minSc < 0.0) || (minSc < Min_Allowed_Scale)) { |
81 |
minSc = 1.0 * Min_Allowed_Scale;
|
82 |
} |
83 |
|
84 |
type = theType; |
85 |
} |
86 |
|
87 |
/**
|
88 |
*
|
89 |
* @return
|
90 |
*/
|
91 |
public String getId() { |
92 |
return id;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
*
|
97 |
* @return
|
98 |
*/
|
99 |
public double getMaxSc() { |
100 |
return maxSc;
|
101 |
} |
102 |
|
103 |
/**
|
104 |
*
|
105 |
* @return
|
106 |
*/
|
107 |
public double getMinSc() { |
108 |
return minSc;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
*
|
113 |
* @return
|
114 |
*/
|
115 |
public String getName() { |
116 |
return name;
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* Gets the color depending on the type of layer and whether
|
121 |
* the current scale is inside the limits or not.
|
122 |
*
|
123 |
* @param current current scale
|
124 |
* @return the color to be used when painting the limits
|
125 |
*/
|
126 |
public Color getColor(double current) { |
127 |
Color resp = unknownColor;
|
128 |
|
129 |
// LAYERTYPE_F, LAYERTYPE_I
|
130 |
if (type.compareTo(ServiceInfoTags.vLAYERTYPE_F) == 0) { |
131 |
if (between(minSc, current, maxSc)) {
|
132 |
resp = featYesColor; |
133 |
} |
134 |
else {
|
135 |
resp = featNoColor; |
136 |
} |
137 |
} |
138 |
|
139 |
if (type.compareTo(ServiceInfoTags.vLAYERTYPE_I) == 0) { |
140 |
if (between(minSc, current, maxSc)) {
|
141 |
resp = imagYesColor; |
142 |
} |
143 |
else {
|
144 |
resp = imagNoColor; |
145 |
} |
146 |
} |
147 |
|
148 |
return resp;
|
149 |
} |
150 |
|
151 |
/**
|
152 |
*
|
153 |
* @param c
|
154 |
* @return
|
155 |
*/
|
156 |
public static Color darker(Color c) { |
157 |
int r = c.getRed();
|
158 |
int g = c.getGreen();
|
159 |
int b = c.getBlue();
|
160 |
|
161 |
float f = (float) 0.7; |
162 |
Color newcolor = new Color(Math.round(r * f), Math.round(g * f), |
163 |
Math.round(b * f));
|
164 |
|
165 |
return newcolor;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
*
|
170 |
* @return
|
171 |
*/
|
172 |
public String getType() { |
173 |
return type;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
*
|
178 |
* @param a
|
179 |
* @param d
|
180 |
* @param b
|
181 |
* @return
|
182 |
*/
|
183 |
private boolean between(double a, double d, double b) { |
184 |
if ((a > b) && (d < b)) {
|
185 |
return false; |
186 |
} |
187 |
|
188 |
if ((a > b) && (d > a)) {
|
189 |
return false; |
190 |
} |
191 |
|
192 |
if ((a < b) && (d < a)) {
|
193 |
return false; |
194 |
} |
195 |
|
196 |
if ((a < b) && (d > b)) {
|
197 |
return false; |
198 |
} |
199 |
|
200 |
return true; |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Computes real scale from unit-dependant scale and the dpi.
|
205 |
*
|
206 |
* @param rs unit-dependant scale
|
207 |
* @param units units used
|
208 |
* @param theDpi
|
209 |
* @return the real scale (the <i>x</i> in "1:<i>x</i>")
|
210 |
*/
|
211 |
public static long getTrueScaleFromRelativeScaleAndMapUnits(double rs, |
212 |
String units, int theDpi) { |
213 |
// decimal_degrees | feet | meters
|
214 |
double fromMetersPerPixelToTrueScale = theDpi / ArcImsProtocolHandler.INCHES;
|
215 |
double fromDegreesPerPixelToTrueScale = (fromMetersPerPixelToTrueScale * 40000000.0) / 360.0; |
216 |
double fromFeetPerPixelToTrueScale = fromMetersPerPixelToTrueScale * 0.3048; |
217 |
|
218 |
if (units.compareToIgnoreCase(ServiceInfoTags.vMAP_UNITS_FEET) == 0) { |
219 |
return Math.round(fromFeetPerPixelToTrueScale * rs); |
220 |
} |
221 |
|
222 |
if (units.compareToIgnoreCase(ServiceInfoTags.vMAP_UNITS_METERS) == 0) { |
223 |
return Math.round(fromMetersPerPixelToTrueScale * rs); |
224 |
} |
225 |
|
226 |
if (units.compareToIgnoreCase(
|
227 |
ServiceInfoTags.vMAP_UNITS_DECIMAL_DEGREES) == 0) {
|
228 |
return Math.round(fromDegreesPerPixelToTrueScale * rs); |
229 |
} |
230 |
|
231 |
logger.error( |
232 |
"Unable to compute true scale. Returned value: scale = 1:1");
|
233 |
|
234 |
return 1; |
235 |
} |
236 |
} |