| 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 | grid();
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | public static void symbol(Symbol symbol) {
|
|---|
| 85 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 86 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, null);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | public static void symbol(Symbol symbol, Scheme scheme) {
|
|---|
| 90 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 91 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, null);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | public static void symbol(Symbol symbol, Delta delta) {
|
|---|
| 95 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 96 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, delta);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | public static void symbol(Symbol symbol, Scheme scheme, Delta delta) {
|
|---|
| 100 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 101 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, delta);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | public static void cluster(ArrayList<Symbol> symbols) {
|
|---|
| 105 | Rectangle2D.Double bbox = null;
|
|---|
| 106 | if (symbols.size() > 4) {
|
|---|
| 107 | for (Instr instr : symbols.get(0)) {
|
|---|
| 108 | if (instr.type == Form.BBOX) {
|
|---|
| 109 | bbox = (Rectangle2D.Double) instr.params;
|
|---|
| 110 | break;
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | if (bbox == null) return;
|
|---|
| 114 | }
|
|---|
| 115 | switch (symbols.size()) {
|
|---|
| 116 | case 1:
|
|---|
| 117 | symbol(symbols.get(0), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 118 | break;
|
|---|
| 119 | case 2:
|
|---|
| 120 | symbol(symbols.get(0), new Delta(Handle.RC, new AffineTransform()));
|
|---|
| 121 | symbol(symbols.get(1), new Delta(Handle.LC, new AffineTransform()));
|
|---|
| 122 | break;
|
|---|
| 123 | case 3:
|
|---|
| 124 | symbol(symbols.get(0), new Delta(Handle.BC, new AffineTransform()));
|
|---|
| 125 | symbol(symbols.get(1), new Delta(Handle.TR, new AffineTransform()));
|
|---|
| 126 | symbol(symbols.get(2), new Delta(Handle.TL, new AffineTransform()));
|
|---|
| 127 | break;
|
|---|
| 128 | case 4:
|
|---|
| 129 | symbol(symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
|
|---|
| 130 | symbol(symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
|
|---|
| 131 | symbol(symbols.get(2), new Delta(Handle.TR, new AffineTransform()));
|
|---|
| 132 | symbol(symbols.get(3), new Delta(Handle.TL, new AffineTransform()));
|
|---|
| 133 | break;
|
|---|
| 134 | case 5:
|
|---|
| 135 | symbol(symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
|
|---|
| 136 | symbol(symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
|
|---|
| 137 | symbol(symbols.get(2), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 138 | symbol(symbols.get(3), new Delta(Handle.TC, new AffineTransform()));
|
|---|
| 139 | symbol(symbols.get(4), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 140 | break;
|
|---|
| 141 | case 6:
|
|---|
| 142 | symbol(symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 143 | symbol(symbols.get(1), new Delta(Handle.BC, new AffineTransform()));
|
|---|
| 144 | symbol(symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 145 | symbol(symbols.get(3), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 146 | symbol(symbols.get(4), new Delta(Handle.TC, new AffineTransform()));
|
|---|
| 147 | symbol(symbols.get(5), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 148 | break;
|
|---|
| 149 | case 7:
|
|---|
| 150 | symbol(symbols.get(0), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 151 | symbol(symbols.get(1), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 152 | symbol(symbols.get(2), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 153 | symbol(symbols.get(3), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 154 | symbol(symbols.get(4), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 155 | symbol(symbols.get(5), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 156 | symbol(symbols.get(6), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 157 | break;
|
|---|
| 158 | case 8:
|
|---|
| 159 | symbol(symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 160 | symbol(symbols.get(1), new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 161 | symbol(symbols.get(2), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 162 | symbol(symbols.get(3), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 163 | symbol(symbols.get(4), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 164 | symbol(symbols.get(5), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 165 | symbol(symbols.get(6), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 166 | symbol(symbols.get(7), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 167 | break;
|
|---|
| 168 | case 9:
|
|---|
| 169 | symbol(symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, -bbox.height/2)));
|
|---|
| 170 | symbol(symbols.get(1), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 171 | symbol(symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, -bbox.height/2)));
|
|---|
| 172 | symbol(symbols.get(3), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 173 | symbol(symbols.get(4), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 174 | symbol(symbols.get(5), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 175 | symbol(symbols.get(6), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 176 | symbol(symbols.get(7), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 177 | symbol(symbols.get(8), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 178 | break;
|
|---|
| 179 | }
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | private static Rectangle2D.Double symbolSize(Symbol symbol) {
|
|---|
| 183 | Symbol ssymb = symbol;
|
|---|
| 184 | while (ssymb != null) {
|
|---|
| 185 | for (Instr item : symbol) {
|
|---|
| 186 | if (item.type == Form.BBOX) {
|
|---|
| 187 | return (Rectangle2D.Double) item.params;
|
|---|
| 188 | }
|
|---|
| 189 | if (item.type == Form.SYMB) {
|
|---|
| 190 | ssymb = ((SubSymbol) item.params).instr;
|
|---|
| 191 | break;
|
|---|
| 192 | }
|
|---|
| 193 | }
|
|---|
| 194 | if (ssymb == symbol)
|
|---|
| 195 | break;
|
|---|
| 196 | }
|
|---|
| 197 | return null;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | public static void lineSymbols(Symbol prisymb, double space, Symbol secsymb, Symbol tersymb, int ratio, Color col) {
|
|---|
| 201 | if ((Rules.feature.geom.prim == Pflag.NOSP) || (Rules.feature.geom.prim == Pflag.POINT))
|
|---|
| 202 | return;
|
|---|
| 203 | Rectangle2D.Double prect = symbolSize(prisymb);
|
|---|
| 204 | Rectangle2D.Double srect = symbolSize(secsymb);
|
|---|
| 205 | Rectangle2D.Double trect = symbolSize(tersymb);
|
|---|
| 206 | if (srect == null)
|
|---|
| 207 | ratio = 0;
|
|---|
| 208 | if (prect != null) {
|
|---|
| 209 | double psize = Math.abs(prect.getY()) * sScale;
|
|---|
| 210 | double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
|
|---|
| 211 | double tsize = (trect != null) ? Math.abs(srect.getY()) * sScale : 0;
|
|---|
| 212 | Point2D prev = new Point2D.Double();
|
|---|
| 213 | Point2D next = new Point2D.Double();
|
|---|
| 214 | Point2D curr = new Point2D.Double();
|
|---|
| 215 | Point2D succ = new Point2D.Double();
|
|---|
| 216 | boolean gap = true;
|
|---|
| 217 | boolean piv = false;
|
|---|
| 218 | double len = 0;
|
|---|
| 219 | double angle = 0;
|
|---|
| 220 | int stcount = ratio;
|
|---|
| 221 | boolean stflag = false;
|
|---|
| 222 | Symbol symbol = prisymb;
|
|---|
| 223 | GeomIterator git = map.new GeomIterator(Rules.feature.geom);
|
|---|
| 224 | while (git.hasComp()) {
|
|---|
| 225 | git.nextComp();
|
|---|
| 226 | boolean first = true;
|
|---|
| 227 | while (git.hasEdge()) {
|
|---|
| 228 | git.nextEdge();
|
|---|
| 229 | while (git.hasNode()) {
|
|---|
| 230 | Snode node = git.next();
|
|---|
| 231 | if (node == null) continue;
|
|---|
| 232 | prev = next;
|
|---|
| 233 | next = context.getPoint(node);
|
|---|
| 234 | angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
|
|---|
| 235 | piv = true;
|
|---|
| 236 | if (first) {
|
|---|
| 237 | curr = succ = next;
|
|---|
| 238 | gap = (space > 0);
|
|---|
| 239 | stcount = ratio - 1;
|
|---|
| 240 | symbol = prisymb;
|
|---|
| 241 | len = gap ? psize * space * 0.5 : psize;
|
|---|
| 242 | first = false;
|
|---|
| 243 | } else {
|
|---|
| 244 | while (curr.distance(next) >= len) {
|
|---|
| 245 | if (piv) {
|
|---|
| 246 | double rem = len;
|
|---|
| 247 | double s = prev.distance(next);
|
|---|
| 248 | double p = curr.distance(prev);
|
|---|
| 249 | if ((s > 0) && (p > 0)) {
|
|---|
| 250 | double n = curr.distance(next);
|
|---|
| 251 | double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
|
|---|
| 252 | double phi = Math.asin(p / len * Math.sin(theta));
|
|---|
| 253 | rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
|
|---|
| 254 | }
|
|---|
| 255 | succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
|
|---|
| 256 | piv = false;
|
|---|
| 257 | } else {
|
|---|
| 258 | succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
|
|---|
| 259 | }
|
|---|
| 260 | if (!gap) {
|
|---|
| 261 | Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Scheme(col),
|
|---|
| 262 | new Delta(Handle.BC, AffineTransform.getRotateInstance(
|
|---|
| 263 | Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))));
|
|---|
| 264 | }
|
|---|
| 265 | if (space > 0)
|
|---|
| 266 | gap = !gap;
|
|---|
| 267 | curr = succ;
|
|---|
| 268 | len = gap ? (psize * space) : (--stcount == 0) ? (stflag ? tsize : ssize) : psize;
|
|---|
| 269 | if (stcount == 0) {
|
|---|
| 270 | symbol = stflag ? tersymb : secsymb;
|
|---|
| 271 | if (trect != null)
|
|---|
| 272 | stflag = !stflag;
|
|---|
| 273 | stcount = ratio;
|
|---|
| 274 | } else {
|
|---|
| 275 | symbol = prisymb;
|
|---|
| 276 | }
|
|---|
| 277 | }
|
|---|
| 278 | }
|
|---|
| 279 | }
|
|---|
| 280 | }
|
|---|
| 281 | }
|
|---|
| 282 | }
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | public static void lineVector(LineStyle style) {
|
|---|
| 286 | Path2D.Double p = new Path2D.Double();
|
|---|
| 287 | p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
|
|---|
| 288 | Point2D point;
|
|---|
| 289 | GeomIterator git = map.new GeomIterator(Rules.feature.geom);
|
|---|
| 290 | while (git.hasComp()) {
|
|---|
| 291 | git.nextComp();
|
|---|
| 292 | boolean first = true;
|
|---|
| 293 | while (git.hasEdge()) {
|
|---|
| 294 | git.nextEdge();
|
|---|
| 295 | point = context.getPoint(git.next());
|
|---|
| 296 | if (first) {
|
|---|
| 297 | p.moveTo(point.getX(), point.getY());
|
|---|
| 298 | first = false;
|
|---|
| 299 | } else {
|
|---|
| 300 | p.lineTo(point.getX(), point.getY());
|
|---|
| 301 | }
|
|---|
| 302 | while (git.hasNode()) {
|
|---|
| 303 | Snode node = git.next();
|
|---|
| 304 | if (node == null) continue;
|
|---|
| 305 | point = context.getPoint(node);
|
|---|
| 306 | p.lineTo(point.getX(), point.getY());
|
|---|
| 307 | }
|
|---|
| 308 | }
|
|---|
| 309 | }
|
|---|
| 310 | if ((style.fill != null) && (Rules.feature.geom.prim == Pflag.AREA)) {
|
|---|
| 311 | g2.setPaint(style.fill);
|
|---|
| 312 | g2.fill(p);
|
|---|
| 313 | }
|
|---|
| 314 | if (style.line != null) {
|
|---|
| 315 | if (style.dash != null) {
|
|---|
| 316 | float[] dash = new float[style.dash.length];
|
|---|
| 317 | System.arraycopy(style.dash, 0, dash, 0, style.dash.length);
|
|---|
| 318 | for (int i = 0; i < style.dash.length; i++) {
|
|---|
| 319 | dash[i] *= (float) sScale;
|
|---|
| 320 | }
|
|---|
| 321 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, dash, 0));
|
|---|
| 322 | } else {
|
|---|
| 323 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
|---|
| 324 | }
|
|---|
| 325 | g2.setPaint(style.line);
|
|---|
| 326 | g2.draw(p);
|
|---|
| 327 | }
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | public static void grid() {
|
|---|
| 331 | if ((context.grid() > 0) && (map != null)) {
|
|---|
| 332 | LineStyle style = new LineStyle(Color.black, (float)2.0);
|
|---|
| 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));
|
|---|
| 336 | double mult = 1.0;
|
|---|
| 337 | if (nspan < 1.0) {
|
|---|
| 338 | do {
|
|---|
| 339 | nspan *= 10.0;
|
|---|
| 340 | mult *= 10.0;
|
|---|
| 341 | } while (nspan < 1.0);
|
|---|
| 342 | } else if (nspan > 10.0){
|
|---|
| 343 | do {
|
|---|
| 344 | nspan /= 10.0;
|
|---|
| 345 | mult /= 10.0;
|
|---|
| 346 | } while (nspan > 10.0);
|
|---|
| 347 | }
|
|---|
| 348 | if (nspan < 2.0) nspan = 1.0;
|
|---|
| 349 | else if (nspan < 5.0) nspan = 2.0;
|
|---|
| 350 | else nspan = 5.0;
|
|---|
| 351 | nspan = nspan / mult / 60.0;
|
|---|
| 352 | double left = Math.toDegrees(map.bounds.minlon) + 180.0;
|
|---|
| 353 | left = Math.ceil(left / nspan);
|
|---|
| 354 | left = Math.toRadians((left * nspan) - 180.0);
|
|---|
| 355 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
|
|---|
| 356 | Path2D.Double p = new Path2D.Double();
|
|---|
| 357 | for (double lon = left; lon < map.bounds.maxlon; lon += Math.toRadians(nspan)) {
|
|---|
| 358 | point = context.getPoint(new Snode(map.bounds.maxlat, lon));
|
|---|
| 359 | p.moveTo(point.getX(), point.getY());
|
|---|
| 360 | point = context.getPoint(new Snode(map.bounds.minlat, lon));
|
|---|
| 361 | p.lineTo(point.getX(), point.getY());
|
|---|
| 362 | double deg = Math.toDegrees(lon);
|
|---|
| 363 | String ew = (deg < -0.001) ? "W" : (deg > 0.001) ? "E" : "";
|
|---|
| 364 | deg = Math.abs(deg);
|
|---|
| 365 | String dstr = String.format("%03d°", (int)Math.floor(deg));
|
|---|
| 366 | double min = (deg - Math.floor(deg)) * 60.0;
|
|---|
| 367 | String mstr = String.format("%05.2f'%s", min, ew);
|
|---|
| 368 | Symbol label = new Symbol();
|
|---|
| 369 | if (point.getX() > 600.0) {
|
|---|
| 370 | 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)))));
|
|---|
| 371 | 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)))));
|
|---|
| 372 | Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, null);
|
|---|
| 373 | }
|
|---|
| 374 | }
|
|---|
| 375 | g2.setPaint(style.line);
|
|---|
| 376 | g2.draw(p);
|
|---|
| 377 | double tspan = 60 * Math.toDegrees(map.bounds.maxlat - map.bounds.minlat) / (context.grid() / (ratio < 1.0 ? ratio : 1.0));
|
|---|
| 378 | mult = 1.0;
|
|---|
| 379 | if (tspan < 1.0) {
|
|---|
| 380 | do {
|
|---|
| 381 | tspan *= 10.0;
|
|---|
| 382 | mult *= 10.0;
|
|---|
| 383 | } while (tspan < 1.0);
|
|---|
| 384 | } else if (tspan > 10.0){
|
|---|
| 385 | do {
|
|---|
| 386 | tspan /= 10.0;
|
|---|
| 387 | mult /= 10.0;
|
|---|
| 388 | } while (tspan > 10.0);
|
|---|
| 389 | }
|
|---|
| 390 | if (tspan < 2.0) tspan = 1.0;
|
|---|
| 391 | else if (tspan < 5.0) tspan = 2.0;
|
|---|
| 392 | else tspan = 5.0;
|
|---|
| 393 | tspan = tspan / mult / 60.0;
|
|---|
| 394 | double bottom = Math.toDegrees(map.bounds.minlat) + 90.0;
|
|---|
| 395 | bottom = Math.ceil(bottom / tspan);
|
|---|
| 396 | bottom = Math.toRadians((bottom * tspan) - 90.0);
|
|---|
| 397 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
|
|---|
| 398 | p = new Path2D.Double();
|
|---|
| 399 | for (double lat = bottom; lat < map.bounds.maxlat; lat += Math.toRadians(tspan)) {
|
|---|
| 400 | point = context.getPoint(new Snode(lat, map.bounds.maxlon));
|
|---|
| 401 | p.moveTo(point.getX(), point.getY());
|
|---|
| 402 | point = context.getPoint(new Snode(lat, map.bounds.minlon));
|
|---|
| 403 | p.lineTo(point.getX(), point.getY());
|
|---|
| 404 | double deg = Math.toDegrees(lat);
|
|---|
| 405 | String ns = (deg < -0.001) ? "S" : (deg > 0.001) ? "N" : "";
|
|---|
| 406 | deg = Math.abs(deg);
|
|---|
| 407 | String dstr = String.format("%02d°%s", (int)Math.floor(deg), ns);
|
|---|
| 408 | double min = (deg - Math.floor(deg)) * 60.0;
|
|---|
| 409 | String mstr = String.format("%05.2f'", min);
|
|---|
| 410 | Symbol label = new Symbol();
|
|---|
| 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 | }
|
|---|
| 416 | }
|
|---|
| 417 | g2.setPaint(style.line);
|
|---|
| 418 | g2.draw(p);
|
|---|
| 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();
|
|---|
| 422 | legend.add(new Instr(Form.FILL, Color.white));
|
|---|
| 423 | legend.add(new Instr(Form.PGON, path));
|
|---|
| 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));
|
|---|
| 426 | Symbols.drawSymbol(g2, legend, sScale, point.getX(), point.getY(), null, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 0)));
|
|---|
| 427 | legend = new Symbol();
|
|---|
| 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)))));
|
|---|
| 430 | point = context.getPoint(new Snode(map.bounds.minlat, map.bounds.minlon));
|
|---|
| 431 | Symbols.drawSymbol(g2, legend, sScale, point.getX(), point.getY(), null, new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, 0)));
|
|---|
| 432 | }
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | public static void lineCircle(LineStyle style, double radius, UniHLU units) {
|
|---|
| 436 | switch (units) {
|
|---|
| 437 | case HLU_FEET:
|
|---|
| 438 | radius /= 6076;
|
|---|
| 439 | break;
|
|---|
| 440 | case HLU_KMTR:
|
|---|
| 441 | radius /= 1.852;
|
|---|
| 442 | break;
|
|---|
| 443 | case HLU_HMTR:
|
|---|
| 444 | radius /= 18.52;
|
|---|
| 445 | break;
|
|---|
| 446 | case HLU_SMIL:
|
|---|
| 447 | radius /= 1.15078;
|
|---|
| 448 | break;
|
|---|
| 449 | case HLU_NMIL:
|
|---|
| 450 | break;
|
|---|
| 451 | default:
|
|---|
| 452 | radius /= 1852;
|
|---|
| 453 | break;
|
|---|
| 454 | }
|
|---|
| 455 | radius *= context.mile(Rules.feature);
|
|---|
| 456 | Symbol circle = new Symbol();
|
|---|
| 457 | if (style.fill != null) {
|
|---|
| 458 | circle.add(new Instr(Form.FILL, style.fill));
|
|---|
| 459 | circle.add(new Instr(Form.RSHP, new Ellipse2D.Double(-radius, -radius, radius*2, radius*2)));
|
|---|
| 460 | }
|
|---|
| 461 | circle.add(new Instr(Form.FILL, style.line));
|
|---|
| 462 | circle.add(new Instr(Form.STRK, new BasicStroke(style.width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, style.dash, 0)));
|
|---|
| 463 | circle.add(new Instr(Form.ELPS, new Ellipse2D.Double(-radius, -radius, radius*2, radius*2)));
|
|---|
| 464 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 465 | Symbols.drawSymbol(g2, circle, 1, point.getX(), point.getY(), null, null);
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | public static void fillPattern(BufferedImage image) {
|
|---|
| 469 | Path2D.Double p = new Path2D.Double();
|
|---|
| 470 | p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
|
|---|
| 471 | Point2D point;
|
|---|
| 472 | switch (Rules.feature.geom.prim) {
|
|---|
| 473 | case POINT:
|
|---|
| 474 | point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 475 | g2.drawImage(image, new AffineTransformOp(AffineTransform.getScaleInstance(sScale, sScale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
|
|---|
| 476 | (int) (point.getX() - (50 * sScale)), (int) (point.getY() - (50 * sScale)));
|
|---|
| 477 | break;
|
|---|
| 478 | case AREA:
|
|---|
| 479 | GeomIterator git = map.new GeomIterator(Rules.feature.geom);
|
|---|
| 480 | while (git.hasComp()) {
|
|---|
| 481 | git.nextComp();
|
|---|
| 482 | boolean newComp = true;
|
|---|
| 483 | while (git.hasEdge()) {
|
|---|
| 484 | git.nextEdge();
|
|---|
| 485 | point = context.getPoint(git.next());
|
|---|
| 486 | if (newComp) {
|
|---|
| 487 | p.moveTo(point.getX(), point.getY());
|
|---|
| 488 | newComp = false;
|
|---|
| 489 | } else {
|
|---|
| 490 | p.lineTo(point.getX(), point.getY());
|
|---|
| 491 | }
|
|---|
| 492 | while (git.hasNode()) {
|
|---|
| 493 | Snode node = git.next();
|
|---|
| 494 | if (node == null) continue;
|
|---|
| 495 | point = context.getPoint(node);
|
|---|
| 496 | p.lineTo(point.getX(), point.getY());
|
|---|
| 497 | }
|
|---|
| 498 | }
|
|---|
| 499 | }
|
|---|
| 500 | g2.setPaint(new TexturePaint(image, new Rectangle(0, 0, 1 + (int) (300 * sScale), 1 + (int) (300 * sScale))));
|
|---|
| 501 | g2.fill(p);
|
|---|
| 502 | break;
|
|---|
| 503 | default:
|
|---|
| 504 | break;
|
|---|
| 505 | }
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | public static void labelText(String str, Font font, Color tc) {
|
|---|
| 509 | labelText(str, font, tc, LabelStyle.NONE, null, null, null);
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | public static void labelText(String str, Font font, Color tc, Delta delta) {
|
|---|
| 513 | labelText(str, font, tc, LabelStyle.NONE, null, null, delta);
|
|---|
| 514 | }
|
|---|
| 515 |
|
|---|
| 516 | public static void labelText(String str, Font font, Color tc, LabelStyle style, Color fg) {
|
|---|
| 517 | labelText(str, font, tc, style, fg, null, null);
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | public static void labelText(String str, Font font, Color tc, LabelStyle style, Color fg, Color bg) {
|
|---|
| 521 | labelText(str, font, tc, style, fg, bg, null);
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | public static void labelText(String str, Font font, Color tc, LabelStyle style, Color fg, Delta delta) {
|
|---|
| 525 | labelText(str, font, tc, style, fg, null, delta);
|
|---|
| 526 | }
|
|---|
| 527 |
|
|---|
| 528 | public static void labelText(String str, Font font, Color tc, LabelStyle style, Color fg, Color bg, Delta delta) {
|
|---|
| 529 | if (delta == null) delta = new Delta(Handle.CC);
|
|---|
| 530 | if (bg == null) bg = new Color(0x00000000, true);
|
|---|
| 531 | if (str == null || str.isEmpty()) str = " ";
|
|---|
| 532 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 533 | GlyphVector gv = font.deriveFont((float) font.getSize()).createGlyphVector(frc, str.equals(" ") ? "M" : str);
|
|---|
| 534 | Rectangle2D bounds = gv.getVisualBounds();
|
|---|
| 535 | double width = bounds.getWidth();
|
|---|
| 536 | double height = bounds.getHeight();
|
|---|
| 537 | Symbol label = new Symbol();
|
|---|
| 538 | double lx, ly, tx, ty;
|
|---|
| 539 | switch (style) {
|
|---|
| 540 | case RRCT:
|
|---|
| 541 | width += height * 1.0;
|
|---|
| 542 | height *= 1.5;
|
|---|
| 543 | if (width < height) width = height;
|
|---|
| 544 | lx = -width / 2;
|
|---|
| 545 | ly = -height / 2;
|
|---|
| 546 | tx = lx + (height * 0.34);
|
|---|
| 547 | ty = ly + (height * 0.17);
|
|---|
| 548 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 549 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 550 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 551 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 552 | label.add(new Instr(Form.STRK, new BasicStroke(1 + (int) (height/10), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 553 | label.add(new Instr(Form.RRCT, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 554 | break;
|
|---|
| 555 | case VCLR:
|
|---|
| 556 | width += height * 1.0;
|
|---|
| 557 | height *= 2.0;
|
|---|
| 558 | if (width < height) width = height;
|
|---|
| 559 | lx = -width / 2;
|
|---|
| 560 | ly = -height / 2;
|
|---|
| 561 | tx = lx + (height * 0.27);
|
|---|
| 562 | ty = ly + (height * 0.25);
|
|---|
| 563 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 564 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 565 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 566 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 567 | int sw = 1 + (int) (height/10);
|
|---|
| 568 | double po = sw / 2;
|
|---|
| 569 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 570 | Path2D.Double p = new Path2D.Double(); p.moveTo(-height*0.2, -ly-po);
|
|---|
| 571 | p.lineTo(height*0.2, -ly-po); p.moveTo(0, -ly-po); p.lineTo(0, -ly-po-(height*0.15));
|
|---|
| 572 | 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));
|
|---|
| 573 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 574 | break;
|
|---|
| 575 | case PCLR:
|
|---|
| 576 | width += height * 1.0;
|
|---|
| 577 | height *= 2.0;
|
|---|
| 578 | if (width < height) width = height;
|
|---|
| 579 | lx = -width / 2;
|
|---|
| 580 | ly = -height / 2;
|
|---|
| 581 | tx = lx + (height * 0.27);
|
|---|
| 582 | ty = ly + (height * 0.25);
|
|---|
| 583 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 584 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 585 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 586 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 587 | sw = 1 + (int) (height/10);
|
|---|
| 588 | po = sw / 2;
|
|---|
| 589 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 590 | p = new Path2D.Double();
|
|---|
| 591 | p.moveTo(-height*0.2, -ly-po);
|
|---|
| 592 | p.lineTo(height*0.2, -ly-po);
|
|---|
| 593 | p.moveTo(0, -ly-po);
|
|---|
| 594 | p.lineTo(0, -ly-po-(height*0.15));
|
|---|
| 595 | p.moveTo(-height*0.2, ly+po);
|
|---|
| 596 | p.lineTo((height*0.2), ly+po);
|
|---|
| 597 | p.moveTo(0, ly+po);
|
|---|
| 598 | p.lineTo(0, ly+po+(height*0.15));
|
|---|
| 599 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 600 | label.add(new Instr(Form.SYMB, new Symbols.SubSymbol(Areas.CableFlash, 1, 0, 0, null,
|
|---|
| 601 | new Delta(Handle.CC, new AffineTransform(0, -1, 1, 0, -width/2, 0)))));
|
|---|
| 602 | label.add(new Instr(Form.SYMB, new Symbols.SubSymbol(Areas.CableFlash, 1, 0, 0, null,
|
|---|
| 603 | new Delta(Handle.CC, new AffineTransform(0, -1, 1, 0, width/2, 0)))));
|
|---|
| 604 | break;
|
|---|
| 605 | case HCLR:
|
|---|
| 606 | width += height * 1.5;
|
|---|
| 607 | height *= 1.5;
|
|---|
| 608 | if (width < height) width = height;
|
|---|
| 609 | lx = -width / 2;
|
|---|
| 610 | ly = -height / 2;
|
|---|
| 611 | tx = lx + (height * 0.5);
|
|---|
| 612 | ty = ly + (height * 0.17);
|
|---|
| 613 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 614 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 615 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx, ly, width, height, height, height)));
|
|---|
| 616 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 617 | sw = 1 + (int) (height/10);
|
|---|
| 618 | double vo = height / 4;
|
|---|
| 619 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 620 | p = new Path2D.Double();
|
|---|
| 621 | p.moveTo(-width*0.4-sw, -ly-vo);
|
|---|
| 622 | p.lineTo(-width*0.4-sw, ly+vo);
|
|---|
| 623 | p.moveTo(-width*0.4-sw, 0);
|
|---|
| 624 | p.lineTo(-width*0.4+sw, 0);
|
|---|
| 625 | p.moveTo(width*0.4+sw, -ly-vo);
|
|---|
| 626 | p.lineTo(width*0.4+sw, ly+vo);
|
|---|
| 627 | p.moveTo(width*0.4-sw, 0);
|
|---|
| 628 | p.lineTo(width*0.4+sw, 0);
|
|---|
| 629 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 630 | break;
|
|---|
| 631 | default:
|
|---|
| 632 | lx = -width / 2;
|
|---|
| 633 | ly = -height / 2;
|
|---|
| 634 | tx = lx;
|
|---|
| 635 | ty = ly;
|
|---|
| 636 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx, ly, width, height)));
|
|---|
| 637 | break;
|
|---|
| 638 | }
|
|---|
| 639 | label.add(new Instr(Form.TEXT, new Caption(str, font, tc, new Delta(Handle.TL, AffineTransform.getTranslateInstance(tx, ty)))));
|
|---|
| 640 | Point2D point = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 641 | Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, delta);
|
|---|
| 642 | }
|
|---|
| 643 |
|
|---|
| 644 | public static void lineText(String str, Font font, Color colour, double dy) {
|
|---|
| 645 | if (!str.isEmpty()) {
|
|---|
| 646 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|---|
| 647 | g2.setPaint(colour);
|
|---|
| 648 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 649 | GlyphVector gv = font.deriveFont(font.getSize2D() * (float) sScale).createGlyphVector(frc, str);
|
|---|
| 650 | double width = gv.getVisualBounds().getWidth();
|
|---|
| 651 | double height = gv.getVisualBounds().getHeight();
|
|---|
| 652 | double offset = (Rules.feature.geom.length * context.mile(Rules.feature) - width) / 2;
|
|---|
| 653 | if (offset > 0) {
|
|---|
| 654 | Point2D before = null;
|
|---|
| 655 | Point2D after = null;
|
|---|
| 656 | ArrayList<Point2D> between = new ArrayList<>();
|
|---|
| 657 | Point2D prev = null;
|
|---|
| 658 | Point2D next = null;
|
|---|
| 659 | double length = 0;
|
|---|
| 660 | double lb = 0;
|
|---|
| 661 | double la = 0;
|
|---|
| 662 | GeomIterator git = map.new GeomIterator(Rules.feature.geom);
|
|---|
| 663 | if (git.hasComp()) {
|
|---|
| 664 | git.nextComp();
|
|---|
| 665 | while (git.hasEdge()) {
|
|---|
| 666 | git.nextEdge();
|
|---|
| 667 | while (git.hasNode()) {
|
|---|
| 668 | Snode node = git.next();
|
|---|
| 669 | if (node == null)
|
|---|
| 670 | continue;
|
|---|
| 671 | prev = next;
|
|---|
| 672 | next = context.getPoint(node);
|
|---|
| 673 | if (prev != null)
|
|---|
| 674 | length += Math.sqrt(Math.pow((next.getX() - prev.getX()), 2) + Math.pow((next.getY() - prev.getY()), 2));
|
|---|
| 675 | if (length < offset) {
|
|---|
| 676 | before = next;
|
|---|
| 677 | lb = la = length;
|
|---|
| 678 | } else if (after == null) {
|
|---|
| 679 | if (length > (offset + width)) {
|
|---|
| 680 | after = next;
|
|---|
| 681 | la = length;
|
|---|
| 682 | break;
|
|---|
| 683 | } else {
|
|---|
| 684 | between.add(next);
|
|---|
| 685 | }
|
|---|
| 686 | }
|
|---|
| 687 | }
|
|---|
| 688 | if (after != null)
|
|---|
| 689 | break;
|
|---|
| 690 | }
|
|---|
| 691 | }
|
|---|
| 692 | if (after != null) {
|
|---|
| 693 | double angle = Math.atan2((after.getY() - before.getY()), (after.getX() - before.getX()));
|
|---|
| 694 | double rotate = Math.abs(angle) < (Math.PI / 2) ? angle : angle + Math.PI;
|
|---|
| 695 | Point2D mid = new Point2D.Double((before.getX() + after.getX()) / 2, (before.getY() + after.getY()) / 2);
|
|---|
| 696 | Point2D centre = context.getPoint(Rules.feature.geom.centre);
|
|---|
| 697 | AffineTransform pos = AffineTransform.getTranslateInstance(-dy * Math.sin(rotate), dy * Math.cos(rotate));
|
|---|
| 698 | pos.rotate(rotate);
|
|---|
| 699 | pos.translate((mid.getX() - centre.getX()), (mid.getY() - centre.getY()));
|
|---|
| 700 | Symbol label = new Symbol();
|
|---|
| 701 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double((-width / 2), -height, width, height)));
|
|---|
| 702 | label.add(new Instr(Form.TEXT, new Caption(str, font, colour, new Delta(Handle.BC))));
|
|---|
| 703 | Symbols.drawSymbol(g2, label, sScale, centre.getX(), centre.getY(), null, new Delta(Handle.BC, pos));
|
|---|
| 704 | }
|
|---|
| 705 | }
|
|---|
| 706 | }
|
|---|
| 707 | }
|
|---|
| 708 |
|
|---|
| 709 | public static void lightSector(Color col1, Color col2, double radius, double s1, double s2, Double dir, String str) {
|
|---|
| 710 | double mid = (((s1 + s2) / 2) + (s1 > s2 ? 180 : 0)) % 360;
|
|---|
| 711 | g2.setStroke(new BasicStroke((float) (3.0 * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1,
|
|---|
| 712 | new float[] {20 * (float) sScale, 20 * (float) sScale}, 0));
|
|---|
| 713 | g2.setPaint(Color.black);
|
|---|
| 714 | Point2D.Double centre = (Point2D.Double) context.getPoint(Rules.feature.geom.centre);
|
|---|
| 715 | double radial = radius * context.mile(Rules.feature);
|
|---|
| 716 | if (dir != null) {
|
|---|
| 717 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(dir)),
|
|---|
| 718 | centre.y + radial * Math.cos(Math.toRadians(dir))));
|
|---|
| 719 | } else {
|
|---|
| 720 | if ((s1 != 0.0) || (s2 != 360.0)) {
|
|---|
| 721 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(s1)),
|
|---|
| 722 | centre.y + radial * Math.cos(Math.toRadians(s1))));
|
|---|
| 723 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(s2)),
|
|---|
| 724 | centre.y + radial * Math.cos(Math.toRadians(s2))));
|
|---|
| 725 | }
|
|---|
| 726 | }
|
|---|
| 727 | double arcWidth = 10.0 * sScale;
|
|---|
| 728 | g2.setStroke(new BasicStroke((float) arcWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1));
|
|---|
| 729 | g2.setPaint(col1);
|
|---|
| 730 | g2.draw(new Arc2D.Double(centre.x - radial, centre.y - radial, 2 * radial, 2 * radial, -(s1 + 90),
|
|---|
| 731 | ((s1 < s2) ? (s1 - s2) : (s1 - s2 - 360)), Arc2D.OPEN));
|
|---|
| 732 | if (col2 != null) {
|
|---|
| 733 | g2.setPaint(col2);
|
|---|
| 734 | g2.draw(new Arc2D.Double(centre.x - radial + arcWidth, centre.y - radial + arcWidth, 2 * (radial - arcWidth),
|
|---|
| 735 | 2 * (radial - arcWidth), -(s1 + 90), ((s1 < s2) ? (s1 - s2) : (s1 - s2 - 360)), Arc2D.OPEN));
|
|---|
| 736 | }
|
|---|
| 737 | if (str != null && !str.isEmpty()) {
|
|---|
| 738 | Font font = new Font("Arial", Font.PLAIN, 40);
|
|---|
| 739 | double arc = (s2 > s1) ? (s2 - s1) : (s2 - s1 + 360);
|
|---|
| 740 | double awidth = (Math.toRadians(arc) * radial);
|
|---|
| 741 | boolean hand = ((mid > 270) || (mid < 90));
|
|---|
| 742 | double phi = Math.toRadians(mid);
|
|---|
| 743 | radial += 30 * sScale;
|
|---|
| 744 | AffineTransform at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale);
|
|---|
| 745 | if ((font.getSize() * sScale * str.length()) < awidth) {
|
|---|
| 746 | at.rotate(Math.toRadians(mid + (hand ? 0 : 180)));
|
|---|
| 747 | labelText(str, font, Color.black, new Delta(Handle.CC, at));
|
|---|
| 748 | } else if ((font.getSize() * sScale) < awidth) {
|
|---|
| 749 | hand = (mid < 180);
|
|---|
| 750 | at.rotate(Math.toRadians(mid + (hand ? -90 : 90)));
|
|---|
| 751 | labelText(str, font, Color.black, hand ? new Delta(Handle.RC, at) : new Delta(Handle.LC, at));
|
|---|
| 752 | }
|
|---|
| 753 | if (dir != null) {
|
|---|
| 754 | font = new Font("Arial", Font.PLAIN, 30);
|
|---|
| 755 | str = dir + "°";
|
|---|
| 756 | hand = (dir > 180);
|
|---|
| 757 | phi = Math.toRadians(dir + (hand ? -0.5 : 0.5));
|
|---|
| 758 | radial -= 70 * sScale;
|
|---|
| 759 | at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale);
|
|---|
| 760 | at.rotate(Math.toRadians(dir + (hand ? 90 : -90)));
|
|---|
| 761 | labelText(str, font, Color.black, hand ? new Delta(Handle.BR, at) : new Delta(Handle.BL, at));
|
|---|
| 762 | }
|
|---|
| 763 | }
|
|---|
| 764 | }
|
|---|
| 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 | }
|
|---|
| 782 | }
|
|---|