Revision 44249 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/dynamiclegend/DefaultDynamicLabelingStrategy.java
DefaultDynamicLabelingStrategy.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend; |
7 | 7 |
|
8 |
import org.gvsig.labeling.dynamiclabeling.DynamicLabelingStrategy; |
|
8 | 9 |
import java.awt.Color; |
9 | 10 |
import java.awt.Font; |
10 | 11 |
import java.awt.Graphics2D; |
11 | 12 |
import java.awt.image.BufferedImage; |
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
import org.cresques.cts.ICoordTrans; |
|
16 |
import org.cresques.cts.IProjection; |
|
12 | 17 |
import org.gvsig.compat.print.PrintAttributes; |
18 |
import org.gvsig.expressionevaluator.Expression; |
|
19 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
20 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
|
21 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
22 |
import org.gvsig.fmap.dal.DALLocator; |
|
13 | 23 |
import org.gvsig.fmap.dal.exception.ReadException; |
24 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
|
25 |
import org.gvsig.fmap.dal.feature.Feature; |
|
26 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
27 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
28 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
29 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
14 | 30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
32 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
33 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
34 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
35 |
import org.gvsig.fmap.geom.primitive.Point; |
|
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
15 | 37 |
import org.gvsig.fmap.mapcontext.ViewPort; |
16 | 38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
40 |
import org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory; |
|
17 | 41 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
18 | 42 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
19 | 43 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IZoomConstraints; |
20 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy; |
|
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy; |
|
45 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy.MIN_TEXT_SIZE; |
|
46 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit; |
|
47 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol; |
|
48 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
49 |
import org.gvsig.tools.evaluator.Evaluator; |
|
50 |
import org.gvsig.tools.exception.BaseException; |
|
21 | 51 |
import org.gvsig.tools.persistence.PersistentState; |
22 | 52 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
23 | 53 |
import org.gvsig.tools.task.Cancellable; |
54 |
import org.slf4j.Logger; |
|
55 |
import org.slf4j.LoggerFactory; |
|
24 | 56 |
|
25 | 57 |
/** |
26 | 58 |
* |
... | ... | |
28 | 60 |
*/ |
29 | 61 |
public class DefaultDynamicLabelingStrategy extends DynamicLabelingStrategy { |
30 | 62 |
|
31 |
public DefaultDynamicLabelingStrategy() { |
|
32 |
super(); |
|
63 |
private Feature feature; |
|
64 |
public String LROTATION = "LROTATION"; |
|
65 |
public String LTEXT = "LTEXT"; |
|
66 |
public String LHEIGHT = "LHEIGHT"; |
|
67 |
public String LCOLOR = "LCOLOR"; |
|
68 |
public String LFONT = "LFONT"; |
|
69 |
public String LFONTSTYLE = "LFONTS"; |
|
70 |
private MutableSymbolTable symbolTable = null; |
|
71 |
private FLyrVect layer; |
|
72 |
private List<Geometry> drawnGeometryLabels; |
|
73 |
private boolean printMode = false; |
|
74 |
private IZoomConstraints zoom = null; |
|
75 |
private static final Logger logger = LoggerFactory.getLogger(AttrInTableLabelingStrategy.class); |
|
76 |
private int referenceSystem; |
|
77 |
private String textField; |
|
78 |
|
|
79 |
public SymbolTable getFeatureSymbolTable() { |
|
80 |
if (symbolTable == null) { |
|
81 |
MutableSymbolTable s = ExpressionEvaluatorLocator.getManager().createSymbolTable(); |
|
82 |
FeatureSymbolTable fst = DALLocator.getDataManager().createFeatureSymbolTable(); |
|
83 |
s.addSymbolTable(fst); |
|
84 |
fst.setFeature(feature); |
|
85 |
symbolTable = s; |
|
86 |
} |
|
87 |
return symbolTable; |
|
88 |
|
|
33 | 89 |
} |
34 | 90 |
|
91 |
private Expression getExpressionFromString(String value) { |
|
92 |
Expression expression = ExpressionEvaluatorLocator.getManager().createExpression(); |
|
93 |
expression.setPhrase(value); |
|
94 |
return expression; |
|
95 |
} |
|
96 |
|
|
97 |
private Object getValueFromExpression(Expression exp) { |
|
98 |
if (exp == null) { |
|
99 |
return null; |
|
100 |
} |
|
101 |
Object value = exp.execute(getFeatureSymbolTable()); |
|
102 |
return value; |
|
103 |
} |
|
104 |
|
|
105 |
public Object getComputedValue(String field) { |
|
106 |
Object value; |
|
107 |
value = feature.get(field); |
|
108 |
|
|
109 |
return value; |
|
110 |
} |
|
111 |
|
|
35 | 112 |
@Override |
36 |
public String getRotation() { |
|
37 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
113 |
public Expression getRotation() { |
|
114 |
String value = feature.get(LROTATION).toString(); |
|
115 |
Expression exp = getExpressionFromString(value); |
|
116 |
return exp; |
|
38 | 117 |
} |
39 | 118 |
|
40 | 119 |
@Override |
41 |
public String getText() { |
|
42 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
120 |
public int getComputedRotation() { |
|
121 |
Integer value = (Integer) getValueFromExpression(getRotation()); |
|
122 |
return value; |
|
43 | 123 |
} |
44 | 124 |
|
45 | 125 |
@Override |
46 |
public String getHeight() { |
|
47 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
126 |
public Expression getText() { |
|
127 |
if (feature == null) { |
|
128 |
return null; |
|
129 |
} |
|
130 |
String value = feature.get(LTEXT).toString(); |
|
131 |
Expression exp = getExpressionFromString(value); |
|
132 |
return exp; |
|
48 | 133 |
} |
49 | 134 |
|
50 | 135 |
@Override |
51 |
public String getColor() { |
|
52 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
136 |
public String getComputedText() { |
|
137 |
String value = (String) getValueFromExpression(getText()); |
|
138 |
return value; |
|
53 | 139 |
} |
54 | 140 |
|
55 | 141 |
@Override |
56 |
public double getFixedSize() { |
|
57 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
142 |
public Expression getHeight() { |
|
143 |
String value = feature.get(LHEIGHT).toString(); |
|
144 |
Expression exp = getExpressionFromString(value); |
|
145 |
return exp; |
|
58 | 146 |
} |
59 | 147 |
|
60 | 148 |
@Override |
149 |
public int getComputedHeight() { |
|
150 |
int value = (int) getValueFromExpression(getHeight()); |
|
151 |
return value; |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public Expression getColor() { |
|
156 |
String value = feature.get(LCOLOR).toString(); |
|
157 |
Expression exp = getExpressionFromString(value); |
|
158 |
return exp; |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
public Color getComputedColor() { |
|
163 |
int rgbcolor = (int) getColor().execute(getFeatureSymbolTable()); |
|
164 |
Color color = new Color(rgbcolor, true); |
|
165 |
return color; |
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
169 |
public Expression getFixedSize() { |
|
170 |
String value = feature.get(LHEIGHT).toString(); |
|
171 |
Expression exp = getExpressionFromString(value); |
|
172 |
return exp; |
|
173 |
} |
|
174 |
|
|
175 |
@Override |
|
176 |
public double getComputedFixedSize() { |
|
177 |
double value = (double) getValueFromExpression(getFixedSize()); |
|
178 |
return value; |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public int getComputedUnit() { |
|
183 |
int value = (int) getValueFromExpression(getUnitExp()); |
|
184 |
return value; |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
61 | 188 |
public void setTextField(String textFieldName) { |
62 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
189 |
this.LTEXT=textFieldName;
|
|
63 | 190 |
} |
64 | 191 |
|
65 | 192 |
@Override |
66 | 193 |
public void setRotationField(String rotationFieldName) { |
67 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
194 |
this.LROTATION=rotationFieldName;
|
|
68 | 195 |
} |
69 | 196 |
|
70 | 197 |
@Override |
71 | 198 |
public void setHeightField(String heightFieldName) { |
72 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
199 |
this.LHEIGHT=heightFieldName;
|
|
73 | 200 |
} |
74 | 201 |
|
75 | 202 |
@Override |
76 | 203 |
public void setColorField(String colorFieldName) { |
77 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
204 |
this.LCOLOR=colorFieldName;
|
|
78 | 205 |
} |
79 | 206 |
|
80 | 207 |
@Override |
... | ... | |
84 | 211 |
|
85 | 212 |
@Override |
86 | 213 |
public boolean usesFixedSize() { |
87 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
214 |
return false;
|
|
88 | 215 |
} |
89 | 216 |
|
90 | 217 |
@Override |
... | ... | |
99 | 226 |
|
100 | 227 |
@Override |
101 | 228 |
public boolean usesFixedColor() { |
102 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
229 |
return true;
|
|
103 | 230 |
} |
104 | 231 |
|
105 | 232 |
@Override |
106 |
public Color getFixedColor() { |
|
107 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
233 |
public Expression getFixedColor() { |
|
234 |
String value = feature.get(LCOLOR).toString(); |
|
235 |
Expression exp = getExpressionFromString(value); |
|
236 |
return exp; |
|
108 | 237 |
} |
109 | 238 |
|
110 | 239 |
@Override |
240 |
public Color getComputedFixedColor() { |
|
241 |
int rgbcolor = (int) getFixedColor().execute(getFeatureSymbolTable()); |
|
242 |
Color color = new Color(rgbcolor, true); |
|
243 |
return color; |
|
244 |
} |
|
245 |
|
|
246 |
@Override |
|
111 | 247 |
public void setFixedColor(Color fixedColor) { |
112 | 248 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
113 | 249 |
} |
114 | 250 |
|
115 | 251 |
@Override |
116 |
public Color getColorFont() { |
|
117 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
252 |
public Expression getColorFont() { |
|
253 |
String value = feature.get(LCOLOR).toString(); |
|
254 |
Expression exp = getExpressionFromString(value); |
|
255 |
return exp; |
|
118 | 256 |
} |
119 | 257 |
|
120 | 258 |
@Override |
259 |
public Color getComputedColorFont() { |
|
260 |
int rgbcolor = (int) getColorFont().execute(getFeatureSymbolTable()); |
|
261 |
Color color = new Color(rgbcolor, true); |
|
262 |
return color; |
|
263 |
} |
|
264 |
|
|
265 |
@Override |
|
121 | 266 |
public void setColorFont(Color colorFont) { |
122 | 267 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
123 | 268 |
} |
124 | 269 |
|
125 | 270 |
@Override |
126 |
public Font getFont() { |
|
127 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
271 |
public Expression getFont() { |
|
272 |
String value = feature.get(LFONT).toString(); |
|
273 |
Expression exp = getExpressionFromString(value); |
|
274 |
return exp; |
|
128 | 275 |
} |
129 | 276 |
|
130 | 277 |
@Override |
278 |
public Font getComputedFont() { |
|
279 |
String value = (String) getFont().execute(getFeatureSymbolTable()); |
|
280 |
Font font = new Font(value, getComputedFontStyle(), getComputedHeight()); |
|
281 |
return font; |
|
282 |
} |
|
283 |
|
|
284 |
@Override |
|
131 | 285 |
public void setFont(Font selFont) { |
132 | 286 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
133 | 287 |
} |
134 | 288 |
|
289 |
@Override |
|
290 |
public Expression getFontStyle() { |
|
291 |
String value = feature.get(LFONTSTYLE).toString(); |
|
292 |
Expression exp = getExpressionFromString(value); |
|
293 |
return exp; |
|
294 |
} |
|
295 |
|
|
296 |
@Override |
|
297 |
public int getComputedFontStyle() { |
|
298 |
int value = (int) getFontStyle().execute(getFeatureSymbolTable()); |
|
299 |
return value; |
|
300 |
} |
|
301 |
|
|
302 |
@Override |
|
303 |
public void setFontStyle(int selFont) { |
|
304 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
305 |
} |
|
306 |
|
|
307 |
public void setFeature(Feature f) { |
|
308 |
feature = f; |
|
309 |
} |
|
310 |
|
|
311 |
@Override |
|
312 |
public ILabelingMethod getLabelingMethod() { |
|
313 |
throw new UnsupportedOperationException("Not supported yet."); |
|
314 |
} |
|
315 |
|
|
316 |
@Override |
|
317 |
public void setLabelingMethod(ILabelingMethod method) { |
|
318 |
throw new UnsupportedOperationException("Not supported yet."); |
|
319 |
} |
|
320 |
|
|
321 |
@Override |
|
322 |
public IPlacementConstraints getPlacementConstraints() { |
|
323 |
throw new UnsupportedOperationException("Not supported yet."); |
|
324 |
} |
|
325 |
|
|
326 |
@Override |
|
327 |
public void setPlacementConstraints(IPlacementConstraints constraints) { |
|
328 |
throw new UnsupportedOperationException("Not supported yet."); |
|
329 |
} |
|
330 |
|
|
331 |
@Override |
|
332 |
public IZoomConstraints getZoomConstraints() { |
|
333 |
throw new UnsupportedOperationException("Not supported yet."); |
|
334 |
} |
|
335 |
|
|
336 |
@Override |
|
337 |
public void setZoomConstraints(IZoomConstraints constraints) { |
|
338 |
throw new UnsupportedOperationException("Not supported yet."); |
|
339 |
} |
|
340 |
|
|
341 |
@Override |
|
342 |
public Expression getUnitExp() { |
|
343 |
String value = "-1"; |
|
344 |
Expression exp = getExpressionFromString(value); |
|
345 |
return exp; |
|
346 |
} |
|
347 |
|
|
348 |
public Expression getReferenceSystemExp() { |
|
349 |
String value = "0"; |
|
350 |
Expression exp = getExpressionFromString(value); |
|
351 |
return exp; |
|
352 |
} |
|
353 |
|
|
354 |
private org.gvsig.fmap.geom.primitive.Point createLabelPoint(org.gvsig.fmap.geom.Geometry geom) |
|
355 |
throws CreateGeometryException { |
|
356 |
|
|
357 |
try { |
|
358 |
return geom.centroid(); |
|
359 |
} catch (GeometryOperationNotSupportedException e) { |
|
360 |
return null; |
|
361 |
} catch (GeometryOperationException e) { |
|
362 |
return null; |
|
363 |
} |
|
364 |
} |
|
365 |
|
|
366 |
@Override |
|
367 |
public void draw(BufferedImage mapImage, Graphics2D mapGraphics, double scale, ViewPort viewPort, Cancellable cancel, double dpi) throws ReadException { |
|
368 |
// double scale = getScale(viewPort, props); |
|
369 |
PrintAttributes props = null; |
|
370 |
if (layer == null) { |
|
371 |
return; |
|
372 |
} |
|
373 |
|
|
374 |
if (zoom == null |
|
375 |
|| (zoom.isUserDefined() && (scale >= zoom.getMaxScale()) |
|
376 |
&& (scale <= zoom.getMinScale()))) { |
|
377 |
FeatureSet set = null; |
|
378 |
DisposableIterator iterator = null; |
|
379 |
try { |
|
380 |
// AttrInTableLabelingStrategy.FilteredLogger logger = new AttrInTableLabelingStrategy.FilteredLogger(AttrInTableLabelingStrategy.logger, 10); |
|
381 |
|
|
382 |
// limit the labeling to the visible extent |
|
383 |
List<String> fields = new ArrayList<String>(); |
|
384 |
|
|
385 |
FeatureStore featureStore = layer.getFeatureStore(); |
|
386 |
ICoordTrans ct = layer.getCoordTrans(); |
|
387 |
|
|
388 |
String geomName = featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(); |
|
389 |
fields.add(LCOLOR); |
|
390 |
fields.add(LFONT); |
|
391 |
fields.add(LFONTSTYLE); |
|
392 |
fields.add(LHEIGHT); |
|
393 |
fields.add(LROTATION); |
|
394 |
fields.add(LTEXT); |
|
395 |
fields.add(geomName); |
|
396 |
|
|
397 |
FeatureQuery featureQuery = layer.createFeatureQuery(); |
|
398 |
|
|
399 |
if (viewPort.getAdjustedEnvelope().contains( |
|
400 |
layer.getFullEnvelope())) { |
|
401 |
/* |
|
402 |
* viewport contains layer completely |
|
403 |
*/ |
|
404 |
set = featureStore.getFeatureSet(featureQuery); |
|
405 |
} else { |
|
406 |
/* |
|
407 |
* view port does not contain layer completely |
|
408 |
*/ |
|
409 |
Evaluator iee = null; |
|
410 |
|
|
411 |
IProjection data_proj = null; |
|
412 |
Envelope env_in_store_crs = null; |
|
413 |
|
|
414 |
if (ct == null) { |
|
415 |
env_in_store_crs = viewPort.getAdjustedEnvelope(); |
|
416 |
data_proj = viewPort.getProjection(); |
|
417 |
} else { |
|
418 |
env_in_store_crs = viewPort.getAdjustedEnvelope().convert( |
|
419 |
ct.getInverted()); |
|
420 |
data_proj = ct.getPOrig(); |
|
421 |
} |
|
422 |
iee = SpatialEvaluatorsFactory.getInstance().intersects( |
|
423 |
env_in_store_crs, |
|
424 |
data_proj, |
|
425 |
featureStore |
|
426 |
); |
|
427 |
featureQuery.setAttributeNames((String[]) fields.toArray(new String[fields.size()])); |
|
428 |
featureQuery.setFilter(iee); |
|
429 |
set = featureStore.getFeatureSet(featureQuery); |
|
430 |
} |
|
431 |
|
|
432 |
/* |
|
433 |
* 'set' now has the features that have to be labeled |
|
434 |
*/ |
|
435 |
FeatureSelection selection = this.layer.getFeatureStore().getFeatureSelection(); |
|
436 |
iterator = set.fastIterator(); |
|
437 |
while (iterator.hasNext()) { |
|
438 |
if (cancel.isCanceled()) { |
|
439 |
return; |
|
440 |
} |
|
441 |
try { |
|
442 |
Feature feat = (Feature) iterator.next(); |
|
443 |
Geometry geom = feat.getDefaultGeometry(); |
|
444 |
if (geom == null) { |
|
445 |
continue; |
|
446 |
} |
|
447 |
|
|
448 |
double size = 0; |
|
449 |
Color color = null; |
|
450 |
this.setFeature(feat); |
|
451 |
if ("".equals(getComputedText())) { |
|
452 |
continue; |
|
453 |
} else if (getComputedText() == null) { |
|
454 |
continue; |
|
455 |
} |
|
456 |
|
|
457 |
SimpleTextSymbol sym = new SimpleTextSymbol(); |
|
458 |
sym.setFont(getComputedFont()); |
|
459 |
sym.setUnit(getComputedUnit()); |
|
460 |
sym.setReferenceSystem(getComputedReferenceSystemExp()); |
|
461 |
if (this.usesFixedSize()) { //(useFixedSize) { |
|
462 |
// uses fixed size |
|
463 |
size = getComputedFixedSize();// * fontScaleFactor; |
|
464 |
} else if (true) { //(getComputedHeight() ) { |
|
465 |
// text size is defined in the table |
|
466 |
size = getComputedHeight(); |
|
467 |
} else { |
|
468 |
// otherwise will use the size in the symbol |
|
469 |
size = sym.getFont().getSize(); |
|
470 |
} |
|
471 |
|
|
472 |
double the_dpi = viewPort.getDPI(); |
|
473 |
if (props != null) { |
|
474 |
int len = PrintAttributes.PRINT_QUALITY_DPI.length; |
|
475 |
int priq = props.getPrintQuality(); |
|
476 |
if (priq < 0 || priq >= len) { |
|
477 |
throw new ReadException(featureStore.getName(), |
|
478 |
new Exception("Bad print quality value: " + priq)); |
|
479 |
} else { |
|
480 |
the_dpi = PrintAttributes.PRINT_QUALITY_DPI[priq]; |
|
481 |
} |
|
482 |
} |
|
483 |
|
|
484 |
size = CartographicSupportToolkit.getCartographicLength(this, |
|
485 |
size, |
|
486 |
viewPort, |
|
487 |
the_dpi); |
|
488 |
if (size <= MIN_TEXT_SIZE) { |
|
489 |
// label is too small to be readable, will be skipped |
|
490 |
// this speeds up the rendering in wider zooms |
|
491 |
continue; |
|
492 |
} |
|
493 |
|
|
494 |
/* |
|
495 |
* ym.setFontSize(int) assumes dpi = 72 |
|
496 |
*/ |
|
497 |
double font_size = size * 72 / the_dpi; |
|
498 |
sym.setFontSize(font_size); |
|
499 |
|
|
500 |
// if (false) { //useFixedColor) { |
|
501 |
// color = getComputedFixedColor(); |
|
502 |
// } else if (true) { //colorFieldName != null) { |
|
503 |
// // text size is defined in the table |
|
504 |
if (selection.isSelected(feat)) { |
|
505 |
color = MapContext.getSelectionColor(); |
|
506 |
} else { |
|
507 |
color = getComputedColorFont(); |
|
508 |
} |
|
509 |
|
|
510 |
sym.setTextColor(color); |
|
511 |
|
|
512 |
if (ct != null) { |
|
513 |
/* |
|
514 |
* Reproject from store CRS to view CRS |
|
515 |
*/ |
|
516 |
geom = geom.cloneGeometry(); |
|
517 |
geom.reProject(ct); |
|
518 |
} |
|
519 |
|
|
520 |
Point p = null; |
|
521 |
// text rotation is defined in the table |
|
522 |
double rotation = -Math.toRadians(((Number) getComputedRotation()).doubleValue()); |
|
523 |
p = createLabelPoint(geom); |
|
524 |
|
|
525 |
sym.setText(getComputedText()); |
|
526 |
sym.setRotation(rotation); |
|
527 |
|
|
528 |
if (p != null) { |
|
529 |
if (props == null) { |
|
530 |
sym.draw(mapGraphics, viewPort.getAffineTransform(), p, feat, cancel); |
|
531 |
} else { |
|
532 |
sym.print(mapGraphics, viewPort.getAffineTransform(), p, props); |
|
533 |
} |
|
534 |
} |
|
535 |
} catch (Exception ex) { |
|
536 |
logger.warn("", ex); |
|
537 |
} |
|
538 |
} |
|
539 |
|
|
540 |
} catch (BaseException e) { |
|
541 |
throw new ReadException( |
|
542 |
"Could not draw annotation in the layer.", e); |
|
543 |
} finally { |
|
544 |
if (iterator != null) { |
|
545 |
iterator.dispose(); |
|
546 |
} |
|
547 |
if (set != null) { |
|
548 |
set.dispose(); |
|
549 |
} |
|
550 |
|
|
551 |
} |
|
552 |
|
|
553 |
} |
|
554 |
|
|
555 |
} |
|
556 |
|
|
557 |
@Override |
|
558 |
public void print(Graphics2D g, double scale, ViewPort viewPort, Cancellable cancel, PrintAttributes properties) throws ReadException { |
|
559 |
throw new UnsupportedOperationException("Not supported yet."); |
|
560 |
} |
|
561 |
|
|
562 |
@Override |
|
563 |
public String[] getUsedFields() { |
|
564 |
throw new UnsupportedOperationException("Not supported yet."); |
|
565 |
} |
|
566 |
|
|
567 |
@Override |
|
568 |
public void setLayer(FLayer flayer) { |
|
569 |
layer = (FLyrVect) flayer; |
|
570 |
} |
|
571 |
|
|
572 |
@Override |
|
573 |
public boolean shouldDrawLabels(double scale) { |
|
574 |
return true; |
|
575 |
} |
|
576 |
|
|
577 |
@Override |
|
578 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
579 |
throw new UnsupportedOperationException("Not supported yet."); |
|
580 |
} |
|
581 |
|
|
582 |
@Override |
|
583 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
584 |
throw new UnsupportedOperationException("Not supported yet."); |
|
585 |
} |
|
586 |
|
|
587 |
@Override |
|
588 |
public void setUnit(int unitIndex) { |
|
589 |
throw new UnsupportedOperationException("Not supported yet."); |
|
590 |
} |
|
591 |
|
|
592 |
@Override |
|
593 |
public int getUnit() { |
|
594 |
return getComputedUnitExp(); |
|
595 |
} |
|
596 |
|
|
597 |
public int getComputedUnitExp() { |
|
598 |
int value = (int) getValueFromExpression(getUnitExp()); |
|
599 |
return value; |
|
600 |
} |
|
601 |
|
|
602 |
public int getComputedReferenceSystemExp() { |
|
603 |
int value = (int) getValueFromExpression(getReferenceSystemExp()); |
|
604 |
return value; |
|
605 |
} |
|
606 |
|
|
607 |
@Override |
|
608 |
public int getReferenceSystem() { |
|
609 |
return 0; |
|
610 |
} |
|
611 |
|
|
612 |
@Override |
|
613 |
public void setReferenceSystem(int referenceSystem) { |
|
614 |
this.referenceSystem = referenceSystem; |
|
615 |
} |
|
616 |
|
|
617 |
@Override |
|
618 |
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
619 |
throw new UnsupportedOperationException("Not supported yet."); |
|
620 |
} |
|
621 |
|
|
622 |
@Override |
|
623 |
public void setCartographicSize(double cartographicSize, Geometry geom) { |
|
624 |
throw new UnsupportedOperationException("Not supported yet."); |
|
625 |
} |
|
626 |
|
|
627 |
@Override |
|
628 |
public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
629 |
throw new UnsupportedOperationException("Not supported yet."); |
|
630 |
} |
|
631 |
|
|
632 |
@Override |
|
633 |
public void setFontField(String fontField) { |
|
634 |
this.LFONT = fontField; |
|
635 |
} |
|
636 |
|
|
637 |
@Override |
|
638 |
public void setFontStyleField(String field) { |
|
639 |
this.LFONTSTYLE=field; |
|
640 |
} |
|
641 |
|
|
135 | 642 |
} |
Also available in: Unified diff