Revision 43
org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/showmeasures/ShowMeasuresExtension.java | ||
---|---|---|
35 | 35 |
import javax.swing.JOptionPane; |
36 | 36 |
|
37 | 37 |
import org.apache.commons.lang3.StringUtils; |
38 |
import org.cresques.cts.ICoordTrans; |
|
38 | 39 |
import org.slf4j.Logger; |
39 | 40 |
import org.slf4j.LoggerFactory; |
40 | 41 |
|
... | ... | |
248 | 249 |
long curValue = 0; |
249 | 250 |
taskStatus.setCurValue(curValue); |
250 | 251 |
DisposableIterator it = selection.fastIterator(); |
252 |
ICoordTrans ct = layer.getCoordTrans(); |
|
251 | 253 |
while (it.hasNext()) { |
252 | 254 |
Feature feature = (Feature) it.next(); |
253 | 255 |
Geometry geometry = feature.getDefaultGeometry(); |
254 | 256 |
if (geometry instanceof Line) { |
255 |
curValue = showLineMeasures(graphics, curValue, (Line) geometry, distance); |
|
257 |
curValue = showLineMeasures(graphics, curValue, (Line) geometry, distance, ct);
|
|
256 | 258 |
taskStatus.setCurValue(curValue); |
257 | 259 |
} else if (geometry instanceof MultiLine) { |
258 | 260 |
MultiLine multiLine = (MultiLine) geometry; |
259 | 261 |
int primitives = multiLine.getPrimitivesNumber(); |
260 | 262 |
for (int i = 0; i < primitives; i++) { |
261 |
curValue = showLineMeasures(graphics, curValue, (Line) multiLine.getPrimitiveAt(i), distance); |
|
263 |
curValue = showLineMeasures(graphics, curValue, (Line) multiLine.getPrimitiveAt(i), distance, ct);
|
|
262 | 264 |
taskStatus.setCurValue(curValue); |
263 | 265 |
} |
264 | 266 |
} |
... | ... | |
272 | 274 |
* Shows measurements along a line with a fixed spacing |
273 | 275 |
* |
274 | 276 |
* @param curValue |
277 |
* @param ct2 |
|
275 | 278 |
* @param taskStatus |
276 | 279 |
* @param geometry |
277 | 280 |
* @return |
278 | 281 |
* @throws LocatorException |
279 | 282 |
* @throws CreateGeometryException |
280 | 283 |
*/ |
281 |
private long showLineMeasures(GraphicLayer graphics, long curValue, Line line, Double distance) throws CreateGeometryException, LocatorException { |
|
284 |
private long showLineMeasures(GraphicLayer graphics, long curValue, Line line, Double distance, ICoordTrans ct) throws CreateGeometryException, LocatorException {
|
|
282 | 285 |
long value = curValue; |
283 | 286 |
for (int i = 0; i < line.getNumVertices() - 1; i++) { |
284 | 287 |
value++; |
285 |
Point vertex = line.getVertex(i); |
|
288 |
Point vertex = (Point) line.getVertex(i);
|
|
286 | 289 |
double m0 = vertex.getCoordinateAt(vertex.getDimension() - 1); |
290 |
|
|
287 | 291 |
double div = m0 / distance; |
288 | 292 |
if (isMultiple(m0, distance)) { |
289 |
showMeasure(graphics, vertex, m0); |
|
293 |
showMeasure(graphics, vertex, m0, ct);
|
|
290 | 294 |
} |
291 | 295 |
Point nextVertex = line.getVertex(i + 1); |
292 | 296 |
double m1 = nextVertex.getCoordinateAt(vertex.getDimension() - 1); |
... | ... | |
294 | 298 |
for (Iterator iterator = multiples.iterator(); iterator.hasNext();) { |
295 | 299 |
Double m = (Double) iterator.next(); |
296 | 300 |
Point point = getPointWithMBetweenTwoVertex(m, vertex, nextVertex); |
297 |
showMeasure(graphics, point, m); |
|
301 |
showMeasure(graphics, point, m, ct);
|
|
298 | 302 |
} |
299 | 303 |
} |
300 | 304 |
value++; |
... | ... | |
305 | 309 |
* Show the m in the point p on the graphicLayer |
306 | 310 |
* |
307 | 311 |
* @param m |
312 |
* @param ct |
|
308 | 313 |
*/ |
309 |
private void showMeasure(GraphicLayer graphics, Point p, double m) { |
|
314 |
private void showMeasure(GraphicLayer graphics, Point p, double m, ICoordTrans ct) {
|
|
310 | 315 |
|
311 | 316 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
312 | 317 |
SymbolManager symbolManager = MapContextLocator.getSymbolManager(); |
... | ... | |
318 | 323 |
textSymbol.setText(formato.format(m).replace(",", " + ")); |
319 | 324 |
int idMarkerSymbol = graphics.addSymbol(markerSymbol); |
320 | 325 |
int idTextSymbol = graphics.addSymbol(textSymbol); |
321 |
graphics.addGraphic(SHOW_MEASURES_GRAPHICS_ID, p, idTextSymbol); |
|
322 |
graphics.addGraphic(SHOW_MEASURES_GRAPHICS_ID, p.cloneGeometry(), idMarkerSymbol); |
|
326 |
Point clonedPoint = (Point) p.cloneGeometry(); |
|
327 |
clonedPoint.reProject(ct); |
|
328 |
graphics.addGraphic(SHOW_MEASURES_GRAPHICS_ID, clonedPoint, idTextSymbol); |
|
329 |
graphics.addGraphic(SHOW_MEASURES_GRAPHICS_ID, clonedPoint, idMarkerSymbol); |
|
323 | 330 |
} |
324 | 331 |
|
325 | 332 |
/* |
Also available in: Unified diff