Revision 42464 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/legend/impl/AbstractVectorialLegend.java
AbstractVectorialLegend.java | ||
---|---|---|
87 | 87 |
|
88 | 88 |
/** |
89 | 89 |
* Base implementation for Vectorial data Legends. |
90 |
*
|
|
90 |
* |
|
91 | 91 |
* Provides a draw method implementation which loads the {@link Feature}s and |
92 | 92 |
* uses the {@link ISymbol} objects to draw the {@link Geometry} objects. |
93 |
*
|
|
93 |
* |
|
94 | 94 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
95 | 95 |
*/ |
96 | 96 |
public abstract class AbstractVectorialLegend extends AbstractLegend implements |
97 | 97 |
IVectorLegend { |
98 |
|
|
98 |
|
|
99 | 99 |
private static final Logger LOG = LoggerFactory |
100 | 100 |
.getLogger(AbstractVectorialLegend.class); |
101 | 101 |
|
... | ... | |
123 | 123 |
this.zSort = zSort; |
124 | 124 |
addLegendListener(zSort); |
125 | 125 |
} |
126 |
|
|
126 |
|
|
127 | 127 |
@SuppressWarnings("unchecked") |
128 | 128 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
129 | 129 |
Cancellable cancel, double scale, Map queryParameters, |
... | ... | |
133 | 133 |
draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, |
134 | 134 |
featureStore, null, dpi); |
135 | 135 |
} |
136 |
|
|
136 |
|
|
137 | 137 |
@SuppressWarnings("unchecked") |
138 | 138 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
139 | 139 |
Cancellable cancel, double scale, Map queryParameters, |
... | ... | |
152 | 152 |
print(g, viewPort, cancel, scale, queryParameters, coordTrans, |
153 | 153 |
featureStore, null, properties); |
154 | 154 |
} |
155 |
|
|
155 |
|
|
156 | 156 |
@SuppressWarnings("unchecked") |
157 | 157 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
158 | 158 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
... | ... | |
178 | 178 |
|
179 | 179 |
int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1; |
180 | 180 |
for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) { |
181 |
|
|
181 |
|
|
182 | 182 |
Envelope vp_env_in_store_crs = null; |
183 | 183 |
IProjection store_crs = null; |
184 | 184 |
if (coordTrans != null) { |
... | ... | |
191 | 191 |
vp_env_in_store_crs = viewPort.getAdjustedEnvelope(); |
192 | 192 |
store_crs = viewPort.getProjection(); |
193 | 193 |
} |
194 |
|
|
194 |
|
|
195 | 195 |
FeatureQuery feat_query = fquery; |
196 | 196 |
Envelope store_env = featureStore.getEnvelope(); |
197 | 197 |
boolean use_intersection_cond = false; |
... | ... | |
205 | 205 |
use_intersection_cond = true; |
206 | 206 |
} |
207 | 207 |
} |
208 |
|
|
208 |
|
|
209 | 209 |
if (use_intersection_cond) { |
210 |
FeatureType ft = featureStore.getDefaultFeatureType();
|
|
210 |
FeatureType ft = featureStore.getDefaultFeatureType(); |
|
211 | 211 |
IntersectsEnvelopeEvaluator iee = |
212 | 212 |
new IntersectsEnvelopeEvaluator( |
213 | 213 |
vp_env_in_store_crs, |
... | ... | |
220 | 220 |
} |
221 | 221 |
feat_query.addFilter(iee); |
222 | 222 |
} |
223 |
|
|
223 |
|
|
224 | 224 |
// 'feat_query' can still be NULL here, so we only filter |
225 | 225 |
// the featureStore if it's not null |
226 | 226 |
if (feat_query == null) { |
... | ... | |
235 | 235 |
Geometry geom = feat.getDefaultGeometry(); |
236 | 236 |
if (geom==null) { |
237 | 237 |
continue; |
238 |
}
|
|
238 |
} |
|
239 | 239 |
// Reprojection if needed |
240 | 240 |
if (coordTrans != null) { |
241 | 241 |
geom = geom.cloneGeometry(); |
... | ... | |
363 | 363 |
} |
364 | 364 |
|
365 | 365 |
IProjection dataProjection; |
366 |
Envelope reprojectedDataEnvelop; |
|
367 |
|
|
366 |
Envelope dataEnvelope; |
|
367 |
Envelope reprojectedDataEnvelope; |
|
368 |
// Gets the view envelope |
|
369 |
Envelope viewPortEnvelope = viewPort.getAdjustedEnvelope(); |
|
370 |
Envelope reprojectedViewPortEnvelope; |
|
368 | 371 |
try { |
372 |
dataEnvelope = featureStore.getEnvelope(); |
|
369 | 373 |
if (coordTrans == null) { |
370 | 374 |
dataProjection = featureStore.getDefaultFeatureType() |
371 | 375 |
.getDefaultSRS(); |
... | ... | |
376 | 380 |
dataProjection = viewPort.getProjection(); |
377 | 381 |
} |
378 | 382 |
|
379 |
reprojectedDataEnvelop = featureStore.getEnvelope(); |
|
383 |
reprojectedDataEnvelope = dataEnvelope; |
|
384 |
reprojectedViewPortEnvelope = viewPortEnvelope; |
|
380 | 385 |
} else { |
381 | 386 |
dataProjection = coordTrans.getPOrig(); |
382 | 387 |
|
383 |
Envelope env = featureStore.getEnvelope(); |
|
384 |
if ( env!=null && !env.isEmpty()) { |
|
385 |
reprojectedDataEnvelop = env.convert(coordTrans); |
|
388 |
if ( dataEnvelope!=null && !dataEnvelope.isEmpty()) { |
|
389 |
reprojectedDataEnvelope = dataEnvelope.convert(coordTrans); |
|
386 | 390 |
} else { |
387 |
reprojectedDataEnvelop = env;
|
|
391 |
reprojectedDataEnvelope = dataEnvelope;
|
|
388 | 392 |
} |
393 |
if ( viewPortEnvelope!=null && !viewPortEnvelope.isEmpty()) { |
|
394 |
reprojectedViewPortEnvelope = viewPortEnvelope.convert(coordTrans.getInverted()); |
|
395 |
} else { |
|
396 |
reprojectedViewPortEnvelope = viewPortEnvelope; |
|
397 |
} |
|
389 | 398 |
} |
390 | 399 |
} catch (DataException e) { |
391 | 400 |
throw new LegendDrawingException(e); |
392 | 401 |
} |
393 | 402 |
|
394 |
// Gets the view envelope |
|
395 |
Envelope viewPortEnvelope = viewPort.getAdjustedEnvelope(); |
|
396 | 403 |
|
397 | 404 |
// Gets the data envelope with the viewport SRS |
398 |
Envelope myEnvelope = reprojectedDataEnvelop;
|
|
405 |
// Envelope myEnvelope = reprojectedDataEnvelope;
|
|
399 | 406 |
|
400 | 407 |
// TODO: in some cases, the legend may need a different check to |
401 | 408 |
// decide if the data must be drawn or not |
402 | 409 |
// Checks if the viewport envelope intersects with the data envelope |
403 |
if (!viewPortEnvelope.intersects(myEnvelope)) { |
|
410 |
// This condition may seem redundant, but sometimes the transformations may fail and cause false negatives. |
|
411 |
if (!viewPortEnvelope.intersects(reprojectedDataEnvelope) && !(reprojectedViewPortEnvelope.intersects(dataEnvelope))) { |
|
404 | 412 |
// The data is not visible in the current viewport, do nothing. |
405 | 413 |
return; |
406 | 414 |
} |
407 | 415 |
|
408 | 416 |
// Check if all the data is contained into the viewport envelope |
409 |
boolean containsAll = viewPortEnvelope.contains(myEnvelope); |
|
417 |
// This condition may seem redundant, but sometimes the transformations may fail and cause false negatives. |
|
418 |
boolean containsAll = viewPortEnvelope.contains(reprojectedDataEnvelope) || reprojectedViewPortEnvelope.contains(dataEnvelope); |
|
410 | 419 |
|
411 | 420 |
// Create the drawing notification to be reused on each iteration |
412 | 421 |
DefaultFeatureDrawnNotification drawnNotification = new DefaultFeatureDrawnNotification(); |
... | ... | |
463 | 472 |
boolean containsAll) throws DataException { |
464 | 473 |
|
465 | 474 |
featureQuery.setScale(scale); |
466 |
|
|
475 |
|
|
467 | 476 |
//Adds the attributes |
468 | 477 |
String[] fieldNames = getRequiredFeatureAttributeNames(featureStore); |
469 | 478 |
for (int i=0 ; i<fieldNames.length ;i++){ |
470 | 479 |
featureQuery.addAttributeName(fieldNames[i]); |
471 |
}
|
|
472 |
|
|
480 |
} |
|
481 |
|
|
473 | 482 |
// TODO: Mobile has it's own IntersectsEnvelopeEvaluator |
474 | 483 |
if (!containsAll) { |
475 | 484 |
// Gets the viewport envelope with the data SRS |
... | ... | |
490 | 499 |
featureStore.getDefaultFeatureType(), featureStore |
491 | 500 |
.getDefaultFeatureType() |
492 | 501 |
.getDefaultGeometryAttributeName()); |
493 |
featureQuery.addFilter(iee);
|
|
502 |
featureQuery.addFilter(iee); |
|
494 | 503 |
} |
495 | 504 |
if (queryParameters != null) { |
496 | 505 |
Iterator iterEntry = queryParameters.entrySet().iterator(); |
... | ... | |
500 | 509 |
featureQuery.setQueryParameter((String) entry.getKey(), |
501 | 510 |
entry.getValue()); |
502 | 511 |
} |
503 |
}
|
|
512 |
} |
|
504 | 513 |
return featureQuery; |
505 | 514 |
} |
506 | 515 |
|
... | ... | |
579 | 588 |
try { |
580 | 589 |
geom.reProject(coordTrans); |
581 | 590 |
} catch (ReprojectionRuntimeException re) { |
591 |
LOG.warn("Can't reproject geometry "+geom.toString(), re); |
|
592 |
return; |
|
593 |
|
|
582 | 594 |
/* |
583 | 595 |
* Library was unable to reproject |
584 | 596 |
* See reproject method in Point2D (geometry) |
585 | 597 |
*/ |
586 |
throw new CreateGeometryException( |
|
587 |
geom.getGeometryType().getType(), |
|
588 |
geom.getGeometryType().getSubType(), |
|
589 |
re); |
|
598 |
// throw new CreateGeometryException(
|
|
599 |
// geom.getGeometryType().getType(),
|
|
600 |
// geom.getGeometryType().getSubType(),
|
|
601 |
// re);
|
|
590 | 602 |
} |
591 | 603 |
} |
592 | 604 |
|
... | ... | |
926 | 938 |
/** |
927 | 939 |
* Returns the names of the {@link Feature} attributes required for the |
928 | 940 |
* {@link ILegend} to operate. |
929 |
*
|
|
941 |
* |
|
930 | 942 |
* @param featureStore |
931 | 943 |
* the store where the {@link Feature}s belong to |
932 | 944 |
* @return the names of required {@link Feature} attribute names |
Also available in: Unified diff