Changeset 29826 in osm for applications/editors/josm/plugins
- Timestamp:
- 2013-08-05T11:15:02+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/smed2/src/seamap
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/seamap/Renderer.java
r29789 r29826 11 11 12 12 import java.awt.*; 13 import java.awt.font.*; 13 14 import java.awt.geom.*; 14 15 import java.util.*; … … 25 26 26 27 public class Renderer { 27 28 28 29 static MapHelper helper; 29 30 static SeaMap map; … … 32 33 static Graphics2D g2; 33 34 static int zoom; 34 35 35 36 public static void reRender(Graphics2D g, int z, double factor, SeaMap m, MapHelper h) { 36 37 g2 = g; … … 38 39 helper = h; 39 40 map = m; 40 sScale = Symbols.symbolScale[zoom] *factor;41 tScale = Symbols.textScale[zoom] *factor;41 sScale = Symbols.symbolScale[zoom] * factor; 42 tScale = Symbols.textScale[zoom] * factor; 42 43 if (map != null) { 43 44 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); … … 46 47 } 47 48 } 48 49 49 50 public static AttMap getAtts(Feature feature, Obj obj, int idx) { 50 51 HashMap<Integer, AttMap> objs = feature.objs.get(obj); 51 if (objs == null) return null; 52 else return objs.get(idx); 53 } 54 52 if (objs == null) 53 return null; 54 else 55 return objs.get(idx); 56 } 57 55 58 public static Object getAttVal(Feature feature, Obj obj, int idx, Att att) { 56 59 AttMap atts = getAtts(feature, obj, idx); 57 if (atts == null) return S57val.nullVal(att); 60 if (atts == null) 61 return S57val.nullVal(att); 58 62 else { 59 63 AttItem item = atts.get(att); 60 if (item == null) return S57val.nullVal(att); 64 if (item == null) 65 return S57val.nullVal(att); 61 66 return item.val; 62 67 } … … 73 78 } 74 79 } 75 80 76 81 private static Rectangle symbolSize(Symbol symbol) { 77 82 Symbol ssymb = symbol; … … 82 87 } 83 88 if (item.type == Prim.SYMB) { 84 ssymb = ((SubSymbol) item.params).instr;89 ssymb = ((SubSymbol) item.params).instr; 85 90 break; 86 91 } … … 90 95 } 91 96 return null; 97 } 98 99 private double mile(Feature feature) { 100 return Math.pow(2, zoom) * 256 / (21600 * Math.abs(Math.cos(feature.centre.lat))); 92 101 } 93 102 … … 133 142 if (first) { 134 143 curr = succ = next; 135 gap 136 scount 137 symbol 144 gap = (space > 0); 145 scount = ratio; 146 symbol = prisymb; 138 147 len = gap ? psize * space * 0.5 : psize; 139 148 first = false; … … 156 165 } 157 166 if (!gap) { 158 Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), 159 new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))), null);160 }161 if (space > 0)gap = !gap;167 Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))), null); 168 } 169 if (space > 0) 170 gap = !gap; 162 171 curr = succ; 163 172 len = gap ? (psize * space) : (--scount == 0) ? ssize : psize; … … 175 184 } 176 185 177 public static void lineVector 186 public static void lineVector(Feature feature, LineStyle style) { 178 187 Path2D.Double p = new Path2D.Double(); 179 188 p.setWindingRule(GeneralPath.WIND_EVEN_ODD); … … 220 229 } 221 230 } 222 223 public static void labelText 231 232 public static void labelText(Feature feature, String str, Font font, Color colour, Delta delta) { 224 233 Symbol label = new Symbol(); 225 234 label.add(new Instr(Prim.TEXT, new Caption(str, font, colour, (delta == null) ? new Delta(Handle.CC, null) : delta))); … … 227 236 Symbols.drawSymbol(g2, label, tScale, point.getX(), point.getY(), null, null); 228 237 } 229 230 public static void lineText (Feature feature, String str, Font font, Color colour, double offset, double dy) { 231 238 239 public static void lineText(Feature feature, String str, Font font, Color colour, double offset, double dy) { 240 Area area; 241 switch (feature.flag) { 242 case LINE: 243 Edge edge = map.edges.get(feature.refs); 244 area = map.new Area(); 245 area.add(map.new Bound(map.new Side(edge, true), true)); 246 break; 247 case AREA: 248 area = map.areas.get(feature.refs); 249 break; 250 default: 251 return; 252 } 253 // Rectangle prect = symbolSize(prisymb); 254 if (!str.isEmpty()) { 255 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 256 FontRenderContext frc = g2.getFontRenderContext(); 257 GlyphVector gv = font.deriveFont((float)(font.getSize()*tScale)).createGlyphVector(frc, str); 258 // double psize = Math.abs(prect.getX()); 259 Point2D prev = new Point2D.Double(); 260 Point2D next = new Point2D.Double(); 261 Point2D curr = new Point2D.Double(); 262 Point2D succ = new Point2D.Double(); 263 boolean gap = true; 264 boolean piv = false; 265 double len = 0; 266 double angle = 0; 267 for (Bound bound : area) { 268 BoundIterator bit = map.new BoundIterator(bound); 269 boolean first = true; 270 while (bit.hasNext()) { 271 prev = next; 272 next = helper.getPoint(bit.next()); 273 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX()); 274 piv = true; 275 if (first) { 276 curr = succ = next; 277 // gap = (space > 0); 278 // len = gap ? psize * space * 0.5 : psize; 279 first = false; 280 } else { 281 while (curr.distance(next) >= len) { 282 if (piv) { 283 double rem = len; 284 double s = prev.distance(next); 285 double p = curr.distance(prev); 286 if ((s > 0) && (p > 0)) { 287 double n = curr.distance(next); 288 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p); 289 double phi = Math.asin(p / len * Math.sin(theta)); 290 rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta); 291 } 292 succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle))); 293 piv = false; 294 } else { 295 succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle))); 296 } 297 if (!gap) { 298 // Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))), null); 299 } 300 gap = false; 301 curr = succ; 302 // len = psize; 303 } 304 } 305 } 306 } 307 } 232 308 } 233 309 } -
applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java
r29286 r29826 163 163 public AttMap atts; 164 164 public ObjMap objs; 165 public long area; 165 public double area; 166 public double length; 166 167 public Snode centre; 167 168 … … 173 174 objs = new ObjMap(); 174 175 area = 0; 176 length = 0; 175 177 centre = new Snode(); 176 178 } … … 377 379 node.flg = Nflag.ISOL; 378 380 } 381 feature.length = 0; 382 feature.area = 0; 379 383 break; 380 384 case LINE: … … 382 386 nodes.get(edge.first).flg = Nflag.CONN; 383 387 nodes.get(edge.last).flg = Nflag.CONN; 388 Bound ebound = (new Bound(new Side(edge, edge.forward), true)); 389 feature.length = calcLength(ebound); 384 390 if (edge.first == edge.last) { 385 391 feature.flag = Fflag.AREA; 386 392 Area area = new Area(); 387 area.add(new Bound(new Side(edge, edge.forward), true)); 393 area.add(ebound); 394 feature.area = calcArea(ebound); 388 395 areas.put(id, area); 396 } else { 397 feature.area = 0; 389 398 } 390 399 break; 391 400 case AREA: 401 Bound bound = null; 392 402 Area area = new Area(); 393 403 ArrayList<Long> role = outers; … … 397 407 long node1 = edge.first; 398 408 long node2 = edge.last; 399 Boundbound = new Bound(new Side(edge, edge.forward), (role == outers));409 bound = new Bound(new Side(edge, edge.forward), (role == outers)); 400 410 if (node1 != node2) { 401 411 for (ListIterator<Long> it = role.listIterator(0); it.hasNext();) { … … 417 427 } 418 428 if (role == outers) { 429 feature.length = calcLength(bound); 430 feature.area = calcArea(bound); 419 431 role = inners; 420 432 } else { … … 435 447 } 436 448 437 publicdouble signedArea(Bound bound) {449 double signedArea(Bound bound) { 438 450 Snode node; 439 451 double lat, lon, llon, llat; … … 449 461 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 450 462 } 451 return sigma ;463 return sigma / 2.0; 452 464 } 453 465 … … 457 469 458 470 public double calcArea(Bound bound) { 459 return Math.abs(signedArea(bound)) * 3444 * 3444 / 2.0; 471 return Math.abs(signedArea(bound)) * 3444 * 3444; 472 } 473 474 public double calcLength(Bound bound) { 475 Snode node; 476 double lat, lon, llon, llat; 477 lat = lon = llon = llat = 0; 478 double sigma = 0; 479 BoundIterator it = new BoundIterator(bound); 480 if (it.hasNext()) { 481 node = it.next(); 482 lat = node.lat; 483 lon = node.lon; 484 while (it.hasNext()) { 485 llon = lon; 486 llat = lat; 487 node = it.next(); 488 lat = node.lat; 489 lon = node.lon; 490 sigma += Math.acos(Math.sin(lat) * Math.sin(llat) + Math.cos(lat) * Math.cos(llat) * Math.cos(llon - lon)); 491 } 492 } 493 return sigma * 3444; 460 494 } 461 495
Note:
See TracChangeset
for help on using the changeset viewer.