]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.maps/src/org/simantics/maps/sg/MapScaleNode.java
Add location & zoom node for network diagram - also OSM attribution
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / sg / MapScaleNode.java
index a0242c11d502781fac0a69e7b3511b6178e09a3c..dc6b393d5a4ea2e8daf334d1095e3f7b46f0cb98 100644 (file)
@@ -28,13 +28,14 @@ public class MapScaleNode extends G2DNode {
 
     protected double           gridSize          = 1.0;
 
-    private double scale;
-
     @Override
     public void render(Graphics2D g) {
         if (!enabled)
             return;
 
+        AffineTransform ot = g.getTransform();
+        g.transform(transform);
+        
         AffineTransform tr = g.getTransform();
         double scaleX = Math.abs(tr.getScaleX());
         double scaleY = Math.abs(tr.getScaleY());
@@ -57,9 +58,9 @@ public class MapScaleNode extends G2DNode {
 
         double previousText = -100;
         
-        double minY = bounds.getMaxY() - 30;
+        double minY = bounds.getMaxY() - 40;
         
-        double scaleRight = bounds.getMaxX() - 30;
+        double scaleRight = bounds.getMaxX() - 20;
         
         double meterPerPixel = getMeterPerPixel(scaleRight - offsetX, minY - offsetY, scaleX, scaleY);
         
@@ -76,7 +77,7 @@ public class MapScaleNode extends G2DNode {
         
         double newScaleLeft = scaleRight - pixels;
         g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
-        Rectangle2D vertical = new Rectangle2D.Double(newScaleLeft, bounds.getMaxY() - 30, pixels, 20);
+        Rectangle2D vertical = new Rectangle2D.Double(newScaleLeft, bounds.getMaxY() - 40, pixels, 20);
         g.fill(vertical);
         
         g.setColor(GRAY);
@@ -100,9 +101,9 @@ public class MapScaleNode extends G2DNode {
         
         // Horizontal ruler
         double label = 0;
+        FontMetrics fm = g.getFontMetrics();
         for(double x = newScaleLeft; x < scaleRight; x += stepX) {
             String str = formatValue(label * meterPerPixel);
-            FontMetrics fm = g.getFontMetrics();
             Rectangle2D r = fm.getStringBounds(str, g);
             if((x - r.getWidth() / 2) > previousText) {
                 g.setColor(Color.BLACK);
@@ -129,7 +130,7 @@ public class MapScaleNode extends G2DNode {
             label += stepX;
         }
 
-        g.setTransform(tr);
+        g.setTransform(ot);
     }
 
     @Override
@@ -199,10 +200,6 @@ public class MapScaleNode extends G2DNode {
         this.enabled = enabled;
     }
 
-    public void setScale(double scale) {
-        this.scale = scale;
-    }
-    
     @Override
     public void init() {
         try {
@@ -225,11 +222,11 @@ public class MapScaleNode extends G2DNode {
     }
     
     public double getMeterPerPixel(double screenX, double screenY, double scaleX, double scaleY) {
-        double startLon = (screenX / scaleX) / scale;
-        double val = (screenY / scaleY) / scale;
+        double startLon = (screenX / scaleX);
+        double val = (screenY / scaleY);
         val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val))));
         double startLat = val;
-        double endLon = ((screenX + 1) / scaleX) / scale;
+        double endLon = ((screenX + 1) / scaleX);
         double endLat = val;
         
         calculator.setStartingGeographicPoint(startLon, startLat);