Ticket #6035: 0001-Add-some-more-symbol-shapes-to-MapCSS-styles.patch
File 0001-Add-some-more-symbol-shapes-to-MapCSS-styles.patch, 6.5 KB (added by , 11 years ago) |
---|
-
src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
From d62d776ec8be0115c8434c9a33d5189365aedda6 Mon Sep 17 00:00:00 2001 From: Jeffrey C. Ollie <jeff@ocjtech.us> Date: Sat, 26 Feb 2011 19:06:43 -0600 Subject: [PATCH] Add some more symbol shapes to MapCSS styles. --- .../josm/data/osm/visitor/paint/MapPainter.java | 89 ++++++++++++++++---- .../josm/gui/mappaint/NodeElemStyle.java | 16 ++++- 2 files changed, 88 insertions(+), 17 deletions(-) diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java index ff370d4..8e4db4a 100644
a b public class MapPainter { 356 356 } 357 357 } 358 358 359 private Polygon buildPolygon(Point center, int radius, int sides, double rotation) { 360 Polygon polygon = new Polygon(); 361 for (int i = 0; i < sides; i++) { 362 double angle = ((2 * Math.PI / sides) * i) - rotation; 363 int x = (int) Math.round(center.x + radius * Math.cos(angle)); 364 int y = (int) Math.round(center.y + radius * Math.sin(angle)); 365 polygon.addPoint(x, y); 366 } 367 return polygon; 368 } 369 370 private Polygon buildPolygon(Point center, int radius, int sides) { 371 return buildPolygon(center, radius, sides, 0.0); 372 } 373 359 374 public void drawNodeSymbol(Node n, Symbol s, Color fillColor, Color strokeColor, NodeTextElement text) { 360 375 Point p = nc.getPoint(n); 361 376 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; … … public class MapPainter { 364 379 if (fillColor != null) { 365 380 g.setColor(fillColor); 366 381 switch (s.symbol) { 367 case SQUARE: 368 g.fillRect(p.x - radius, p.y - radius, s.size, s.size); 369 break; 370 case CIRCLE: 371 g.fillOval(p.x - radius, p.y - radius, s.size, s.size); 372 break; 373 default: 374 throw new AssertionError(); 382 case SQUARE: 383 g.fillRect(p.x - radius, p.y - radius, s.size, s.size); 384 break; 385 case CIRCLE: 386 g.fillOval(p.x - radius, p.y - radius, s.size, s.size); 387 break; 388 case TRIANGLE: 389 g.fillPolygon(buildPolygon(p, radius, 3, Math.PI / 2)); 390 break; 391 case PENTAGON: 392 g.fillPolygon(buildPolygon(p, radius, 5, Math.PI / 2)); 393 break; 394 case HEXAGON: 395 g.fillPolygon(buildPolygon(p, radius, 6)); 396 break; 397 case HEPTAGON: 398 g.fillPolygon(buildPolygon(p, radius, 7, Math.PI / 2)); 399 break; 400 case OCTAGON: 401 g.fillPolygon(buildPolygon(p, radius, 8, Math.PI / 8)); 402 break; 403 case NONAGON: 404 g.fillPolygon(buildPolygon(p, radius, 9, Math.PI / 2)); 405 break; 406 case DECAGON: 407 g.fillPolygon(buildPolygon(p, radius, 10)); 408 break; 409 default: 410 throw new AssertionError(); 375 411 } 376 412 } 377 413 if (s.stroke != null) { 378 414 g.setStroke(s.stroke); 379 415 g.setColor(strokeColor); 380 416 switch (s.symbol) { 381 case SQUARE: 382 g.drawRect(p.x - radius, p.y - radius, s.size - 1, s.size - 1); 383 break; 384 case CIRCLE: 385 g.drawOval(p.x - radius, p.y - radius, s.size - 1, s.size - 1); 386 break; 387 default: 388 throw new AssertionError(); 417 case SQUARE: 418 g.drawRect(p.x - radius, p.y - radius, s.size - 1, s.size - 1); 419 break; 420 case CIRCLE: 421 g.drawOval(p.x - radius, p.y - radius, s.size - 1, s.size - 1); 422 break; 423 case TRIANGLE: 424 g.drawPolygon(buildPolygon(p, radius, 3, Math.PI / 2)); 425 break; 426 case PENTAGON: 427 g.drawPolygon(buildPolygon(p, radius, 5, Math.PI / 2)); 428 break; 429 case HEXAGON: 430 g.drawPolygon(buildPolygon(p, radius, 6)); 431 break; 432 case HEPTAGON: 433 g.drawPolygon(buildPolygon(p, radius, 7, Math.PI / 2)); 434 break; 435 case OCTAGON: 436 g.drawPolygon(buildPolygon(p, radius, 8, Math.PI / 8)); 437 break; 438 case NONAGON: 439 g.drawPolygon(buildPolygon(p, radius, 9, Math.PI / 2)); 440 break; 441 case DECAGON: 442 g.drawPolygon(buildPolygon(p, radius, 10)); 443 break; 444 default: 445 throw new AssertionError(); 389 446 } 390 447 g.setStroke(new BasicStroke()); 391 448 } -
src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
diff --git a/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java b/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java index 25fcc92..b119e74 100644
a b public class NodeElemStyle extends ElemStyle { 34 34 35 35 private ImageIcon disabledIcon; 36 36 37 public enum SymbolShape { SQUARE, CIRCLE }37 public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON } 38 38 public enum HorizontalTextAlignment { LEFT, CENTER, RIGHT } 39 39 public enum VerticalTextAlignment { ABOVE, TOP, CENTER, BOTTOM, BELOW } 40 40 … … public class NodeElemStyle extends ElemStyle { 207 207 shape = SymbolShape.SQUARE; 208 208 } else if (equal(shapeStr, "circle")) { 209 209 shape = SymbolShape.CIRCLE; 210 } else if (equal(shapeStr, "triangle")) { 211 shape = SymbolShape.TRIANGLE; 212 } else if (equal(shapeStr, "pentagon")) { 213 shape = SymbolShape.PENTAGON; 214 } else if (equal(shapeStr, "hexagon")) { 215 shape = SymbolShape.HEXAGON; 216 } else if (equal(shapeStr, "heptagon")) { 217 shape = SymbolShape.HEPTAGON; 218 } else if (equal(shapeStr, "octagon")) { 219 shape = SymbolShape.OCTAGON; 220 } else if (equal(shapeStr, "nonagon")) { 221 shape = SymbolShape.NONAGON; 222 } else if (equal(shapeStr, "decagon")) { 223 shape = SymbolShape.DECAGON; 210 224 } else 211 225 return null; 212 226