|
@@ -31,6 +31,7 @@ import org.insa.graphics.drawing.BasicGraphPalette;
|
31
|
31
|
import org.insa.graphics.drawing.Drawing;
|
32
|
32
|
import org.insa.graphics.drawing.DrawingClickListener;
|
33
|
33
|
import org.insa.graphics.drawing.GraphPalette;
|
|
34
|
+import org.insa.graphics.drawing.MercatorProjection;
|
34
|
35
|
import org.insa.graphics.drawing.overlays.MarkerOverlay;
|
35
|
36
|
import org.insa.graphics.drawing.overlays.MarkerUtils;
|
36
|
37
|
import org.insa.graphics.drawing.overlays.Overlay;
|
|
@@ -146,8 +147,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
146
|
147
|
@Override
|
147
|
148
|
public void drawImpl(Graphics2D graphics) {
|
148
|
149
|
|
149
|
|
- int px = BasicDrawing.this.projx(getPoint().getLongitude());
|
150
|
|
- int py = BasicDrawing.this.projy(getPoint().getLatitude());
|
|
150
|
+ int px = projection.longitudeToPixelX(getPoint().getLongitude());
|
|
151
|
+ int py = projection.latitudeToPixelY(getPoint().getLatitude());
|
151
|
152
|
|
152
|
153
|
graphics.drawImage(this.image, px - MARKER_WIDTH / 2, py - MARKER_HEIGHT, MARKER_WIDTH,
|
153
|
154
|
MARKER_HEIGHT, BasicDrawing.this);
|
|
@@ -193,10 +194,10 @@ public class BasicDrawing extends JPanel implements Drawing {
|
193
|
194
|
while (itPoint.hasNext()) {
|
194
|
195
|
Point curr = itPoint.next();
|
195
|
196
|
|
196
|
|
- int x1 = BasicDrawing.this.projx(prev.getLongitude());
|
197
|
|
- int x2 = BasicDrawing.this.projx(curr.getLongitude());
|
198
|
|
- int y1 = BasicDrawing.this.projy(prev.getLatitude());
|
199
|
|
- int y2 = BasicDrawing.this.projy(curr.getLatitude());
|
|
197
|
+ int x1 = projection.longitudeToPixelX(prev.getLongitude());
|
|
198
|
+ int x2 = projection.longitudeToPixelX(curr.getLongitude());
|
|
199
|
+ int y1 = projection.latitudeToPixelY(prev.getLatitude());
|
|
200
|
+ int y2 = projection.latitudeToPixelY(curr.getLatitude());
|
200
|
201
|
|
201
|
202
|
graphics.drawLine(x1, y1, x2, y2);
|
202
|
203
|
|
|
@@ -253,8 +254,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
253
|
254
|
|
254
|
255
|
@Override
|
255
|
256
|
public void addPoint(Point point) {
|
256
|
|
- int x = BasicDrawing.this.projx(point.getLongitude()) - this.width / 2;
|
257
|
|
- int y = BasicDrawing.this.projy(point.getLatitude()) - this.width / 2;
|
|
257
|
+ int x = projection.longitudeToPixelX(point.getLongitude()) - this.width / 2;
|
|
258
|
+ int y = projection.latitudeToPixelY(point.getLatitude()) - this.width / 2;
|
258
|
259
|
this.graphics.fillOval(x, y, this.width, this.width);
|
259
|
260
|
BasicDrawing.this.repaint();
|
260
|
261
|
}
|
|
@@ -294,7 +295,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
294
|
295
|
// Maximum width for the drawing (in pixels).
|
295
|
296
|
private static final int MAXIMUM_DRAWING_WIDTH = 2000;
|
296
|
297
|
|
297
|
|
- private double long1, long2, lat1, lat2;
|
|
298
|
+ private MercatorProjection projection;
|
298
|
299
|
|
299
|
300
|
// Width and height of the image
|
300
|
301
|
private int width, height;
|
|
@@ -430,22 +431,6 @@ public class BasicDrawing extends JPanel implements Drawing {
|
430
|
431
|
}
|
431
|
432
|
|
432
|
433
|
/**
|
433
|
|
- * @param lon
|
434
|
|
- * @return
|
435
|
|
- */
|
436
|
|
- private int projx(double lon) {
|
437
|
|
- return (int) (width * (lon - this.long1) / (this.long2 - this.long1));
|
438
|
|
- }
|
439
|
|
-
|
440
|
|
- /**
|
441
|
|
- * @param lat
|
442
|
|
- * @return
|
443
|
|
- */
|
444
|
|
- private int projy(double lat) {
|
445
|
|
- return (int) (height * (1 - (lat - this.lat1) / (this.lat2 - this.lat1)));
|
446
|
|
- }
|
447
|
|
-
|
448
|
|
- /**
|
449
|
434
|
* Return the longitude and latitude corresponding to the given position of the
|
450
|
435
|
* MouseEvent.
|
451
|
436
|
*
|
|
@@ -465,13 +450,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
465
|
450
|
.inverseTransform(event.getPoint(), null);
|
466
|
451
|
|
467
|
452
|
// Inverse the "projection" on x/y to get longitude and latitude.
|
468
|
|
- double lon = ptDst.getX();
|
469
|
|
- double lat = ptDst.getY();
|
470
|
|
- lon = (lon / this.width) * (this.long2 - this.long1) + this.long1;
|
471
|
|
- lat = (1 - lat / this.height) * (this.lat2 - this.lat1) + this.lat1;
|
472
|
|
-
|
473
|
|
- // Return a new point.
|
474
|
|
- return new Point((float) lon, (float) lat);
|
|
453
|
+ return new Point(projection.pixelXToLongitude(ptDst.getX()),
|
|
454
|
+ projection.pixelYToLatitude(ptDst.getY()));
|
475
|
455
|
}
|
476
|
456
|
|
477
|
457
|
/*
|
|
@@ -546,10 +526,10 @@ public class BasicDrawing extends JPanel implements Drawing {
|
546
|
526
|
while (it1.hasNext()) {
|
547
|
527
|
Point curr = it1.next();
|
548
|
528
|
|
549
|
|
- int x1 = this.projx(prev.getLongitude());
|
550
|
|
- int x2 = this.projx(curr.getLongitude());
|
551
|
|
- int y1 = this.projy(prev.getLatitude());
|
552
|
|
- int y2 = this.projy(curr.getLatitude());
|
|
529
|
+ int x1 = projection.longitudeToPixelX(prev.getLongitude());
|
|
530
|
+ int x2 = projection.longitudeToPixelX(curr.getLongitude());
|
|
531
|
+ int y1 = projection.latitudeToPixelY(prev.getLatitude());
|
|
532
|
+ int y2 = projection.latitudeToPixelY(curr.getLatitude());
|
553
|
533
|
|
554
|
534
|
graphGraphics.drawLine(x1, y1, x2, y2);
|
555
|
535
|
prev = curr;
|
|
@@ -573,30 +553,20 @@ public class BasicDrawing extends JPanel implements Drawing {
|
573
|
553
|
BoundingBox box = graph.getGraphInformation().getBoundingBox();
|
574
|
554
|
|
575
|
555
|
// Find minimum/maximum longitude and latitude.
|
576
|
|
- double minLon = box.getTopLeftPoint().getLongitude(),
|
|
556
|
+ float minLon = box.getTopLeftPoint().getLongitude(),
|
577
|
557
|
maxLon = box.getBottomRightPoint().getLongitude(),
|
578
|
558
|
minLat = box.getBottomRightPoint().getLatitude(),
|
579
|
559
|
maxLat = box.getTopLeftPoint().getLatitude();
|
580
|
560
|
|
581
|
561
|
// Add a little delta to avoid drawing on the edge...
|
582
|
|
- double diffLon = maxLon - minLon, diffLat = maxLat - minLat;
|
583
|
|
- double deltaLon = 0.01 * diffLon, deltaLat = 0.01 * diffLat;
|
584
|
|
-
|
585
|
|
- this.long1 = minLon - deltaLon;
|
586
|
|
- this.long2 = maxLon + deltaLon;
|
587
|
|
- this.lat1 = minLat - deltaLat;
|
588
|
|
- this.lat2 = maxLat + deltaLat;
|
589
|
|
-
|
590
|
|
- // Compute width/height for the image
|
591
|
|
-
|
592
|
|
- if (diffLat < diffLon) {
|
593
|
|
- this.width = MAXIMUM_DRAWING_WIDTH;
|
594
|
|
- this.height = (int) (this.width * diffLat / diffLon);
|
595
|
|
- }
|
596
|
|
- else {
|
597
|
|
- this.height = MAXIMUM_DRAWING_WIDTH;
|
598
|
|
- this.width = (int) (this.height * diffLon / diffLat);
|
599
|
|
- }
|
|
562
|
+ float diffLon = maxLon - minLon, diffLat = maxLat - minLat;
|
|
563
|
+ float deltaLon = 0.01f * diffLon, deltaLat = 0.01f * diffLat;
|
|
564
|
+
|
|
565
|
+ // Create the projection and retrieve width and height for the box.
|
|
566
|
+ projection = new MercatorProjection(box.extend(deltaLon, deltaLat, deltaLon, deltaLat),
|
|
567
|
+ MAXIMUM_DRAWING_WIDTH);
|
|
568
|
+ this.width = (int) projection.getImageWidth();
|
|
569
|
+ this.height = (int) projection.getImageHeight();
|
600
|
570
|
|
601
|
571
|
// Create the image
|
602
|
572
|
BufferedImage img = new BufferedImage(this.width, this.height,
|