Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button panTo = new Button("Pan To");
- panTo.addActionListener(e->{
- //bounds.extend(new google.maps.LatLng('66.057878', '-22.579047')); // Iceland
- //bounds.extend(new google.maps.LatLng('37.961952', '43.878878')); // Turkey
- Coord c1 = new Coord(49.0986192, -122.6764454);
- Coord c2 = new Coord(49.2577142, -123.1941149);
- //Coord center = new Coord(c1.getLatitude()/2 + c2.getLatitude() / 2, c1.getLongitude()/2 + c2.getLongitude()/2 );
- Coord center = new Coord(49.1110928, -122.9414646);
- float zoom = cnt.getZoom();
- boolean[] finished = new boolean[1];
- cnt.addMapListener(new MapListener() {
- @Override
- public void mapPositionUpdated(Component source, int zoom, Coord c) {
- if (Math.abs(c.getLatitude() - center.getLatitude()) > .001 || Math.abs(c.getLongitude() - center.getLongitude()) > .001) {
- return;
- }
- finished[0] = true;
- synchronized(finished) {
- final MapListener fthis = this;
- Display.getInstance().callSerially(()->{
- cnt.removeMapListener(fthis);
- });
- finished.notify();
- }
- }
- });
- cnt.zoom(center, (int)zoom);
- while (!finished[0]) {
- Display.getInstance().invokeAndBlock(()->{
- while (!finished[0]) {
- Util.wait(finished, 100);
- }
- });
- }
- BoundingBox box = cnt.getBoundingBox();
- if (!box.contains(c1) || !box.contains(c2)) {
- while (!box.contains(c1) || !box.contains(c2)) {
- if (!box.contains(c1)) {
- System.out.println("Box "+box+" doesn't contain "+c1);
- }
- if (!box.contains(c1)) {
- System.out.println("Box "+box+" doesn't contain "+c2);
- }
- zoom -= 1;
- final boolean[] done = new boolean[1];
- final int fzoom = (int)zoom;
- cnt.addMapListener(new MapListener() {
- @Override
- public void mapPositionUpdated(Component source, int zm, Coord center) {
- if (zm == fzoom) {
- final MapListener fthis = this;
- Display.getInstance().callSerially(()->{
- cnt.removeMapListener(fthis);
- });
- done[0] = true;
- synchronized(done) {
- done.notify();
- }
- }
- }
- });
- cnt.zoom(center, (int)zoom);
- while (!done[0]) {
- Display.getInstance().invokeAndBlock(()->{
- while (!done[0]) {
- Util.wait(done, 100);
- }
- });
- }
- box = cnt.getBoundingBox();
- System.out.println("Zoom now "+zoom);
- }
- } else if (box.contains(c1) && box.contains(c2)) {
- while (box.contains(c1) && box.contains(c2)) {
- zoom += 1;
- final boolean[] done = new boolean[1];
- final int fzoom = (int)zoom;
- cnt.addMapListener(new MapListener() {
- public void mapPositionUpdated(Component source, int zm, Coord center) {
- if (zm == fzoom) {
- final MapListener fthis = this;
- Display.getInstance().callSerially(()->{
- cnt.removeMapListener(fthis);
- });
- done[0] = true;
- synchronized(done) {
- done.notify();
- }
- }
- }
- });
- cnt.zoom(center, (int)zoom);
- while (!done[0]) {
- Display.getInstance().invokeAndBlock(()->{
- while (!done[0]) {
- Util.wait(done, 100);
- }
- });
- }
- box = cnt.getBoundingBox();
- }
- zoom -= 1;
- cnt.zoom(center, (int)zoom);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement