Ignore:
Timestamp:
2020-03-29T23:03:21+02:00 (6 years ago)
Author:
malcolmh
Message:

more map features

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/seachart/src/render/Renderer.java

    r35392 r35404  
    2525
    2626import s57.S57map;
    27 import s57.S57map.Feature;
    2827import s57.S57map.GeomIterator;
    2928import s57.S57map.Pflag;
     
    330329   
    331330    public static void grid() {
    332         if (context.grid() > 0) {
     331        if ((context.grid() > 0) && (map != null)) {
    333332            LineStyle style = new LineStyle(Color.black, (float)2.0);
    334             double nspan = 60 * Math.toDegrees(map.bounds.maxlon - map.bounds.minlon) / context.grid();
     333            Point2D point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.maxlon));
     334            double ratio = point.getX() / point.getY();
     335            double nspan = 60 * Math.toDegrees(map.bounds.maxlon - map.bounds.minlon) / (context.grid() * (ratio > 1.0 ? ratio : 1.0));
    335336            double mult = 1.0;
    336337            if (nspan < 1.0) {
     
    355356            Path2D.Double p = new Path2D.Double();
    356357            for (double lon = left; lon < map.bounds.maxlon; lon += Math.toRadians(nspan)) {
    357                 Point2D point = context.getPoint(new Snode(map.bounds.maxlat, lon));
     358                point = context.getPoint(new Snode(map.bounds.maxlat, lon));
    358359                p.moveTo(point.getX(), point.getY());
    359360                point = context.getPoint(new Snode(map.bounds.minlat, lon));
    360361                p.lineTo(point.getX(), point.getY());
    361362                double deg = Math.toDegrees(lon);
    362                 String ew = (deg < 0) ? "W" : "E";
     363                String ew = (deg < -0.001) ? "W" : (deg > 0.001) ? "E" : "";
    363364                deg = Math.abs(deg);
    364365                String dstr = String.format("%03d°", (int)Math.floor(deg));
     
    366367                String mstr = String.format("%05.2f'%s", min, ew);
    367368                Symbol label = new Symbol();
    368                 if (point.getX() > 500.0) {
     369                if (point.getX() > 600.0) {
    369370                    label.add(new Instr(Form.TEXT, new Caption(dstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BR, AffineTransform.getTranslateInstance(-10, -20)))));
    370371                    label.add(new Instr(Form.TEXT, new Caption(mstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BL, AffineTransform.getTranslateInstance(20, 0)))));
     
    374375            g2.setPaint(style.line);
    375376            g2.draw(p);
    376             double tspan = 60 * Math.toDegrees(map.bounds.maxlat - map.bounds.minlat) / context.grid();
     377            double tspan = 60 * Math.toDegrees(map.bounds.maxlat - map.bounds.minlat) / (context.grid() / (ratio < 1.0 ? ratio : 1.0));
    377378            mult = 1.0;
    378379            if (tspan < 1.0) {
     
    397398            p = new Path2D.Double();
    398399            for (double lat = bottom; lat < map.bounds.maxlat; lat += Math.toRadians(tspan)) {
    399                 Point2D point = context.getPoint(new Snode(lat, map.bounds.maxlon));
     400                point = context.getPoint(new Snode(lat, map.bounds.maxlon));
    400401                p.moveTo(point.getX(), point.getY());
    401402                point = context.getPoint(new Snode(lat, map.bounds.minlon));
    402403                p.lineTo(point.getX(), point.getY());
    403404                double deg = Math.toDegrees(lat);
    404                 String ns = (deg < 0) ? "S" : "N";
     405                String ns = (deg < -0.001) ? "S" : (deg > 0.001) ? "N" : "";
    405406                deg = Math.abs(deg);
    406407                String dstr = String.format("%02d°%s", (int)Math.floor(deg), ns);
     
    408409                String mstr = String.format("%05.2f'", min);
    409410                Symbol label = new Symbol();
    410                 label.add(new Instr(Form.TEXT, new Caption(dstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BL, AffineTransform.getTranslateInstance(10, -10)))));
    411                 label.add(new Instr(Form.TEXT, new Caption(mstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 50)))));
    412                 Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, null);
     411                if (point.getY() < (context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon)).getY() - 200.0)) {
     412                        label.add(new Instr(Form.TEXT, new Caption(dstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BL, AffineTransform.getTranslateInstance(10, -10)))));
     413                        label.add(new Instr(Form.TEXT, new Caption(mstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 50)))));
     414                        Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, null);
     415                }
    413416            }
    414417            g2.setPaint(style.line);
    415418            g2.draw(p);
    416 /*            Symbol legend = new Symbol();
    417             legend.add(new Instr(Form.BBOX, new Rectangle2D.Double(0, 0, 900, 300)));
    418             Path2D.Double path = new Path2D.Double(); path.moveTo(0, 0); path.lineTo(900, 0); path.lineTo(900, 300); path.lineTo(0, 300); path.closePath();
     419            Symbol legend = new Symbol();
     420            legend.add(new Instr(Form.BBOX, new Rectangle2D.Double(0, 0, 500, 100)));
     421            Path2D.Double path = new Path2D.Double(); path.moveTo(0, 0); path.lineTo(500, 0); path.lineTo(500, 100); path.lineTo(0, 100); path.closePath();
    419422            legend.add(new Instr(Form.FILL, Color.white));
    420423            legend.add(new Instr(Form.PGON, path));
    421             legend.add(new Instr(Form.TEXT, new Caption("© OpenStreetMap contributors", new Font("Arial", Font.PLAIN, 25), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(450, 300)))));
    422             legend.add(new Instr(Form.TEXT, new Caption("Mercator projection", new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(450, 250)))));
    423             Point2D point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon));
     424            legend.add(new Instr(Form.TEXT, new Caption("Mercator Projection", new Font("Arial", Font.PLAIN, 50), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(250, 60)))));
     425            point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon));
    424426            Symbols.drawSymbol(g2, legend, sScale, point.getX(), point.getY(), null, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 0)));
    425427            legend = new Symbol();
    426             legend.add(new Instr(Form.BBOX, new Rectangle2D.Double(0, 0, 900, 300)));
    427             legend.add(new Instr(Form.TEXT, new Caption("Mercator projection", new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(450, 250)))));
     428            legend.add(new Instr(Form.BBOX, new Rectangle2D.Double(0, 0, 500, 100)));
     429            legend.add(new Instr(Form.TEXT, new Caption("© OpenStreetMap contributors", new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(250, 100)))));
    428430            point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon));
    429431            Symbols.drawSymbol(g2, legend, sScale, point.getX(), point.getY(), null, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 0)));
    430 */        }
     432        }
    431433    }
    432434
     
    761763        }
    762764    }
     765   
     766    public static void rasterPixel(double size, Color col) {
     767        double s = Rules.feature.geom.centre.lat - (size / 2.0);
     768        double w = Rules.feature.geom.centre.lon - (size / 2.0);
     769        double n = Rules.feature.geom.centre.lat + (size / 2.0);
     770        double e = Rules.feature.geom.centre.lon + (size / 2.0);
     771        Point2D sw = context.getPoint(new Snode(s, w));
     772        Point2D nw = context.getPoint(new Snode(n, w));
     773        Point2D ne = context.getPoint(new Snode(n, e));
     774        Point2D se = context.getPoint(new Snode(s, e));
     775        Symbol pixel = new Symbol();
     776        Path2D.Double path = new Path2D.Double(); path.moveTo(sw.getX(), sw.getY()); path.lineTo(nw.getX(), nw.getY());
     777        path.lineTo(ne.getX(), ne.getY()); path.lineTo(se.getX(), se.getY()); path.closePath();
     778        pixel.add(new Instr(Form.FILL, col));
     779        pixel.add(new Instr(Form.PGON, path));
     780        Symbols.drawSymbol(g2, pixel, 1.0, 0, 0, null, null);
     781    }
    763782}
Note: See TracChangeset for help on using the changeset viewer.