Changeset 1202 in josm for trunk/src/org
- Timestamp:
- 2009-01-01T23:53:59+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r1200 r1202 462 462 } 463 463 464 /* handle inside out stuff */ 465 466 if(zoomok) /* draw */ 467 { 464 if(outerclosed.size() == 0) 465 { 466 r.putError(tr("No outer way for multipolygon ''{0}''.", 467 r.getName()), true); 468 } 469 else if(zoomok) /* draw */ 470 { 471 class PolyData { 472 public Polygon poly = new Polygon(); 473 public Way way; 474 private Point p = null; 475 private Collection<Polygon> inner = null; 476 PolyData(Way w) 477 { 478 way = w; 479 for (Node n : w.nodes) 480 { 481 p = nc.getPoint(n.eastNorth); 482 poly.addPoint(p.x,p.y); 483 } 484 } 485 public int contains(Polygon p) 486 { 487 int contains = p.npoints; 488 for(int i = 0; i < p.npoints; ++i) 489 { 490 if(poly.contains(p.xpoints[i],p.ypoints[i])) 491 --contains; 492 } 493 if(contains == 0) return 1; /* inside */ 494 if(contains == p.npoints) return 0; /* outside */ 495 return 2; /* mixed */ 496 } 497 public void addInner(Polygon p) 498 { 499 if(inner == null) 500 inner = new ArrayList<Polygon>(); 501 inner.add(p); 502 } 503 public Polygon get() 504 { 505 if(inner != null) 506 { 507 for (Polygon pp : inner) 508 { 509 for(int i = 0; i < pp.npoints; ++i) 510 poly.addPoint(pp.xpoints[i],pp.ypoints[i]); 511 poly.addPoint(p.x,p.y); 512 } 513 inner = null; 514 } 515 return poly; 516 } 517 } 518 LinkedList<PolyData> poly = new LinkedList<PolyData>(); 468 519 for (Way w : outerclosed) 469 520 { 470 Color color = (w.selected || r.selected) ? selectedColor 521 poly.add(new PolyData(w)); 522 } 523 for (Way wInner : innerclosed) 524 { 525 Polygon polygon = new Polygon(); 526 527 for (Node n : wInner.nodes) 528 { 529 Point pInner = nc.getPoint(n.eastNorth); 530 polygon.addPoint(pInner.x,pInner.y); 531 } 532 if(!wInner.isClosed()) 533 { 534 Point pInner = nc.getPoint(wInner.nodes.get(0).eastNorth); 535 polygon.addPoint(pInner.x,pInner.y); 536 } 537 PolyData o = null; 538 for (PolyData pd : poly) 539 { 540 Integer c = pd.contains(polygon); 541 if(c >= 1) 542 { 543 if(c > 1 && pd.way.isClosed()) 544 { 545 r.putError(tr("Intersection between ways ''{0}'' and ''{1}''.", 546 pd.way.getName(), wInner.getName()), true); 547 } 548 if(o == null || o.contains(pd.poly) > 0) 549 o = pd; 550 } 551 } 552 if(o == null) 553 { 554 if(!incomplete) 555 { 556 r.putError(tr("Inner way ''{0}'' is outside.", 557 wInner.getName()), true); 558 } 559 o = poly.get(0); 560 } 561 o.addInner(polygon); 562 } 563 for (PolyData pd : poly) 564 { 565 Color color = (pd.way.selected || r.selected) ? selectedColor 471 566 : ((AreaElemStyle)wayStyle).color; 472 Polygon polygon = new Polygon();473 Point pOuter = null;474 475 for (Node n : w.nodes)476 {477 pOuter = nc.getPoint(n.eastNorth);478 polygon.addPoint(pOuter.x,pOuter.y);479 }480 for (Way wInner : innerclosed)481 {482 for (Node n : wInner.nodes)483 {484 Point pInner = nc.getPoint(n.eastNorth);485 polygon.addPoint(pInner.x,pInner.y);486 }487 if(!wInner.isClosed())488 {489 Point pInner = nc.getPoint(wInner.nodes.get(0).eastNorth);490 polygon.addPoint(pInner.x,pInner.y);491 }492 polygon.addPoint(pOuter.x,pOuter.y);493 }494 495 567 g.setColor(new Color( color.getRed(), color.getGreen(), 496 568 color.getBlue(), fillAlpha)); 497 569 498 g.fillPolygon(polygon); 499 alreadyDrawnAreas.add(w); 570 g.fillPolygon(pd.get()); 500 571 } 501 572 }
Note:
See TracChangeset
for help on using the changeset viewer.