| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package render;
|
|---|
| 3 |
|
|---|
| 4 | import java.awt.BasicStroke;
|
|---|
| 5 | import java.awt.Color;
|
|---|
| 6 | import java.awt.Font;
|
|---|
| 7 | import java.awt.Graphics2D;
|
|---|
| 8 | import java.awt.Rectangle;
|
|---|
| 9 | import java.awt.RenderingHints;
|
|---|
| 10 | import java.awt.TexturePaint;
|
|---|
| 11 | import java.awt.font.FontRenderContext;
|
|---|
| 12 | import java.awt.font.GlyphVector;
|
|---|
| 13 | import java.awt.geom.AffineTransform;
|
|---|
| 14 | import java.awt.geom.Arc2D;
|
|---|
| 15 | import java.awt.geom.Ellipse2D;
|
|---|
| 16 | import java.awt.geom.GeneralPath;
|
|---|
| 17 | import java.awt.geom.Line2D;
|
|---|
| 18 | import java.awt.geom.Path2D;
|
|---|
| 19 | import java.awt.geom.Point2D;
|
|---|
| 20 | import java.awt.geom.Rectangle2D;
|
|---|
| 21 | import java.awt.geom.RoundRectangle2D;
|
|---|
| 22 | import java.awt.image.AffineTransformOp;
|
|---|
| 23 | import java.awt.image.BufferedImage;
|
|---|
| 24 | import java.util.ArrayList;
|
|---|
| 25 |
|
|---|
| 26 | import s57.S57map;
|
|---|
| 27 | import s57.S57map.GeomIterator;
|
|---|
| 28 | import s57.S57map.Pflag;
|
|---|
| 29 | import s57.S57map.Snode;
|
|---|
| 30 | import s57.S57val.UniHLU;
|
|---|
| 31 | import symbols.Areas;
|
|---|
| 32 | import symbols.Symbols;
|
|---|
| 33 | import symbols.Symbols.Caption;
|
|---|
| 34 | import symbols.Symbols.Delta;
|
|---|
| 35 | import symbols.Symbols.Form;
|
|---|
| 36 | import symbols.Symbols.Handle;
|
|---|
| 37 | import symbols.Symbols.Instr;
|
|---|
| 38 | import symbols.Symbols.LineStyle;
|
|---|
| 39 | import symbols.Symbols.Scheme;
|
|---|
| 40 | import symbols.Symbols.SubSymbol;
|
|---|
| 41 | import symbols.Symbols.Symbol;
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * @author Malcolm Herring
|
|---|
| 45 | */
|
|---|
| 46 | public final class Renderer {
|
|---|
| 47 | private Renderer() {
|
|---|
| 48 | // Hide default constructor for utilities classes
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | public static final double[] symbolScale = {
|
|---|
| 52 | 256.0, 128.0, 64.0, 32.0, 16.0, 8.0, 4.0, 2.0, 1.0, 0.61, 0.372, 0.227, 0.138, 0.0843, 0.0514, 0.0313, 0.0191, 0.0117, 0.007};
|
|---|
| 53 |
|
|---|
| 54 | public enum LabelStyle { NONE, RRCT, RECT, ELPS, CIRC, VCLR, PCLR, HCLR }
|
|---|
| 55 |
|
|---|
| 56 | static ChartContext context;
|
|---|
| 57 | static S57map map;
|
|---|
| 58 | static double sScale;
|
|---|
| 59 | static Graphics2D g2;
|
|---|
| 60 | static int zoom;
|
|---|
| 61 |
|
|---|
| 62 | public static void reRender(Graphics2D g, Rectangle rect, int z, double factor, S57map m, ChartContext c) {
|
|---|
| 63 | g2 = g;
|
|---|
| 64 | zoom = z;
|
|---|
| 65 | context = c;
|
|---|
| 66 | map = m;
|
|---|
| 67 | sScale = symbolScale[zoom] * factor;
|
|---|
| 68 | if (map != null) {
|
|---|
| 69 | if (context.clip()) {
|
|---|
| 70 | Point2D tl = context.getPoint(new Snode(map.bounds.maxlat, map.bounds.minlon));
|
|---|
| 71 | Point2D br = context.getPoint(new Snode(map.bounds.minlat, map.bounds.maxlon));
|
|---|
| 72 | g2.clip(new Rectangle2D.Double(tl.getX(), tl.getY(), (br.getX() - tl.getX()), (br.getY() - tl.getY())));
|
|---|
| 73 | }
|
|---|
| 74 | g2.setBackground(context.background(map));
|
|---|
| 75 | g2.clearRect(rect.x, rect.y, rect.width, rect.height);
|
|---|
| 76 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|---|
| 77 | g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
|
|---|
| 78 | g2.setStroke(new BasicStroke(0, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
|
|---|
| 79 | do {} while (!Rules.rules());
|
|---|
| 80 | }
|
|---|
| 81 | if ((context.grid() > 0) && (map != null)) {
|
|---|
| 82 | rose();
|
|---|
| 83 | grid();
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | public static void symbol(Symbol symbol) {
|
|---|
| 88 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 89 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, null);
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | public static void symbol(Symbol symbol, Scheme scheme) {
|
|---|
| 93 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 94 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, null);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | public static void symbol(Symbol symbol, Delta delta) {
|
|---|
| 98 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 99 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, delta);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | public static void symbol(Symbol symbol, double scale, Delta delta) {
|
|---|
| 103 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 104 | Symbols.drawSymbol(g2, symbol, (sScale * scale), point.getX(), point.getY(), null, delta);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | public static void symbol(Symbol symbol, Scheme scheme, Delta delta) {
|
|---|
| 108 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 109 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, delta);
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | public static void symbol(Symbol symbol, double scale, Scheme scheme) {
|
|---|
| 113 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 114 | Symbols.drawSymbol(g2, symbol, (sScale * scale), point.getX(), point.getY(), scheme, null);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | public static void colLetters(ArrayList<?> cols) {
|
|---|
| 118 | String str = "";
|
|---|
| 119 | for (int i = 0; (i < cols.size()) && (i < 4); i++) {
|
|---|
| 120 | str = str.concat(Rules.colourLetters.get(cols.get(i)));
|
|---|
| 121 | }
|
|---|
| 122 | labelText(str, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, 40)));
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | public static void cluster(ArrayList<Symbol> symbols) {
|
|---|
| 126 | Rectangle2D.Double bbox = null;
|
|---|
| 127 | if (symbols.size() > 4) {
|
|---|
| 128 | for (Instr instr : symbols.get(0)) {
|
|---|
| 129 | if (instr.type == Form.BBOX) {
|
|---|
| 130 | bbox = (Rectangle2D.Double) instr.params;
|
|---|
| 131 | break;
|
|---|
| 132 | }
|
|---|
| 133 | }
|
|---|
| 134 | if (bbox == null) return;
|
|---|
| 135 | }
|
|---|
| 136 | switch (symbols.size()) {
|
|---|
| 137 | case 1:
|
|---|
| 138 | symbol(symbols.get(0), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 139 | break;
|
|---|
| 140 | case 2:
|
|---|
| 141 | symbol(symbols.get(0), new Delta(Handle.RC, new AffineTransform()));
|
|---|
| 142 | symbol(symbols.get(1), new Delta(Handle.LC, new AffineTransform()));
|
|---|
| 143 | break;
|
|---|
| 144 | case 3:
|
|---|
| 145 | symbol(symbols.get(0), new Delta(Handle.BC, new AffineTransform()));
|
|---|
| 146 | symbol(symbols.get(1), new Delta(Handle.TR, new AffineTransform()));
|
|---|
| 147 | symbol(symbols.get(2), new Delta(Handle.TL, new AffineTransform()));
|
|---|
| 148 | break;
|
|---|
| 149 | case 4:
|
|---|
| 150 | symbol(symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
|
|---|
| 151 | symbol(symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
|
|---|
| 152 | symbol(symbols.get(2), new Delta(Handle.TR, new AffineTransform()));
|
|---|
| 153 | symbol(symbols.get(3), new Delta(Handle.TL, new AffineTransform()));
|
|---|
| 154 | break;
|
|---|
| 155 | case 5:
|
|---|
| 156 | symbol(symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
|
|---|
| 157 | symbol(symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
|
|---|
| 158 | symbol(symbols.get(2), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 159 | symbol(symbols.get(3), new Delta(Handle.TC, new AffineTransform()));
|
|---|
| 160 | symbol(symbols.get(4), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 161 | break;
|
|---|
| 162 | case 6:
|
|---|
| 163 | symbol(symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 164 | symbol(symbols.get(1), new Delta(Handle.BC, new AffineTransform()));
|
|---|
| 165 | symbol(symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 166 | symbol(symbols.get(3), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 167 | symbol(symbols.get(4), new Delta(Handle.TC, new AffineTransform()));
|
|---|
| 168 | symbol(symbols.get(5), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 169 | break;
|
|---|
| 170 | case 7:
|
|---|
| 171 | symbol(symbols.get(0), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 172 | symbol(symbols.get(1), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 173 | symbol(symbols.get(2), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 174 | symbol(symbols.get(3), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 175 | symbol(symbols.get(4), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 176 | symbol(symbols.get(5), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 177 | symbol(symbols.get(6), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 178 | break;
|
|---|
| 179 | case 8:
|
|---|
| 180 | symbol(symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 181 | symbol(symbols.get(1), new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 182 | symbol(symbols.get(2), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 183 | symbol(symbols.get(3), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 184 | symbol(symbols.get(4), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 185 | symbol(symbols.get(5), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 186 | symbol(symbols.get(6), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 187 | symbol(symbols.get(7), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 188 | break;
|
|---|
| 189 | case 9:
|
|---|
| 190 | symbol(symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, -bbox.height/2)));
|
|---|
| 191 | symbol(symbols.get(1), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 192 | symbol(symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, -bbox.height/2)));
|
|---|
| 193 | symbol(symbols.get(3), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 194 | symbol(symbols.get(4), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 195 | symbol(symbols.get(5), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 196 | symbol(symbols.get(6), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 197 | symbol(symbols.get(7), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 198 | symbol(symbols.get(8), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 199 | break;
|
|---|
| 200 | }
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | private static Rectangle2D.Double symbolSize(Symbol symbol) {
|
|---|
| 204 | Symbol ssymb = symbol;
|
|---|
| 205 | while (ssymb != null) {
|
|---|
| 206 | for (Instr item : symbol) {
|
|---|
| 207 | if (item.type == Form.BBOX) {
|
|---|
| 208 | return (Rectangle2D.Double) item.params;
|
|---|
| 209 | }
|
|---|
| 210 | if (item.type == Form.SYMB) {
|
|---|
| 211 | ssymb = ((SubSymbol) item.params).instr;
|
|---|
| 212 | break;
|
|---|
| 213 | }
|
|---|
| 214 | }
|
|---|
| 215 | if (ssymb == symbol)
|
|---|
| 216 | break;
|
|---|
| 217 | }
|
|---|
| 218 | return null;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | public static void lineSymbols(Symbol prisymb, double space, Symbol secsymb, Symbol tersymb, int ratio, Color col) {
|
|---|
| 222 | if ((Rules.feature.geom.prim == Pflag.NOSP) || (Rules.feature.geom.prim == Pflag.POINT))
|
|---|
| 223 | return;
|
|---|
| 224 | Rectangle2D.Double prect = symbolSize(prisymb);
|
|---|
| 225 | Rectangle2D.Double srect = symbolSize(secsymb);
|
|---|
| 226 | Rectangle2D.Double trect = symbolSize(tersymb);
|
|---|
| 227 | if (srect == null)
|
|---|
| 228 | ratio = 0;
|
|---|
| 229 | if (prect != null) {
|
|---|
| 230 | double psize = Math.abs(prect.getY()) * sScale;
|
|---|
| 231 | double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
|
|---|
| 232 | double tsize = (trect != null) ? Math.abs(srect.getY()) * sScale : 0;
|
|---|
| 233 | Point2D prev = new Point2D.Double();
|
|---|
| 234 | Point2D next = new Point2D.Double();
|
|---|
| 235 | Point2D curr = new Point2D.Double();
|
|---|
| 236 | Point2D succ = new Point2D.Double();
|
|---|
| 237 | boolean gap = true;
|
|---|
| 238 | boolean piv = false;
|
|---|
| 239 | double len = 0;
|
|---|
| 240 | double angle = 0;
|
|---|
| 241 | int stcount = ratio;
|
|---|
| 242 | boolean stflag = false;
|
|---|
| 243 | Symbol symbol = prisymb;
|
|---|
| 244 | GeomIterator git = map.new GeomIterator(Rules.feature.geom);
|
|---|
| 245 | while (git.hasComp()) {
|
|---|
| 246 | git.nextComp();
|
|---|
| 247 | boolean first = true;
|
|---|
| 248 | while (git.hasEdge()) {
|
|---|
| 249 | git.nextEdge();
|
|---|
| 250 | while (git.hasNode()) {
|
|---|
| 251 | Snode node = git.next();
|
|---|
| 252 | if (node == null) continue;
|
|---|
| 253 | prev = next;
|
|---|
| 254 | next = context.getPoint(node);
|
|---|
| 255 | angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
|
|---|
| 256 | piv = true;
|
|---|
| 257 | if (first) {
|
|---|
| 258 | curr = succ = next;
|
|---|
| 259 | gap = (space > 0);
|
|---|
| 260 | stcount = ratio - 1;
|
|---|
| 261 | symbol = prisymb;
|
|---|
| 262 | len = gap ? psize * space * 0.5 : psize;
|
|---|
| 263 | first = false;
|
|---|
| 264 | } else {
|
|---|
| 265 | while (curr.distance(next) >= len) {
|
|---|
| 266 | if (piv) {
|
|---|
| 267 | double rem = len;
|
|---|
| 268 | double s = prev.distance(next);
|
|---|
| 269 | double p = curr.distance(prev);
|
|---|
| 270 | if ((s > 0) && (p > 0)) {
|
|---|
| 271 | double n = curr.distance(next);
|
|---|
| 272 | double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
|
|---|
| 273 | double phi = Math.asin(p / len * Math.sin(theta));
|
|---|
| 274 | rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
|
|---|
| 275 | }
|
|---|
| 276 | succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
|
|---|
| 277 | piv = false;
|
|---|
| 278 | } else {
|
|---|
| 279 | succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
|
|---|
| 280 | }
|
|---|
| 281 | if (!gap) {
|
|---|
| 282 | Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Scheme(col),
|
|---|
| 283 | new Delta(Handle.BC, AffineTransform.getRotateInstance(
|
|---|
| 284 | Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))));
|
|---|
| 285 | }
|
|---|
| 286 | if (space > 0)
|
|---|
| 287 | gap = !gap;
|
|---|
| 288 | curr = succ;
|
|---|
| 289 | len = gap ? (psize * space) : (--stcount == 0) ? (stflag ? tsize : ssize) : psize;
|
|---|
| 290 | if (stcount == 0) {
|
|---|
| 291 | symbol = stflag ? tersymb : secsymb;
|
|---|
| 292 | if (trect != null)
|
|---|
| 293 | stflag = !stflag;
|
|---|
| 294 | stcount = ratio;
|
|---|
| 295 | } else {
|
|---|
| 296 | symbol = prisymb;
|
|---|
| 297 | }
|
|---|
| 298 | }
|
|---|
| 299 | }
|
|---|
| 300 | }
|
|---|
| 301 | }
|
|---|
| 302 | }
|
|---|
| 303 | }
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | public static void lineVector(LineStyle style) {
|
|---|
| 307 | Path2D.Double p = new Path2D.Double();
|
|---|
| 308 | p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
|
|---|
| 309 | Point2D point;
|
|---|
| 310 | GeomIterator git = map.new GeomIterator(Rules.feature.geom);
|
|---|
| 311 | while (git.hasComp()) {
|
|---|
| 312 | git.nextComp();
|
|---|
| 313 | boolean first = true;
|
|---|
| 314 | while (git.hasEdge()) {
|
|---|
| 315 | git.nextEdge();
|
|---|
| 316 | point = context.getPoint(git.next());
|
|---|
| 317 | if (first) {
|
|---|
| 318 | p.moveTo(point.getX(), point.getY());
|
|---|
| 319 | first = false;
|
|---|
| 320 | } else {
|
|---|
| 321 | p.lineTo(point.getX(), point.getY());
|
|---|
| 322 | }
|
|---|
| 323 | while (git.hasNode()) {
|
|---|
| 324 | Snode node = git.next();
|
|---|
| 325 | if (node == null) continue;
|
|---|
| 326 | point = context.getPoint(node);
|
|---|
| 327 | p.lineTo(point.getX(), point.getY());
|
|---|
| 328 | }
|
|---|
| 329 | }
|
|---|
| 330 | }
|
|---|
| 331 | if ((style.fill != null) && (Rules.feature.geom.prim == Pflag.AREA)) {
|
|---|
| 332 | g2.setPaint(style.fill);
|
|---|
| 333 | g2.fill(p);
|
|---|
| 334 | }
|
|---|
| 335 | if (style.line != null) {
|
|---|
| 336 | if (style.dash != null) {
|
|---|
| 337 | float[] dash = new float[style.dash.length];
|
|---|
| 338 | System.arraycopy(style.dash, 0, dash, 0, style.dash.length);
|
|---|
| 339 | for (int i = 0; i < style.dash.length; i++) {
|
|---|
| 340 | dash[i] *= (float) sScale;
|
|---|
| 341 | }
|
|---|
| 342 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, dash, 0));
|
|---|
| 343 | } else {
|
|---|
| 344 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
|---|
| 345 | }
|
|---|
| 346 | g2.setPaint(style.line);
|
|---|
| 347 | g2.draw(p);
|
|---|
| 348 | }
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | public static void grid() {
|
|---|
| 352 | if ((context.grid() > 0) && (map != null)) {
|
|---|
| 353 | LineStyle style = new LineStyle(Color.black, (float)2.0);
|
|---|
| 354 | Point2D point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.maxlon));
|
|---|
| 355 | double ratio = point.getX() / point.getY();
|
|---|
| 356 | double nspan = 60 * Math.toDegrees(map.bounds.maxlon - map.bounds.minlon) / (context.grid() * (ratio > 1.0 ? ratio : 1.0));
|
|---|
| 357 | double mult = 1.0;
|
|---|
| 358 | boolean ndiv = false;
|
|---|
| 359 | if (nspan < 1.0) {
|
|---|
| 360 | do {
|
|---|
| 361 | nspan *= 10.0;
|
|---|
| 362 | mult *= 10.0;
|
|---|
| 363 | } while (nspan < 1.0);
|
|---|
| 364 | } else if (nspan > 10.0){
|
|---|
| 365 | do {
|
|---|
| 366 | nspan /= 10.0;
|
|---|
| 367 | mult /= 10.0;
|
|---|
| 368 | } while (nspan > 10.0);
|
|---|
| 369 | }
|
|---|
| 370 | if (nspan < 2.0) nspan = 1.0;
|
|---|
| 371 | else if (nspan < 5.0) nspan = 2.0;
|
|---|
| 372 | else {
|
|---|
| 373 | nspan = 5.0;
|
|---|
| 374 | ndiv = true;
|
|---|
| 375 | }
|
|---|
| 376 | nspan = nspan / mult / 60.0;
|
|---|
| 377 | double left = Math.toDegrees(map.bounds.minlon) + 180.0;
|
|---|
| 378 | left = Math.ceil(left / nspan);
|
|---|
| 379 | left = Math.toRadians((left * nspan) - 180.0);
|
|---|
| 380 | double ndeg = Math.toRadians(nspan);
|
|---|
| 381 | double tspan = 60 * Math.toDegrees(map.bounds.maxlat - map.bounds.minlat) / (context.grid() / (ratio < 1.0 ? ratio : 1.0));
|
|---|
| 382 | mult = 1.0;
|
|---|
| 383 | boolean tdiv = false;
|
|---|
| 384 | if (tspan < 1.0) {
|
|---|
| 385 | do {
|
|---|
| 386 | tspan *= 10.0;
|
|---|
| 387 | mult *= 10.0;
|
|---|
| 388 | } while (tspan < 1.0);
|
|---|
| 389 | } else if (tspan > 10.0){
|
|---|
| 390 | do {
|
|---|
| 391 | tspan /= 10.0;
|
|---|
| 392 | mult /= 10.0;
|
|---|
| 393 | } while (tspan > 10.0);
|
|---|
| 394 | }
|
|---|
| 395 | if (tspan < 2.0) tspan = 1.0;
|
|---|
| 396 | else if (tspan < 5.0) tspan = 2.0;
|
|---|
| 397 | else {
|
|---|
| 398 | tspan = 5.0;
|
|---|
| 399 | tdiv = true;
|
|---|
| 400 | }
|
|---|
| 401 | tspan = tspan / mult / 60.0;
|
|---|
| 402 | double bottom = Math.toDegrees(map.bounds.minlat) + 90.0;
|
|---|
| 403 | bottom = Math.ceil(bottom / tspan);
|
|---|
| 404 | bottom = Math.toRadians((bottom * tspan) - 90.0);
|
|---|
| 405 | double tdeg = Math.toRadians(tspan);
|
|---|
| 406 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
|
|---|
| 407 | Path2D.Double p = new Path2D.Double();
|
|---|
| 408 | for (double lon = left; lon < map.bounds.maxlon; lon += ndeg) {
|
|---|
| 409 | point = context.getPoint(new Snode(map.bounds.maxlat, lon));
|
|---|
| 410 | p.moveTo(point.getX(), point.getY());
|
|---|
| 411 | point = context.getPoint(new Snode(map.bounds.minlat, lon));
|
|---|
| 412 | p.lineTo(point.getX(), point.getY());
|
|---|
| 413 | double deg = Math.toDegrees(lon);
|
|---|
| 414 | String ew = (deg < -0.001) ? "W" : (deg > 0.001) ? "E" : "";
|
|---|
| 415 | deg = Math.abs(deg);
|
|---|
| 416 | String dstr = String.format("%03d°", (int)Math.floor(deg));
|
|---|
| 417 | double min = (deg - Math.floor(deg)) * 60.0;
|
|---|
| 418 | String mstr = String.format("%05.2f'%s", min, ew);
|
|---|
| 419 | Symbol label = new Symbol();
|
|---|
| 420 | if (point.getX() > 600.0) {
|
|---|
| 421 | label.add(new Instr(Form.TEXT, new Caption(dstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BR, AffineTransform.getTranslateInstance(-10, -40)))));
|
|---|
| 422 | 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)))));
|
|---|
| 423 | Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, null);
|
|---|
| 424 | }
|
|---|
| 425 | for (int i = 1; i < 10; i++) {
|
|---|
| 426 | int grad = (i % (ndiv ? 2 : 5)) == 0 ? 2 : 1;
|
|---|
| 427 | point = context.getPoint(new Snode(map.bounds.maxlat, lon + (i * (ndeg / 10))));
|
|---|
| 428 | p.moveTo(point.getX(), point.getY());
|
|---|
| 429 | point = context.getPoint(new Snode(map.bounds.maxlat - (grad * (tdeg / 20)), lon + (i * (ndeg / 10))));
|
|---|
| 430 | p.lineTo(point.getX(), point.getY());
|
|---|
| 431 | point = context.getPoint(new Snode(map.bounds.minlat, lon + (i * (ndeg / 10))));
|
|---|
| 432 | p.moveTo(point.getX(), point.getY());
|
|---|
| 433 | point = context.getPoint(new Snode(map.bounds.minlat + (grad * (tdeg / 20)), lon + (i * (ndeg / 10))));
|
|---|
| 434 | p.lineTo(point.getX(), point.getY());
|
|---|
| 435 | }
|
|---|
| 436 | }
|
|---|
| 437 | g2.setPaint(style.line);
|
|---|
| 438 | g2.draw(p);
|
|---|
| 439 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
|
|---|
| 440 | p = new Path2D.Double();
|
|---|
| 441 | for (double lat = bottom; lat < map.bounds.maxlat; lat += tdeg) {
|
|---|
| 442 | point = context.getPoint(new Snode(lat, map.bounds.maxlon));
|
|---|
| 443 | p.moveTo(point.getX(), point.getY());
|
|---|
| 444 | point = context.getPoint(new Snode(lat, map.bounds.minlon));
|
|---|
| 445 | p.lineTo(point.getX(), point.getY());
|
|---|
| 446 | double deg = Math.toDegrees(lat);
|
|---|
| 447 | String ns = (deg < -0.001) ? "S" : (deg > 0.001) ? "N" : "";
|
|---|
| 448 | deg = Math.abs(deg);
|
|---|
| 449 | String dstr = String.format("%02d°%s", (int)Math.floor(deg), ns);
|
|---|
| 450 | double min = (deg - Math.floor(deg)) * 60.0;
|
|---|
| 451 | String mstr = String.format("%05.2f'", min);
|
|---|
| 452 | Symbol label = new Symbol();
|
|---|
| 453 | if (point.getY() < (context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon)).getY() - 200.0)) {
|
|---|
| 454 | label.add(new Instr(Form.TEXT, new Caption(dstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BL, AffineTransform.getTranslateInstance(40, -10)))));
|
|---|
| 455 | 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)))));
|
|---|
| 456 | Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, null);
|
|---|
| 457 | }
|
|---|
| 458 | for (int i = 1; i < 10; i++) {
|
|---|
| 459 | int grad = (i % (tdiv ? 2 : 5)) == 0 ? 2 : 1;
|
|---|
| 460 | point = context.getPoint(new Snode(lat + (i * (tdeg / 10)), map.bounds.maxlon));
|
|---|
| 461 | p.moveTo(point.getX(), point.getY());
|
|---|
| 462 | point = context.getPoint(new Snode(lat + (i * (tdeg / 10)), map.bounds.maxlon - (grad * (ndeg / 20))));
|
|---|
| 463 | p.lineTo(point.getX(), point.getY());
|
|---|
| 464 | point = context.getPoint(new Snode(lat + (i * (tdeg / 10)), map.bounds.minlon));
|
|---|
| 465 | p.moveTo(point.getX(), point.getY());
|
|---|
| 466 | point = context.getPoint(new Snode(lat + (i * (tdeg / 10)), map.bounds.minlon + (grad * (ndeg / 20))));
|
|---|
| 467 | p.lineTo(point.getX(), point.getY());
|
|---|
| 468 | }
|
|---|
| 469 | }
|
|---|
| 470 | g2.setPaint(style.line);
|
|---|
| 471 | g2.draw(p);
|
|---|
| 472 | Symbol legend = new Symbol();
|
|---|
| 473 | legend.add(new Instr(Form.BBOX, new Rectangle2D.Double(0, 0, 600, 250)));
|
|---|
| 474 | Path2D.Double path = new Path2D.Double(); path.moveTo(0, 0); path.lineTo(600, 0); path.lineTo(600, 250); path.lineTo(0, 250); path.closePath();
|
|---|
| 475 | legend.add(new Instr(Form.FILL, Color.white));
|
|---|
| 476 | legend.add(new Instr(Form.PGON, path));
|
|---|
| 477 | legend.add(new Instr(Form.TEXT, new Caption("Mercator Projection", new Font("Arial", Font.PLAIN, 50), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(300, 60)))));
|
|---|
| 478 | legend.add(new Instr(Form.TEXT, new Caption("© OpenStreetMap contributors", new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 40)))));
|
|---|
| 479 | legend.add(new Instr(Form.TEXT, new Caption("EMODnet Bathymetry Consortium (2018)", new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 40)))));
|
|---|
| 480 | legend.add(new Instr(Form.TEXT, new Caption("EMODnet Digital Bathymetry (DTM)", new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 40)))));
|
|---|
| 481 | legend.add(new Instr(Form.TEXT, new Caption("http://doi.org/10.12770/18ff0d48-b203-4a65-94a9-5fd8b0ec35f6", new Font("Arial", Font.PLAIN, 20), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 35)))));
|
|---|
| 482 | point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon));
|
|---|
| 483 | Symbols.drawSymbol(g2, legend, sScale, point.getX(), point.getY(), null, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 0)));
|
|---|
| 484 | }
|
|---|
| 485 | }
|
|---|
| 486 |
|
|---|
| 487 | public static void rose() {
|
|---|
| 488 | LineStyle style = new LineStyle(Color.black, (float)2.0);
|
|---|
| 489 | Point2D point = context.getPoint(new Snode(Math.toRadians(53.91649), Math.toRadians(-0.16141)));
|
|---|
| 490 | g2.setPaint(Color.white);
|
|---|
| 491 | g2.fill(new Ellipse2D.Double(point.getX() - 30, point.getY() - 30, 60, 60));
|
|---|
| 492 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
|
|---|
| 493 | Path2D.Double p = new Path2D.Double();
|
|---|
| 494 | p.moveTo(point.getX() - 30, point.getY());p.lineTo(point.getX() + 30, point.getY());
|
|---|
| 495 | p.moveTo(point.getX(), point.getY() - 30);p.lineTo(point.getX(), point.getY() + 30);
|
|---|
| 496 | for (int i = 0; i < 360; i++) {
|
|---|
| 497 | double inner = ((i % 10) == 0) ? 0.92 : ((i % 5) == 0) ? 0.96 : 0.98;
|
|---|
| 498 | double xouter = 1750 * Math.sin(Math.toRadians(i));
|
|---|
| 499 | double youter = -1750 * Math.cos(Math.toRadians(i));
|
|---|
| 500 | p.moveTo(point.getX() + xouter, point.getY() + youter);
|
|---|
| 501 | p.lineTo(point.getX() + (inner * xouter), point.getY() + (inner * youter));
|
|---|
| 502 | if ((i % 10) == 0) {
|
|---|
| 503 | Handle h = Handle.BC;
|
|---|
| 504 | if ((i > 0) && (i <= 90)) h = Handle.BL;
|
|---|
| 505 | else if (i == 90) h = Handle.LC;
|
|---|
| 506 | else if ((i > 90) && (i < 180)) h = Handle.LC;
|
|---|
| 507 | else if (i == 180) h = Handle.CC;
|
|---|
| 508 | else if ((i > 180) && (i <= 270)) h = Handle.RC;
|
|---|
| 509 | else if (i > 270) h = Handle.BR;
|
|---|
| 510 | Symbol value = new Symbol();
|
|---|
| 511 | value.add(new Instr(Form.BBOX, new Rectangle2D.Double(0, 0, 60, 30)));
|
|---|
| 512 | value.add(new Instr(Form.TEXT, new Caption(String.format("%03d", i), new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.CC, AffineTransform.getTranslateInstance(30, 25)))));
|
|---|
| 513 | Symbols.drawSymbol(g2, value, sScale, point.getX(), point.getY(), null, new Delta(h, AffineTransform.getTranslateInstance(1.02*xouter/sScale, 1.02*youter/sScale)));
|
|---|
| 514 | }
|
|---|
| 515 | }
|
|---|
| 516 | g2.setPaint(style.line);
|
|---|
| 517 | g2.draw(p);
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | public static void lineCircle(LineStyle style, double radius, UniHLU units) {
|
|---|
| 521 | switch (units) {
|
|---|
| 522 | case HLU_FEET:
|
|---|
| 523 | radius /= 6076;
|
|---|
| 524 | break;
|
|---|
| 525 | case HLU_KMTR:
|
|---|
| 526 | radius /= 1.852;
|
|---|
| 527 | break;
|
|---|
| 528 | case HLU_HMTR:
|
|---|
| 529 | radius /= 18.52;
|
|---|
| 530 | break;
|
|---|
| 531 | case HLU_SMIL:
|
|---|
| 532 | radius /= 1.15078;
|
|---|
| 533 | break;
|
|---|
| 534 | case HLU_NMIL:
|
|---|
| 535 | break;
|
|---|
| 536 | default:
|
|---|
| 537 | radius /= 1852;
|
|---|
| 538 | break;
|
|---|
| 539 | }
|
|---|
| 540 | radius *= context.mile(Rules.feature);
|
|---|
| 541 | Symbol circle = new Symbol();
|
|---|
| 542 | if (style.fill != null) {
|
|---|
| 543 | circle.add(new Instr(Form.FILL, style.fill));
|
|---|
| 544 | circle.add(new Instr(Form.RSHP, new Ellipse2D.Double(-radius, -radius, radius*2, radius*2)));
|
|---|
| 545 | }
|
|---|
| 546 | circle.add(new Instr(Form.FILL, style.line));
|
|---|
| 547 | circle.add(new Instr(Form.STRK, new BasicStroke(style.width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, style.dash, 0)));
|
|---|
| 548 | circle.add(new Instr(Form.ELPS, new Ellipse2D.Double(-radius, -radius, radius*2, radius*2)));
|
|---|
| 549 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 550 | Symbols.drawSymbol(g2, circle, 1, point.getX(), point.getY(), null, null);
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | public static void fillPattern(BufferedImage image) {
|
|---|
| 554 | Path2D.Double p = new Path2D.Double();
|
|---|
| 555 | p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
|
|---|
| 556 | Point2D point;
|
|---|
| 557 | switch (Rules.feature.geom.prim) {
|
|---|
| 558 | case POINT:
|
|---|
| 559 | point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 560 | g2.drawImage(image, new AffineTransformOp(AffineTransform.getScaleInstance(sScale, sScale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
|
|---|
| 561 | (int) (point.getX() - (sScale * image.getWidth() / 2)), (int) (point.getY() - (sScale * image.getHeight() / 2)));
|
|---|
| 562 | break;
|
|---|
| 563 | case AREA:
|
|---|
| 564 | GeomIterator git = map.new GeomIterator(Rules.feature.geom);
|
|---|
| 565 | while (git.hasComp()) {
|
|---|
| 566 | git.nextComp();
|
|---|
| 567 | boolean newComp = true;
|
|---|
| 568 | while (git.hasEdge()) {
|
|---|
| 569 | git.nextEdge();
|
|---|
| 570 | point = context.getPoint(git.next());
|
|---|
| 571 | if (newComp) {
|
|---|
| 572 | p.moveTo(point.getX(), point.getY());
|
|---|
| 573 | newComp = false;
|
|---|
| 574 | } else {
|
|---|
| 575 | p.lineTo(point.getX(), point.getY());
|
|---|
| 576 | }
|
|---|
| 577 | while (git.hasNode()) {
|
|---|
| 578 | Snode node = git.next();
|
|---|
| 579 | if (node == null) continue;
|
|---|
| 580 | point = context.getPoint(node);
|
|---|
| 581 | p.lineTo(point.getX(), point.getY());
|
|---|
| 582 | }
|
|---|
| 583 | }
|
|---|
| 584 | }
|
|---|
| 585 | g2.setPaint(new TexturePaint(image, new Rectangle(0, 0, (1 + (int) (150 * sScale)), (1 + (int) (150 * sScale)))));
|
|---|
| 586 | g2.fill(p);
|
|---|
| 587 | break;
|
|---|
| 588 | default:
|
|---|
| 589 | break;
|
|---|
| 590 | }
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | public static void labelText(String str, Font font, Color tc) {
|
|---|
| 594 | labelText(str, font, tc, LabelStyle.NONE, null, null, null);
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 | public static void labelText(String str, Font font, Color tc, Delta delta) {
|
|---|
| 598 | labelText(str, font, tc, LabelStyle.NONE, null, null, delta);
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | public static void labelText(String str, Font font, Color tc, LabelStyle style, Color fg) {
|
|---|
| 602 | labelText(str, font, tc, style, fg, null, null);
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | public static void labelText(String str, Font font, Color tc, LabelStyle style, Color fg, Color bg) {
|
|---|
| 606 | labelText(str, font, tc, style, fg, bg, null);
|
|---|
| 607 | }
|
|---|
| 608 |
|
|---|
| 609 | public static void labelText(String str, Font font, Color tc, LabelStyle style, Color fg, Delta delta) {
|
|---|
| 610 | labelText(str, font, tc, style, fg, null, delta);
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | public static void labelText(String str, Font font, Color tc, LabelStyle style, Color fg, Color bg, Delta delta) {
|
|---|
| 614 | if (delta == null) delta = new Delta(Handle.CC);
|
|---|
| 615 | if (bg == null) bg = new Color(0x00000000, true);
|
|---|
| 616 | if (str == null || str.isEmpty()) str = " ";
|
|---|
| 617 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 618 | GlyphVector gv = font.deriveFont((float) font.getSize()).createGlyphVector(frc, str.equals(" ") ? "M" : str);
|
|---|
| 619 | Rectangle2D bounds = gv.getVisualBounds();
|
|---|
| 620 | double width = bounds.getWidth();
|
|---|
| 621 | double height = bounds.getHeight();
|
|---|
| 622 | Symbol label = new Symbol();
|
|---|
| 623 | double lx, ly, tx, ty;
|
|---|
| 624 | switch (style) {
|
|---|
| 625 | case RRCT:
|
|---|
| 626 | width += height * 1.0;
|
|---|
| 627 | height *= 1.5;
|
|---|
| 628 | if (width < height) width = height;
|
|---|
| 629 | lx = -width / 2;
|
|---|
| 630 | ly = -height / 2;
|
|---|
| 631 | tx = lx + (height * 0.34);
|
|---|
| 632 | ty = ly + (height * 0.17);
|
|---|
| 633 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 634 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 635 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 636 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 637 | label.add(new Instr(Form.STRK, new BasicStroke(1 + (int) (height/10), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 638 | label.add(new Instr(Form.RRCT, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 639 | break;
|
|---|
| 640 | case VCLR:
|
|---|
| 641 | width += height * 1.0;
|
|---|
| 642 | height *= 2.0;
|
|---|
| 643 | if (width < height) width = height;
|
|---|
| 644 | lx = -width / 2;
|
|---|
| 645 | ly = -height / 2;
|
|---|
| 646 | tx = lx + (height * 0.27);
|
|---|
| 647 | ty = ly + (height * 0.25);
|
|---|
| 648 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 649 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 650 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 651 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 652 | int sw = 1 + (int) (height/10);
|
|---|
| 653 | double po = sw / 2;
|
|---|
| 654 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 655 | Path2D.Double p = new Path2D.Double(); p.moveTo(-height*0.2, -ly-po);
|
|---|
| 656 | p.lineTo(height*0.2, -ly-po); p.moveTo(0, -ly-po); p.lineTo(0, -ly-po-(height*0.15));
|
|---|
| 657 | p.moveTo(-height*0.2, ly+po); p.lineTo((height*0.2), ly+po); p.moveTo(0, ly+po); p.lineTo(0, ly+po+(height*0.15));
|
|---|
| 658 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 659 | break;
|
|---|
| 660 | case PCLR:
|
|---|
| 661 | width += height * 1.0;
|
|---|
| 662 | height *= 2.0;
|
|---|
| 663 | if (width < height) width = height;
|
|---|
| 664 | lx = -width / 2;
|
|---|
| 665 | ly = -height / 2;
|
|---|
| 666 | tx = lx + (height * 0.27);
|
|---|
| 667 | ty = ly + (height * 0.25);
|
|---|
| 668 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 669 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 670 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 671 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 672 | sw = 1 + (int) (height/10);
|
|---|
| 673 | po = sw / 2;
|
|---|
| 674 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 675 | p = new Path2D.Double();
|
|---|
| 676 | p.moveTo(-height*0.2, -ly-po);
|
|---|
| 677 | p.lineTo(height*0.2, -ly-po);
|
|---|
| 678 | p.moveTo(0, -ly-po);
|
|---|
| 679 | p.lineTo(0, -ly-po-(height*0.15));
|
|---|
| 680 | p.moveTo(-height*0.2, ly+po);
|
|---|
| 681 | p.lineTo((height*0.2), ly+po);
|
|---|
| 682 | p.moveTo(0, ly+po);
|
|---|
| 683 | p.lineTo(0, ly+po+(height*0.15));
|
|---|
| 684 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 685 | label.add(new Instr(Form.SYMB, new Symbols.SubSymbol(Areas.CableFlash, 1, 0, 0, null,
|
|---|
| 686 | new Delta(Handle.CC, new AffineTransform(0, -1, 1, 0, -width/2, 0)))));
|
|---|
| 687 | label.add(new Instr(Form.SYMB, new Symbols.SubSymbol(Areas.CableFlash, 1, 0, 0, null,
|
|---|
| 688 | new Delta(Handle.CC, new AffineTransform(0, -1, 1, 0, width/2, 0)))));
|
|---|
| 689 | break;
|
|---|
| 690 | case HCLR:
|
|---|
| 691 | width += height * 1.5;
|
|---|
| 692 | height *= 1.5;
|
|---|
| 693 | if (width < height) width = height;
|
|---|
| 694 | lx = -width / 2;
|
|---|
| 695 | ly = -height / 2;
|
|---|
| 696 | tx = lx + (height * 0.5);
|
|---|
| 697 | ty = ly + (height * 0.17);
|
|---|
| 698 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 699 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 700 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 701 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 702 | sw = 1 + (int) (height/10);
|
|---|
| 703 | double vo = height / 4;
|
|---|
| 704 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 705 | p = new Path2D.Double();
|
|---|
| 706 | p.moveTo(-width*0.4-sw, -ly-vo);
|
|---|
| 707 | p.lineTo(-width*0.4-sw, ly+vo);
|
|---|
| 708 | p.moveTo(-width*0.4-sw, 0);
|
|---|
| 709 | p.lineTo(-width*0.4+sw, 0);
|
|---|
| 710 | p.moveTo(width*0.4+sw, -ly-vo);
|
|---|
| 711 | p.lineTo(width*0.4+sw, ly+vo);
|
|---|
| 712 | p.moveTo(width*0.4-sw, 0);
|
|---|
| 713 | p.lineTo(width*0.4+sw, 0);
|
|---|
| 714 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 715 | break;
|
|---|
| 716 | default:
|
|---|
| 717 | lx = -width / 2;
|
|---|
| 718 | ly = -height / 2;
|
|---|
| 719 | tx = lx;
|
|---|
| 720 | ty = ly;
|
|---|
| 721 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 722 | break;
|
|---|
| 723 | }
|
|---|
| 724 | label.add(new Instr(Form.TEXT, new Caption(str, font, tc, new Delta(Handle.TL, AffineTransform.getTranslateInstance(tx, ty)))));
|
|---|
| 725 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 726 | Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, delta);
|
|---|
| 727 | }
|
|---|
| 728 |
|
|---|
| 729 | public static void lineText(String str, Font font, Color colour, double dy) {
|
|---|
| 730 | if (!str.isEmpty()) {
|
|---|
| 731 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|---|
| 732 | g2.setPaint(colour);
|
|---|
| 733 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 734 | GlyphVector gv = font.deriveFont(font.getSize2D() * (float) sScale).createGlyphVector(frc, str);
|
|---|
| 735 | double width = gv.getVisualBounds().getWidth();
|
|---|
| 736 | double height = gv.getVisualBounds().getHeight();
|
|---|
| 737 | double offset = (Rules.feature.geom.length * context.mile(Rules.feature) - width) / 2;
|
|---|
| 738 | if (offset > 0) {
|
|---|
| 739 | Point2D before = null;
|
|---|
| 740 | Point2D after = null;
|
|---|
| 741 | ArrayList<Point2D> between = new ArrayList<>();
|
|---|
| 742 | Point2D prev = null;
|
|---|
| 743 | Point2D next = null;
|
|---|
| 744 | double length = 0;
|
|---|
| 745 | double lb = 0;
|
|---|
| 746 | double la = 0;
|
|---|
| 747 | GeomIterator git = map.new GeomIterator(Rules.feature.geom);
|
|---|
| 748 | if (git.hasComp()) {
|
|---|
| 749 | git.nextComp();
|
|---|
| 750 | while (git.hasEdge()) {
|
|---|
| 751 | git.nextEdge();
|
|---|
| 752 | while (git.hasNode()) {
|
|---|
| 753 | Snode node = git.next();
|
|---|
| 754 | if (node == null)
|
|---|
| 755 | continue;
|
|---|
| 756 | prev = next;
|
|---|
| 757 | next = context.getPoint(node);
|
|---|
| 758 | if (prev != null)
|
|---|
| 759 | length += Math.sqrt(Math.pow((next.getX() - prev.getX()), 2) + Math.pow((next.getY() - prev.getY()), 2));
|
|---|
| 760 | if (length < offset) {
|
|---|
| 761 | before = next;
|
|---|
| 762 | lb = la = length;
|
|---|
| 763 | } else if (after == null) {
|
|---|
| 764 | if (length > (offset + width)) {
|
|---|
| 765 | after = next;
|
|---|
| 766 | la = length;
|
|---|
| 767 | break;
|
|---|
| 768 | } else {
|
|---|
| 769 | between.add(next);
|
|---|
| 770 | }
|
|---|
| 771 | }
|
|---|
| 772 | }
|
|---|
| 773 | if (after != null)
|
|---|
| 774 | break;
|
|---|
| 775 | }
|
|---|
| 776 | }
|
|---|
| 777 | if (after != null) {
|
|---|
| 778 | double angle = Math.atan2((after.getY() - before.getY()), (after.getX() - before.getX()));
|
|---|
| 779 | double rotate = Math.abs(angle) < (Math.PI / 2) ? angle : angle + Math.PI;
|
|---|
| 780 | Point2D mid = new Point2D.Double((before.getX() + after.getX()) / 2, (before.getY() + after.getY()) / 2);
|
|---|
| 781 | Point2D centre = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 782 | AffineTransform pos = AffineTransform.getTranslateInstance(-dy * Math.sin(rotate), dy * Math.cos(rotate));
|
|---|
| 783 | pos.rotate(rotate);
|
|---|
| 784 | pos.translate((mid.getX() - centre.getX()), (mid.getY() - centre.getY()));
|
|---|
| 785 | Symbol label = new Symbol();
|
|---|
| 786 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double((-width / 2), -height, width, height)));
|
|---|
| 787 | label.add(new Instr(Form.TEXT, new Caption(str, font, colour, new Delta(Handle.BC))));
|
|---|
| 788 | Symbols.drawSymbol(g2, label, sScale, centre.getX(), centre.getY(), null, new Delta(Handle.BC, pos));
|
|---|
| 789 | }
|
|---|
| 790 | }
|
|---|
| 791 | }
|
|---|
| 792 | }
|
|---|
| 793 |
|
|---|
| 794 | public static void lightSector(Color col1, Color col2, double radius, double s1, double s2, Double dir, String str) {
|
|---|
| 795 | double mid = (((s1 + s2) / 2) + (s1 > s2 ? 180 : 0)) % 360;
|
|---|
| 796 | g2.setStroke(new BasicStroke((float) (3.0 * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1,
|
|---|
| 797 | new float[] {20 * (float) sScale, 20 * (float) sScale}, 0));
|
|---|
| 798 | g2.setPaint(Color.black);
|
|---|
| 799 | Point2D.Double centre = (Point2D.Double) context.getPoint(Rules.feature.geom.centre);
|
|---|
| 800 | double radial = radius * context.mile(Rules.feature);
|
|---|
| 801 | if (dir != null) {
|
|---|
| 802 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(dir)),
|
|---|
| 803 | centre.y + radial * Math.cos(Math.toRadians(dir))));
|
|---|
| 804 | } else {
|
|---|
| 805 | if ((s1 != 0.0) || (s2 != 360.0)) {
|
|---|
| 806 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(s1)),
|
|---|
| 807 | centre.y + radial * Math.cos(Math.toRadians(s1))));
|
|---|
| 808 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(s2)),
|
|---|
| 809 | centre.y + radial * Math.cos(Math.toRadians(s2))));
|
|---|
| 810 | }
|
|---|
| 811 | }
|
|---|
| 812 | double arcWidth = 10.0 * sScale;
|
|---|
| 813 | g2.setStroke(new BasicStroke((float) arcWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1));
|
|---|
| 814 | g2.setPaint(col1);
|
|---|
| 815 | g2.draw(new Arc2D.Double(centre.x - radial, centre.y - radial, 2 * radial, 2 * radial, -(s1 + 90),
|
|---|
| 816 | ((s1 < s2) ? (s1 - s2) : (s1 - s2 - 360)), Arc2D.OPEN));
|
|---|
| 817 | if (col2 != null) {
|
|---|
| 818 | g2.setPaint(col2);
|
|---|
| 819 | g2.draw(new Arc2D.Double(centre.x - radial + arcWidth, centre.y - radial + arcWidth, 2 * (radial - arcWidth),
|
|---|
| 820 | 2 * (radial - arcWidth), -(s1 + 90), ((s1 < s2) ? (s1 - s2) : (s1 - s2 - 360)), Arc2D.OPEN));
|
|---|
| 821 | }
|
|---|
| 822 | if (str != null && !str.isEmpty()) {
|
|---|
| 823 | Font font = new Font("Arial", Font.PLAIN, 40);
|
|---|
| 824 | double arc = (s2 > s1) ? (s2 - s1) : (s2 - s1 + 360);
|
|---|
| 825 | double awidth = (Math.toRadians(arc) * radial);
|
|---|
| 826 | boolean hand = ((mid > 270) || (mid < 90));
|
|---|
| 827 | double phi = Math.toRadians(mid);
|
|---|
| 828 | radial += 30 * sScale;
|
|---|
| 829 | AffineTransform at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale);
|
|---|
| 830 | if ((font.getSize() * sScale * str.length()) < awidth) {
|
|---|
| 831 | at.rotate(Math.toRadians(mid + (hand ? 0 : 180)));
|
|---|
| 832 | labelText(str, font, Color.black, new Delta(Handle.CC, at));
|
|---|
| 833 | } else if ((font.getSize() * sScale) < awidth) {
|
|---|
| 834 | hand = (mid < 180);
|
|---|
| 835 | at.rotate(Math.toRadians(mid + (hand ? -90 : 90)));
|
|---|
| 836 | labelText(str, font, Color.black, hand ? new Delta(Handle.RC, at) : new Delta(Handle.LC, at));
|
|---|
| 837 | }
|
|---|
| 838 | if (dir != null) {
|
|---|
| 839 | font = new Font("Arial", Font.PLAIN, 30);
|
|---|
| 840 | str = dir + "°";
|
|---|
| 841 | hand = (dir > 180);
|
|---|
| 842 | phi = Math.toRadians(dir + (hand ? -0.5 : 0.5));
|
|---|
| 843 | radial -= 70 * sScale;
|
|---|
| 844 | at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale);
|
|---|
| 845 | at.rotate(Math.toRadians(dir + (hand ? 90 : -90)));
|
|---|
| 846 | labelText(str, font, Color.black, hand ? new Delta(Handle.BR, at) : new Delta(Handle.BL, at));
|
|---|
| 847 | }
|
|---|
| 848 | }
|
|---|
| 849 | }
|
|---|
| 850 |
|
|---|
| 851 | public static void rasterPixel(double size, Color col) {
|
|---|
| 852 | double s = Rules.feature.geom.centre.lat - (size / 2.0);
|
|---|
| 853 | double w = Rules.feature.geom.centre.lon - (size / 2.0);
|
|---|
| 854 | double n = Rules.feature.geom.centre.lat + (size / 2.0);
|
|---|
| 855 | double e = Rules.feature.geom.centre.lon + (size / 2.0);
|
|---|
| 856 | Point2D sw = context.getPoint(new Snode(s, w));
|
|---|
| 857 | Point2D nw = context.getPoint(new Snode(n, w));
|
|---|
| 858 | Point2D ne = context.getPoint(new Snode(n, e));
|
|---|
| 859 | Point2D se = context.getPoint(new Snode(s, e));
|
|---|
| 860 | Symbol pixel = new Symbol();
|
|---|
| 861 | Path2D.Double path = new Path2D.Double(); path.moveTo(sw.getX(), sw.getY()); path.lineTo(nw.getX(), nw.getY());
|
|---|
| 862 | path.lineTo(ne.getX(), ne.getY()); path.lineTo(se.getX(), se.getY()); path.closePath();
|
|---|
| 863 | pixel.add(new Instr(Form.FILL, col));
|
|---|
| 864 | pixel.add(new Instr(Form.PGON, path));
|
|---|
| 865 | Symbols.drawSymbol(g2, pixel, 1.0, 0, 0, null, null);
|
|---|
| 866 | }
|
|---|
| 867 | }
|
|---|