Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. Button panTo = new Button("Pan To");
  2. panTo.addActionListener(e->{
  3. //bounds.extend(new google.maps.LatLng('66.057878', '-22.579047')); // Iceland
  4. //bounds.extend(new google.maps.LatLng('37.961952', '43.878878')); // Turkey
  5. Coord c1 = new Coord(49.0986192, -122.6764454);
  6. Coord c2 = new Coord(49.2577142, -123.1941149);
  7. //Coord center = new Coord(c1.getLatitude()/2 + c2.getLatitude() / 2, c1.getLongitude()/2 + c2.getLongitude()/2 );
  8. Coord center = new Coord(49.1110928, -122.9414646);
  9.  
  10. float zoom = cnt.getZoom();
  11.  
  12. boolean[] finished = new boolean[1];
  13. cnt.addMapListener(new MapListener() {
  14.  
  15. @Override
  16. public void mapPositionUpdated(Component source, int zoom, Coord c) {
  17.  
  18. if (Math.abs(c.getLatitude() - center.getLatitude()) > .001 || Math.abs(c.getLongitude() - center.getLongitude()) > .001) {
  19. return;
  20. }
  21. finished[0] = true;
  22. synchronized(finished) {
  23. final MapListener fthis = this;
  24. Display.getInstance().callSerially(()->{
  25. cnt.removeMapListener(fthis);
  26. });
  27. finished.notify();
  28. }
  29.  
  30. }
  31.  
  32. });
  33. cnt.zoom(center, (int)zoom);
  34. while (!finished[0]) {
  35. Display.getInstance().invokeAndBlock(()->{
  36. while (!finished[0]) {
  37. Util.wait(finished, 100);
  38. }
  39. });
  40. }
  41. BoundingBox box = cnt.getBoundingBox();
  42. if (!box.contains(c1) || !box.contains(c2)) {
  43. while (!box.contains(c1) || !box.contains(c2)) {
  44. if (!box.contains(c1)) {
  45. System.out.println("Box "+box+" doesn't contain "+c1);
  46. }
  47. if (!box.contains(c1)) {
  48. System.out.println("Box "+box+" doesn't contain "+c2);
  49. }
  50. zoom -= 1;
  51. final boolean[] done = new boolean[1];
  52.  
  53. final int fzoom = (int)zoom;
  54. cnt.addMapListener(new MapListener() {
  55.  
  56. @Override
  57. public void mapPositionUpdated(Component source, int zm, Coord center) {
  58.  
  59. if (zm == fzoom) {
  60. final MapListener fthis = this;
  61. Display.getInstance().callSerially(()->{
  62. cnt.removeMapListener(fthis);
  63. });
  64.  
  65. done[0] = true;
  66. synchronized(done) {
  67. done.notify();
  68. }
  69. }
  70. }
  71.  
  72. });
  73. cnt.zoom(center, (int)zoom);
  74. while (!done[0]) {
  75. Display.getInstance().invokeAndBlock(()->{
  76. while (!done[0]) {
  77. Util.wait(done, 100);
  78. }
  79. });
  80. }
  81. box = cnt.getBoundingBox();
  82. System.out.println("Zoom now "+zoom);
  83.  
  84. }
  85. } else if (box.contains(c1) && box.contains(c2)) {
  86. while (box.contains(c1) && box.contains(c2)) {
  87. zoom += 1;
  88. final boolean[] done = new boolean[1];
  89.  
  90. final int fzoom = (int)zoom;
  91. cnt.addMapListener(new MapListener() {
  92. public void mapPositionUpdated(Component source, int zm, Coord center) {
  93. if (zm == fzoom) {
  94. final MapListener fthis = this;
  95. Display.getInstance().callSerially(()->{
  96. cnt.removeMapListener(fthis);
  97. });
  98. done[0] = true;
  99. synchronized(done) {
  100. done.notify();
  101. }
  102. }
  103. }
  104. });
  105. cnt.zoom(center, (int)zoom);
  106. while (!done[0]) {
  107. Display.getInstance().invokeAndBlock(()->{
  108. while (!done[0]) {
  109. Util.wait(done, 100);
  110. }
  111. });
  112. }
  113. box = cnt.getBoundingBox();
  114.  
  115. }
  116. zoom -= 1;
  117. cnt.zoom(center, (int)zoom);
  118. }
  119.  
  120. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement