Changeset 3831 in josm for trunk/src/org
- Timestamp:
- 2011-01-29T22:03:18+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r3825 r3831 3 3 4 4 import java.awt.Graphics2D; 5 import java.awt.Point;6 5 import java.awt.Polygon; 7 6 import java.awt.Rectangle; … … 22 21 import org.openstreetmap.josm.data.osm.Node; 23 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 import org.openstreetmap.josm.data.osm.OsmUtils;25 23 import org.openstreetmap.josm.data.osm.Relation; 26 24 import org.openstreetmap.josm.data.osm.RelationMember; … … 177 175 if (drawMultipolygon && "multipolygon".equals(r.get("type"))) 178 176 drawMultipolygon(r); 179 else if (drawRestriction && "restriction".equals(r.get("type"))) 180 drawRestriction(r); 181 } 182 183 public void drawRestriction(Relation r) { 184 185 Way fromWay = null; 186 Way toWay = null; 187 OsmPrimitive via = null; 188 189 /* find the "from", "via" and "to" elements */ 190 for (RelationMember m : r.getMembers()) 191 { 192 if(m.getMember().isIncomplete()) 193 return; 194 else 195 { 196 if(m.isWay()) 197 { 198 Way w = m.getWay(); 199 if(w.getNodesCount() < 2) { 200 continue; 201 } 202 203 if("from".equals(m.getRole())) { 204 if(fromWay == null) 205 fromWay = w; 206 } else if("to".equals(m.getRole())) { 207 if(toWay == null) 208 toWay = w; 209 } else if("via".equals(m.getRole())) { 210 if(via == null) 211 via = w; 212 } 213 } 214 else if(m.isNode()) 215 { 216 Node n = m.getNode(); 217 if("via".equals(m.getRole()) && via == null) 218 via = n; 219 } 220 } 221 } 222 223 if (fromWay == null || toWay == null || via == null) 224 return; 225 226 Node viaNode; 227 if(via instanceof Node) 228 { 229 viaNode = (Node) via; 230 if(!fromWay.isFirstLastNode(viaNode)) { 231 return; 232 } 233 } 234 else 235 { 236 Way viaWay = (Way) via; 237 Node firstNode = viaWay.firstNode(); 238 Node lastNode = viaWay.lastNode(); 239 Boolean onewayvia = false; 240 241 String onewayviastr = viaWay.get("oneway"); 242 if(onewayviastr != null) 243 { 244 if("-1".equals(onewayviastr)) { 245 onewayvia = true; 246 Node tmp = firstNode; 247 firstNode = lastNode; 248 lastNode = tmp; 249 } else { 250 onewayvia = OsmUtils.getOsmBoolean(onewayviastr); 251 if (onewayvia == null) { 252 onewayvia = false; 253 } 254 } 255 } 256 257 if(fromWay.isFirstLastNode(firstNode)) { 258 viaNode = firstNode; 259 } else if (!onewayvia && fromWay.isFirstLastNode(lastNode)) { 260 viaNode = lastNode; 261 } else { 262 return; 263 } 264 } 265 266 /* find the "direct" nodes before the via node */ 267 Node fromNode = null; 268 if(fromWay.firstNode() == via) { 269 fromNode = fromWay.getNode(1); 270 } else { 271 fromNode = fromWay.getNode(fromWay.getNodesCount()-2); 272 } 273 274 Point pFrom = nc.getPoint(fromNode); 275 Point pVia = nc.getPoint(viaNode); 276 277 /* starting from via, go back the "from" way a few pixels 278 (calculate the vector vx/vy with the specified length and the direction 279 away from the "via" node along the first segment of the "from" way) 280 */ 281 double distanceFromVia=14; 282 double dx = (pFrom.x >= pVia.x) ? (pFrom.x - pVia.x) : (pVia.x - pFrom.x); 283 double dy = (pFrom.y >= pVia.y) ? (pFrom.y - pVia.y) : (pVia.y - pFrom.y); 284 285 double fromAngle; 286 if(dx == 0.0) { 287 fromAngle = Math.PI/2; 288 } else { 289 fromAngle = Math.atan(dy / dx); 290 } 291 double fromAngleDeg = Math.toDegrees(fromAngle); 292 293 double vx = distanceFromVia * Math.cos(fromAngle); 294 double vy = distanceFromVia * Math.sin(fromAngle); 295 296 if(pFrom.x < pVia.x) { 297 vx = -vx; 298 } 299 if(pFrom.y < pVia.y) { 300 vy = -vy; 301 } 302 303 /* go a few pixels away from the way (in a right angle) 304 (calculate the vx2/vy2 vector with the specified length and the direction 305 90degrees away from the first segment of the "from" way) 306 */ 307 double distanceFromWay=10; 308 double vx2 = 0; 309 double vy2 = 0; 310 double iconAngle = 0; 311 312 if(pFrom.x >= pVia.x && pFrom.y >= pVia.y) { 313 if(!leftHandTraffic) { 314 vx2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg - 90)); 315 vy2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg - 90)); 316 } else { 317 vx2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg + 90)); 318 vy2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg + 90)); 319 } 320 iconAngle = 270+fromAngleDeg; 321 } 322 if(pFrom.x < pVia.x && pFrom.y >= pVia.y) { 323 if(!leftHandTraffic) { 324 vx2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg)); 325 vy2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg)); 326 } else { 327 vx2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg + 180)); 328 vy2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg + 180)); 329 } 330 iconAngle = 90-fromAngleDeg; 331 } 332 if(pFrom.x < pVia.x && pFrom.y < pVia.y) { 333 if(!leftHandTraffic) { 334 vx2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg + 90)); 335 vy2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg + 90)); 336 } else { 337 vx2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg - 90)); 338 vy2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg - 90)); 339 } 340 iconAngle = 90+fromAngleDeg; 341 } 342 if(pFrom.x >= pVia.x && pFrom.y < pVia.y) { 343 if(!leftHandTraffic) { 344 vx2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg + 180)); 345 vy2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg + 180)); 346 } else { 347 vx2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg)); 348 vy2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg)); 349 } 350 iconAngle = 270-fromAngleDeg; 351 } 352 353 IconElemStyle nodeStyle = getPrimitiveNodeStyle(r); 354 355 if (nodeStyle == null) { 356 return; 357 } 358 359 painter.drawRestriction(inactive || r.isDisabled() ? nodeStyle.getDisabledIcon() : nodeStyle.icon, 360 pVia, vx, vx2, vy, vy2, iconAngle, data.isSelected(r)); 177 else if (drawRestriction && "restriction".equals(r.get("type"))) { 178 IconElemStyle nodeStyle = getPrimitiveNodeStyle(r); 179 if (nodeStyle != null) { 180 painter.drawRestriction(r, leftHandTraffic, nodeStyle); 181 } 182 } 361 183 } 362 184 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r3822 r3831 22 22 import org.openstreetmap.josm.data.osm.Node; 23 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 import org.openstreetmap.josm.data.osm.OsmUtils; 25 import org.openstreetmap.josm.data.osm.Relation; 26 import org.openstreetmap.josm.data.osm.RelationMember; 24 27 import org.openstreetmap.josm.data.osm.Way; 25 28 import org.openstreetmap.josm.gui.NavigatableComponent; 29 import org.openstreetmap.josm.gui.mappaint.IconElemStyle; 26 30 import org.openstreetmap.josm.tools.ImageProvider; 27 31 import org.openstreetmap.josm.tools.LanguageInfo; … … 330 334 } 331 335 336 public void drawRestriction(Relation r, boolean leftHandTraffic, IconElemStyle icon) { 337 338 Way fromWay = null; 339 Way toWay = null; 340 OsmPrimitive via = null; 341 342 /* find the "from", "via" and "to" elements */ 343 for (RelationMember m : r.getMembers()) 344 { 345 if(m.getMember().isIncomplete()) 346 return; 347 else 348 { 349 if(m.isWay()) 350 { 351 Way w = m.getWay(); 352 if(w.getNodesCount() < 2) { 353 continue; 354 } 355 356 if("from".equals(m.getRole())) { 357 if(fromWay == null) 358 fromWay = w; 359 } else if("to".equals(m.getRole())) { 360 if(toWay == null) 361 toWay = w; 362 } else if("via".equals(m.getRole())) { 363 if(via == null) 364 via = w; 365 } 366 } 367 else if(m.isNode()) 368 { 369 Node n = m.getNode(); 370 if("via".equals(m.getRole()) && via == null) 371 via = n; 372 } 373 } 374 } 375 376 if (fromWay == null || toWay == null || via == null) 377 return; 378 379 Node viaNode; 380 if(via instanceof Node) 381 { 382 viaNode = (Node) via; 383 if(!fromWay.isFirstLastNode(viaNode)) { 384 return; 385 } 386 } 387 else 388 { 389 Way viaWay = (Way) via; 390 Node firstNode = viaWay.firstNode(); 391 Node lastNode = viaWay.lastNode(); 392 Boolean onewayvia = false; 393 394 String onewayviastr = viaWay.get("oneway"); 395 if(onewayviastr != null) 396 { 397 if("-1".equals(onewayviastr)) { 398 onewayvia = true; 399 Node tmp = firstNode; 400 firstNode = lastNode; 401 lastNode = tmp; 402 } else { 403 onewayvia = OsmUtils.getOsmBoolean(onewayviastr); 404 if (onewayvia == null) { 405 onewayvia = false; 406 } 407 } 408 } 409 410 if(fromWay.isFirstLastNode(firstNode)) { 411 viaNode = firstNode; 412 } else if (!onewayvia && fromWay.isFirstLastNode(lastNode)) { 413 viaNode = lastNode; 414 } else { 415 return; 416 } 417 } 418 419 /* find the "direct" nodes before the via node */ 420 Node fromNode = null; 421 if(fromWay.firstNode() == via) { 422 fromNode = fromWay.getNode(1); 423 } else { 424 fromNode = fromWay.getNode(fromWay.getNodesCount()-2); 425 } 426 427 Point pFrom = nc.getPoint(fromNode); 428 Point pVia = nc.getPoint(viaNode); 429 430 /* starting from via, go back the "from" way a few pixels 431 (calculate the vector vx/vy with the specified length and the direction 432 away from the "via" node along the first segment of the "from" way) 433 */ 434 double distanceFromVia=14; 435 double dx = (pFrom.x >= pVia.x) ? (pFrom.x - pVia.x) : (pVia.x - pFrom.x); 436 double dy = (pFrom.y >= pVia.y) ? (pFrom.y - pVia.y) : (pVia.y - pFrom.y); 437 438 double fromAngle; 439 if(dx == 0.0) { 440 fromAngle = Math.PI/2; 441 } else { 442 fromAngle = Math.atan(dy / dx); 443 } 444 double fromAngleDeg = Math.toDegrees(fromAngle); 445 446 double vx = distanceFromVia * Math.cos(fromAngle); 447 double vy = distanceFromVia * Math.sin(fromAngle); 448 449 if(pFrom.x < pVia.x) { 450 vx = -vx; 451 } 452 if(pFrom.y < pVia.y) { 453 vy = -vy; 454 } 455 456 /* go a few pixels away from the way (in a right angle) 457 (calculate the vx2/vy2 vector with the specified length and the direction 458 90degrees away from the first segment of the "from" way) 459 */ 460 double distanceFromWay=10; 461 double vx2 = 0; 462 double vy2 = 0; 463 double iconAngle = 0; 464 465 if(pFrom.x >= pVia.x && pFrom.y >= pVia.y) { 466 if(!leftHandTraffic) { 467 vx2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg - 90)); 468 vy2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg - 90)); 469 } else { 470 vx2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg + 90)); 471 vy2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg + 90)); 472 } 473 iconAngle = 270+fromAngleDeg; 474 } 475 if(pFrom.x < pVia.x && pFrom.y >= pVia.y) { 476 if(!leftHandTraffic) { 477 vx2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg)); 478 vy2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg)); 479 } else { 480 vx2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg + 180)); 481 vy2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg + 180)); 482 } 483 iconAngle = 90-fromAngleDeg; 484 } 485 if(pFrom.x < pVia.x && pFrom.y < pVia.y) { 486 if(!leftHandTraffic) { 487 vx2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg + 90)); 488 vy2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg + 90)); 489 } else { 490 vx2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg - 90)); 491 vy2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg - 90)); 492 } 493 iconAngle = 90+fromAngleDeg; 494 } 495 if(pFrom.x >= pVia.x && pFrom.y < pVia.y) { 496 if(!leftHandTraffic) { 497 vx2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg + 180)); 498 vy2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg + 180)); 499 } else { 500 vx2 = distanceFromWay * Math.sin(Math.toRadians(fromAngleDeg)); 501 vy2 = distanceFromWay * Math.cos(Math.toRadians(fromAngleDeg)); 502 } 503 iconAngle = 270-fromAngleDeg; 504 } 505 506 drawRestriction(inactive || r.isDisabled() ? icon.getDisabledIcon() : icon.icon, 507 pVia, vx, vx2, vy, vy2, iconAngle, r.isSelected()); 508 } 509 332 510 public void drawVirtualNodes(Collection<Way> ways) { 333 511
Note:
See TracChangeset
for help on using the changeset viewer.