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