Changeset 11730 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
- Timestamp:
- 2017-03-13T20:11:23+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r11722 r11730 39 39 import java.util.concurrent.RecursiveTask; 40 40 import java.util.function.BiConsumer; 41 import java.util.function.Consumer; 41 42 import java.util.function.Supplier; 42 43 import java.util.stream.Collectors; … … 740 741 741 742 /** 742 * Draw the icon for a given area. The icon is drawn around the lat/loncenter of the area.743 * @param primitive The node744 * @param img The icon to draw at the node position743 * Draw the icon for a given area. Normally, the icon is drawn around the center of the area. 744 * @param osm The primitive to draw the icon for 745 * @param img The icon to draw 745 746 * @param disabled {@code} true to render disabled version, {@code false} for the standard version 746 747 * @param selected {@code} true to render it as selected, {@code false} otherwise 747 748 * @param member {@code} true to render it as a relation member, {@code false} otherwise 748 749 * @param theta the angle of rotation in radians 750 * @param iconPosition Where to place the icon. 749 751 * @since 11670 750 752 */ 751 public void drawAreaIcon(OsmPrimitive primitive, MapImage img, boolean disabled, boolean selected, boolean member, double theta) { 752 BBox bbox = null; 753 if (primitive instanceof Way) { 754 bbox = primitive.getBBox(); 755 } else if (primitive instanceof Relation) { 756 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) primitive); 757 if (multipolygon != null) { 758 BBox collect = new BBox(); 759 multipolygon.getOuterPolygons().forEach(p -> p.getNodes().forEach(n -> collect.add(n.getCoor()))); 760 bbox = collect; 761 } 762 } 763 764 if (bbox != null && bbox.isValid()) { 765 MapViewPoint p = mapState.getPointFor(bbox.getCenter()); 753 public void drawAreaIcon(OsmPrimitive osm, MapImage img, boolean disabled, boolean selected, boolean member, double theta, PositionForAreaStrategy iconPosition) { 754 Rectangle2D.Double iconRect = new Rectangle2D.Double(-img.getWidth() / 2.0, -img.getHeight() / 2.0, img.getWidth(), img.getHeight()); 755 756 forEachPolygon(osm, path -> { 757 Shape area = path.createTransformedShape(mapState.getAffineTransform()); 758 Rectangle2D placement = iconPosition.findLabelPlacement(area, iconRect); 759 if (placement == null) { 760 return; 761 } 762 MapViewPoint p = mapState.getForView(placement.getCenterX(), placement.getCenterY()); 766 763 drawIcon(p, img, disabled, selected, member, theta, (g, r) -> { 767 764 if (useStrokes) { … … 774 771 g.draw(r); 775 772 }); 776 } 773 }); 777 774 } 778 775 … … 1122 1119 } 1123 1120 } else { 1124 if (osm instanceof Way) { 1125 drawAreaText(osm, text, getPath((Way) osm)); 1126 } else if (osm instanceof Relation) { 1127 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm); 1128 if (!multipolygon.getOuterWays().isEmpty()) { 1129 for (PolyData pd : multipolygon.getCombinedPolygons()) { 1130 drawAreaText(osm, text, pd.get()); 1131 } 1121 forEachPolygon(osm, path -> drawAreaText(osm, text, path)); 1122 } 1123 } 1124 1125 /** 1126 * Calls a consumer for each path of the area shape- 1127 * @param osm A way or a multipolygon 1128 * @param consumer The consumer to call. 1129 */ 1130 private void forEachPolygon(OsmPrimitive osm, Consumer<Path2D.Double> consumer) { 1131 if (osm instanceof Way) { 1132 consumer.accept(getPath((Way) osm)); 1133 } else if (osm instanceof Relation) { 1134 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm); 1135 if (!multipolygon.getOuterWays().isEmpty()) { 1136 for (PolyData pd : multipolygon.getCombinedPolygons()) { 1137 consumer.accept(pd.get()); 1132 1138 } 1133 1139 }
Note:
See TracChangeset
for help on using the changeset viewer.