X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Fsg%2FMapScaleNode.java;h=e506e11d4a14ab71e2f4dacb7ed5c8797d4f502f;hb=fb4e5f02481e918807be83e87239a4d91b4343f2;hp=a0242c11d502781fac0a69e7b3511b6178e09a3c;hpb=55f42e7fcc2f6733082ab8c150efe3a2b54ff22b;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.maps/src/org/simantics/maps/sg/MapScaleNode.java b/org.simantics.district.maps/src/org/simantics/maps/sg/MapScaleNode.java index a0242c11..e506e11d 100644 --- a/org.simantics.district.maps/src/org/simantics/maps/sg/MapScaleNode.java +++ b/org.simantics.district.maps/src/org/simantics/maps/sg/MapScaleNode.java @@ -16,6 +16,7 @@ import org.geotools.referencing.GeodeticCalculator; import org.opengis.referencing.FactoryException; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.utils.DPIUtil; import org.simantics.scenegraph.utils.GridUtils; public class MapScaleNode extends G2DNode { @@ -28,13 +29,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()); @@ -46,7 +48,7 @@ public class MapScaleNode extends G2DNode { double offsetY = tr.getTranslateY(); g.setTransform(new AffineTransform()); - Font rulerFont = new Font("Tahoma", Font.PLAIN, 9); + Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9));; //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setStroke(new BasicStroke(1)); @@ -57,9 +59,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 +78,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 +102,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 +131,7 @@ public class MapScaleNode extends G2DNode { label += stepX; } - g.setTransform(tr); + g.setTransform(ot); } @Override @@ -140,7 +142,7 @@ public class MapScaleNode extends G2DNode { private static final transient int MAX_DIGITS = 0; private static final transient double EPSILON = 0.01; private static final transient double TRIM_THRESHOLD_MAX_VALUE = Math.pow(10, 2); - private static final transient String[] SI_UNIT_LARGE_PREFIXES = { "m", "km" }; + //private static final transient String[] SI_UNIT_LARGE_PREFIXES = { "m", "km" }; private static final transient double[] SCALE_VALUES = { 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000, 50000000 }; @@ -199,10 +201,6 @@ public class MapScaleNode extends G2DNode { this.enabled = enabled; } - public void setScale(double scale) { - this.scale = scale; - } - @Override public void init() { try { @@ -225,11 +223,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);