simple_view.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Simple Information API, mainly designed for use in the ECMAScript console.
  3. */
  4. /**
  5. * Auto zoom.
  6. * \ingroup ecma_simple
  7. */
  8. function autoZoom() {
  9. var view = getGraphicsView();
  10. if (isNull(view)) {
  11. return false;
  12. }
  13. view.autoZoom();
  14. return true;
  15. }
  16. /**
  17. * Zooms to the given entity.
  18. * Returns the bounding box of the given entity or undefined.
  19. * \ingroup ecma_simple
  20. *
  21. * \code
  22. * zoomTo(entity)
  23. * zoomTo(entity, margin)
  24. * zoomTo(entityId)
  25. * zoomTo(entityId, margin)
  26. * zoomTo(shape)
  27. * zoomTo(shape, margin)
  28. * zoomTo([x1,y1], [x2,y2])
  29. * zoomTo([x1,y1], [x2,y2], margin)
  30. * zoomTo(new RBox(x1,y1, x2,y2))
  31. * zoomTo(new RBox(x1,y1, x2,y2), margin)
  32. * \endcode
  33. */
  34. function zoomTo(p1,p2,p3,p4,p5) {
  35. if (isEntity(p1) || isShape(p1)) {
  36. return zoomTo(p1.getBoundingBox(), p2);
  37. }
  38. if (isNumber(p1) && isNull(p3)) {
  39. var doc = getDocument();
  40. if (isNull(doc)) {
  41. return undefined;
  42. }
  43. var entity = doc.queryEntityDirect(p1);
  44. var e = getPtr(entity);
  45. return zoomTo(e.getBoundingBox(), p2);
  46. }
  47. if (isArray(p1) && isArray(p2)) {
  48. return zoomTo(new RBox(new RVector(p1), new RVector(p2)), p3);
  49. }
  50. var view = getGraphicsView();
  51. if (isNull(view)) {
  52. return undefined;
  53. }
  54. if (isNull(p2)) {
  55. p2 = 10;
  56. }
  57. view.zoomTo(p1, p2);
  58. return p1;
  59. }