| 1 | /* Copyright 2014 Malcolm Herring
|
|---|
| 2 | *
|
|---|
| 3 | * This is free software: you can redistribute it and/or modify
|
|---|
| 4 | * it under the terms of the GNU General Public License as published by
|
|---|
| 5 | * the Free Software Foundation, version 3 of the License.
|
|---|
| 6 | *
|
|---|
| 7 | * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | package render;
|
|---|
| 11 |
|
|---|
| 12 | import java.awt.*;
|
|---|
| 13 | import java.awt.font.*;
|
|---|
| 14 | import java.awt.geom.*;
|
|---|
| 15 | import java.awt.image.*;
|
|---|
| 16 | import java.util.*;
|
|---|
| 17 |
|
|---|
| 18 | import render.Rules.*;
|
|---|
| 19 | import s57.S57val.*;
|
|---|
| 20 | import s57.S57map;
|
|---|
| 21 | import s57.S57obj.Obj;
|
|---|
| 22 | import s57.S57map.*;
|
|---|
| 23 | import symbols.Areas;
|
|---|
| 24 | import symbols.Symbols;
|
|---|
| 25 | import symbols.Symbols.*;
|
|---|
| 26 |
|
|---|
| 27 | public class Renderer {
|
|---|
| 28 |
|
|---|
| 29 | public static final double symbolScale[] = { 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 };
|
|---|
| 30 |
|
|---|
| 31 | public enum LabelStyle { NONE, RRCT, RECT, ELPS, CIRC, VCLR, PCLR, HCLR }
|
|---|
| 32 |
|
|---|
| 33 | static ChartContext context;
|
|---|
| 34 | static S57map map;
|
|---|
| 35 | static double sScale;
|
|---|
| 36 | static Graphics2D g2;
|
|---|
| 37 | static int zoom;
|
|---|
| 38 |
|
|---|
| 39 | public static void reRender(Graphics2D g, int z, double factor, S57map m, ChartContext c) {
|
|---|
| 40 | g2 = g;
|
|---|
| 41 | zoom = z;
|
|---|
| 42 | context = c;
|
|---|
| 43 | map = m;
|
|---|
| 44 | sScale = symbolScale[zoom] * factor;
|
|---|
| 45 | if (map != null) {
|
|---|
| 46 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|---|
| 47 | g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
|
|---|
| 48 | g2.setStroke(new BasicStroke(0, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
|
|---|
| 49 | Rules.rules(RuleSet.BASE);
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | public static void symbol(Feature feature, Symbol symbol) {
|
|---|
| 54 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 55 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, null);
|
|---|
| 56 | }
|
|---|
| 57 | public static void symbol(Feature feature, Symbol symbol, Scheme scheme) {
|
|---|
| 58 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 59 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, null);
|
|---|
| 60 | }
|
|---|
| 61 | public static void symbol(Feature feature, Symbol symbol, Delta delta) {
|
|---|
| 62 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 63 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, delta);
|
|---|
| 64 | }
|
|---|
| 65 | public static void symbol(Feature feature, Symbol symbol, Scheme scheme, Delta delta) {
|
|---|
| 66 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 67 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, delta);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | public static void cluster(Feature feature, ArrayList<Symbol> symbols) {
|
|---|
| 71 | Rectangle2D.Double bbox = null;
|
|---|
| 72 | if (symbols.size() > 4) {
|
|---|
| 73 | for (Instr instr : symbols.get(0)) {
|
|---|
| 74 | if (instr.type == Form.BBOX) {
|
|---|
| 75 | bbox = (Rectangle2D.Double) instr.params;
|
|---|
| 76 | break;
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 | if (bbox == null) return;
|
|---|
| 80 | }
|
|---|
| 81 | switch (symbols.size()) {
|
|---|
| 82 | case 1:
|
|---|
| 83 | symbol(feature, symbols.get(0), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 84 | break;
|
|---|
| 85 | case 2:
|
|---|
| 86 | symbol(feature, symbols.get(0), new Delta(Handle.RC, new AffineTransform()));
|
|---|
| 87 | symbol(feature, symbols.get(1), new Delta(Handle.LC, new AffineTransform()));
|
|---|
| 88 | break;
|
|---|
| 89 | case 3:
|
|---|
| 90 | symbol(feature, symbols.get(0), new Delta(Handle.BC, new AffineTransform()));
|
|---|
| 91 | symbol(feature, symbols.get(1), new Delta(Handle.TR, new AffineTransform()));
|
|---|
| 92 | symbol(feature, symbols.get(2), new Delta(Handle.TL, new AffineTransform()));
|
|---|
| 93 | break;
|
|---|
| 94 | case 4:
|
|---|
| 95 | symbol(feature, symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
|
|---|
| 96 | symbol(feature, symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
|
|---|
| 97 | symbol(feature, symbols.get(2), new Delta(Handle.TR, new AffineTransform()));
|
|---|
| 98 | symbol(feature, symbols.get(3), new Delta(Handle.TL, new AffineTransform()));
|
|---|
| 99 | break;
|
|---|
| 100 | case 5:
|
|---|
| 101 | symbol(feature, symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
|
|---|
| 102 | symbol(feature, symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
|
|---|
| 103 | symbol(feature, symbols.get(2), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 104 | symbol(feature, symbols.get(3), new Delta(Handle.TC, new AffineTransform()));
|
|---|
| 105 | symbol(feature, symbols.get(4), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 106 | break;
|
|---|
| 107 | case 6:
|
|---|
| 108 | symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 109 | symbol(feature, symbols.get(1), new Delta(Handle.BC, new AffineTransform()));
|
|---|
| 110 | symbol(feature, symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 111 | symbol(feature, symbols.get(3), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 112 | symbol(feature, symbols.get(4), new Delta(Handle.TC, new AffineTransform()));
|
|---|
| 113 | symbol(feature, symbols.get(5), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 114 | break;
|
|---|
| 115 | case 7:
|
|---|
| 116 | symbol(feature, symbols.get(0), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 117 | symbol(feature, symbols.get(1), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 118 | symbol(feature, symbols.get(2), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 119 | symbol(feature, symbols.get(3), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 120 | symbol(feature, symbols.get(4), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 121 | symbol(feature, symbols.get(5), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 122 | symbol(feature, symbols.get(6), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 123 | break;
|
|---|
| 124 | case 8:
|
|---|
| 125 | symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 126 | symbol(feature, symbols.get(1), new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 127 | symbol(feature, symbols.get(2), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 128 | symbol(feature, symbols.get(3), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 129 | symbol(feature, symbols.get(4), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 130 | symbol(feature, symbols.get(5), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 131 | symbol(feature, symbols.get(6), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 132 | symbol(feature, symbols.get(7), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 133 | break;
|
|---|
| 134 | case 9:
|
|---|
| 135 | symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, -bbox.height/2)));
|
|---|
| 136 | symbol(feature, symbols.get(1), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 137 | symbol(feature, symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, -bbox.height/2)));
|
|---|
| 138 | symbol(feature, symbols.get(3), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 139 | symbol(feature, symbols.get(4), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 140 | symbol(feature, symbols.get(5), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 141 | symbol(feature, symbols.get(6), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 142 | symbol(feature, symbols.get(7), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 143 | symbol(feature, symbols.get(8), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 144 | break;
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | private static Rectangle2D.Double symbolSize(Symbol symbol) {
|
|---|
| 149 | Symbol ssymb = symbol;
|
|---|
| 150 | while (ssymb != null) {
|
|---|
| 151 | for (Instr item : symbol) {
|
|---|
| 152 | if (item.type == Form.BBOX) {
|
|---|
| 153 | return (Rectangle2D.Double) item.params;
|
|---|
| 154 | }
|
|---|
| 155 | if (item.type == Form.SYMB) {
|
|---|
| 156 | ssymb = ((SubSymbol) item.params).instr;
|
|---|
| 157 | break;
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 | if (ssymb == symbol)
|
|---|
| 161 | break;
|
|---|
| 162 | }
|
|---|
| 163 | return null;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, Symbol tersymb, int ratio, Color col) {
|
|---|
| 167 | if ((feature.geom.prim == Pflag.NOSP) || (feature.geom.prim == Pflag.POINT))
|
|---|
| 168 | return;
|
|---|
| 169 | Rectangle2D.Double prect = symbolSize(prisymb);
|
|---|
| 170 | Rectangle2D.Double srect = symbolSize(secsymb);
|
|---|
| 171 | Rectangle2D.Double trect = symbolSize(tersymb);
|
|---|
| 172 | if (srect == null)
|
|---|
| 173 | ratio = 0;
|
|---|
| 174 | if (prect != null) {
|
|---|
| 175 | double psize = Math.abs(prect.getY()) * sScale;
|
|---|
| 176 | double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
|
|---|
| 177 | double tsize = (trect != null) ? Math.abs(srect.getY()) * sScale : 0;
|
|---|
| 178 | Point2D prev = new Point2D.Double();
|
|---|
| 179 | Point2D next = new Point2D.Double();
|
|---|
| 180 | Point2D curr = new Point2D.Double();
|
|---|
| 181 | Point2D succ = new Point2D.Double();
|
|---|
| 182 | boolean gap = true;
|
|---|
| 183 | boolean piv = false;
|
|---|
| 184 | double len = 0;
|
|---|
| 185 | double angle = 0;
|
|---|
| 186 | int stcount = ratio;
|
|---|
| 187 | boolean stflag = false;
|
|---|
| 188 | Symbol symbol = prisymb;
|
|---|
| 189 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 190 | while (git.hasComp()) {
|
|---|
| 191 | git.nextComp();
|
|---|
| 192 | boolean first = true;
|
|---|
| 193 | while (git.hasEdge()) {
|
|---|
| 194 | git.nextEdge();
|
|---|
| 195 | while (git.hasNode()) {
|
|---|
| 196 | prev = next;
|
|---|
| 197 | next = context.getPoint(git.next());
|
|---|
| 198 | angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
|
|---|
| 199 | piv = true;
|
|---|
| 200 | if (first) {
|
|---|
| 201 | curr = succ = next;
|
|---|
| 202 | gap = (space > 0);
|
|---|
| 203 | stcount = ratio - 1;
|
|---|
| 204 | symbol = prisymb;
|
|---|
| 205 | len = gap ? psize * space * 0.5 : psize;
|
|---|
| 206 | first = false;
|
|---|
| 207 | } else {
|
|---|
| 208 | while (curr.distance(next) >= len) {
|
|---|
| 209 | if (piv) {
|
|---|
| 210 | double rem = len;
|
|---|
| 211 | double s = prev.distance(next);
|
|---|
| 212 | double p = curr.distance(prev);
|
|---|
| 213 | if ((s > 0) && (p > 0)) {
|
|---|
| 214 | double n = curr.distance(next);
|
|---|
| 215 | double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
|
|---|
| 216 | double phi = Math.asin(p / len * Math.sin(theta));
|
|---|
| 217 | rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
|
|---|
| 218 | }
|
|---|
| 219 | succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
|
|---|
| 220 | piv = false;
|
|---|
| 221 | } else {
|
|---|
| 222 | succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
|
|---|
| 223 | }
|
|---|
| 224 | if (!gap) {
|
|---|
| 225 | Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Scheme(col),
|
|---|
| 226 | new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))));
|
|---|
| 227 | }
|
|---|
| 228 | if (space > 0)
|
|---|
| 229 | gap = !gap;
|
|---|
| 230 | curr = succ;
|
|---|
| 231 | len = gap ? (psize * space) : (--stcount == 0) ? (stflag ? tsize : ssize) : psize;
|
|---|
| 232 | if (stcount == 0) {
|
|---|
| 233 | symbol = stflag ? tersymb : secsymb;
|
|---|
| 234 | if (trect != null)
|
|---|
| 235 | stflag = !stflag;
|
|---|
| 236 | stcount = ratio;
|
|---|
| 237 | } else {
|
|---|
| 238 | symbol = prisymb;
|
|---|
| 239 | }
|
|---|
| 240 | }
|
|---|
| 241 | }
|
|---|
| 242 | }
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | public static void lineVector(Feature feature, LineStyle style) {
|
|---|
| 249 | Path2D.Double p = new Path2D.Double();
|
|---|
| 250 | p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
|
|---|
| 251 | Point2D point;
|
|---|
| 252 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 253 | while (git.hasComp()) {
|
|---|
| 254 | git.nextComp();
|
|---|
| 255 | boolean first = true;
|
|---|
| 256 | while (git.hasEdge()) {
|
|---|
| 257 | git.nextEdge();
|
|---|
| 258 | point = context.getPoint(git.next());
|
|---|
| 259 | if (first) {
|
|---|
| 260 | p.moveTo(point.getX(), point.getY());
|
|---|
| 261 | first = false;
|
|---|
| 262 | } else {
|
|---|
| 263 | p.lineTo(point.getX(), point.getY());
|
|---|
| 264 | }
|
|---|
| 265 | while (git.hasNode()) {
|
|---|
| 266 | point = context.getPoint(git.next());
|
|---|
| 267 | p.lineTo(point.getX(), point.getY());
|
|---|
| 268 | }
|
|---|
| 269 | }
|
|---|
| 270 | }
|
|---|
| 271 | if ((style.fill != null) && (feature.geom.prim == Pflag.AREA)) {
|
|---|
| 272 | g2.setPaint(style.fill);
|
|---|
| 273 | g2.fill(p);
|
|---|
| 274 | }
|
|---|
| 275 | if (style.line != null) {
|
|---|
| 276 | if (style.dash != null) {
|
|---|
| 277 | float[] dash = new float[style.dash.length];
|
|---|
| 278 | System.arraycopy(style.dash, 0, dash, 0, style.dash.length);
|
|---|
| 279 | for (int i = 0; i < style.dash.length; i++) {
|
|---|
| 280 | dash[i] *= (float) sScale;
|
|---|
| 281 | }
|
|---|
| 282 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, dash, 0));
|
|---|
| 283 | } else {
|
|---|
| 284 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
|---|
| 285 | }
|
|---|
| 286 | g2.setPaint(style.line);
|
|---|
| 287 | g2.draw(p);
|
|---|
| 288 | }
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | public static void lineCircle(Feature feature, LineStyle style, double radius, UniHLU units) {
|
|---|
| 292 | switch (units) {
|
|---|
| 293 | case HLU_FEET:
|
|---|
| 294 | radius /= 6076;
|
|---|
| 295 | break;
|
|---|
| 296 | case HLU_KMTR:
|
|---|
| 297 | radius /= 1.852;
|
|---|
| 298 | break;
|
|---|
| 299 | case HLU_HMTR:
|
|---|
| 300 | radius /= 18.52;
|
|---|
| 301 | break;
|
|---|
| 302 | case HLU_SMIL:
|
|---|
| 303 | radius /= 1.15078;
|
|---|
| 304 | break;
|
|---|
| 305 | case HLU_NMIL:
|
|---|
| 306 | break;
|
|---|
| 307 | default:
|
|---|
| 308 | radius /= 1852;
|
|---|
| 309 | break;
|
|---|
| 310 | }
|
|---|
| 311 | radius *= context.mile(feature);
|
|---|
| 312 | Symbol circle = new Symbol();
|
|---|
| 313 | if (style.fill != null) {
|
|---|
| 314 | circle.add(new Instr(Form.FILL, style.fill));
|
|---|
| 315 | circle.add(new Instr(Form.RSHP, new Ellipse2D.Double(-radius,-radius,radius*2,radius*2)));
|
|---|
| 316 | }
|
|---|
| 317 | circle.add(new Instr(Form.FILL, style.line));
|
|---|
| 318 | circle.add(new Instr(Form.STRK, new BasicStroke(style.width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, style.dash, 0)));
|
|---|
| 319 | circle.add(new Instr(Form.ELPS, new Ellipse2D.Double(-radius,-radius,radius*2,radius*2)));
|
|---|
| 320 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 321 | Symbols.drawSymbol(g2, circle, 1, point.getX(), point.getY(), null, null);
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 | public static void fillPattern(Feature feature, BufferedImage image) {
|
|---|
| 326 | Path2D.Double p = new Path2D.Double();
|
|---|
| 327 | p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
|
|---|
| 328 | Point2D point;
|
|---|
| 329 | switch (feature.geom.prim) {
|
|---|
| 330 | case POINT:
|
|---|
| 331 | point = context.getPoint(feature.geom.centre);
|
|---|
| 332 | g2.drawImage(image, new AffineTransformOp(AffineTransform.getScaleInstance(sScale, sScale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
|
|---|
| 333 | (int)(point.getX() - (50 * sScale)), (int)(point.getY() - (50 * sScale)));
|
|---|
| 334 | break;
|
|---|
| 335 | case AREA:
|
|---|
| 336 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 337 | while (git.hasComp()) {
|
|---|
| 338 | git.nextComp();
|
|---|
| 339 | while (git.hasEdge()) {
|
|---|
| 340 | git.nextEdge();
|
|---|
| 341 | point = context.getPoint(git.next());
|
|---|
| 342 | p.moveTo(point.getX(), point.getY());
|
|---|
| 343 | while (git.hasNode()) {
|
|---|
| 344 | point = context.getPoint(git.next());
|
|---|
| 345 | p.lineTo(point.getX(), point.getY());
|
|---|
| 346 | }
|
|---|
| 347 | }
|
|---|
| 348 | }
|
|---|
| 349 | g2.setPaint(new TexturePaint(image, new Rectangle(0, 0, 1 + (int)(100 * sScale), 1 + (int)(100 * sScale))));
|
|---|
| 350 | g2.fill(p);
|
|---|
| 351 | break;
|
|---|
| 352 | default:
|
|---|
| 353 | break;
|
|---|
| 354 | }
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | public static void labelText(Feature feature, String str, Font font, Color tc) {
|
|---|
| 358 | labelText(feature, str, font, tc, LabelStyle.NONE, null, null, null);
|
|---|
| 359 | }
|
|---|
| 360 | public static void labelText(Feature feature, String str, Font font, Color tc, Delta delta) {
|
|---|
| 361 | labelText(feature, str, font, tc, LabelStyle.NONE, null, null, delta);
|
|---|
| 362 | }
|
|---|
| 363 | public static void labelText(Feature feature, String str, Font font, Color tc, LabelStyle style, Color fg) {
|
|---|
| 364 | labelText(feature, str, font, tc, style, fg, null, null);
|
|---|
| 365 | }
|
|---|
| 366 | public static void labelText(Feature feature, String str, Font font, Color tc, LabelStyle style, Color fg, Color bg) {
|
|---|
| 367 | labelText(feature, str, font, tc, style, fg, bg, null);
|
|---|
| 368 | }
|
|---|
| 369 | public static void labelText(Feature feature, String str, Font font, Color tc, LabelStyle style, Color fg, Delta delta) {
|
|---|
| 370 | labelText(feature, str, font, tc, style, fg, null, delta);
|
|---|
| 371 | }
|
|---|
| 372 | public static void labelText(Feature feature, String str, Font font, Color tc, LabelStyle style, Color fg, Color bg, Delta delta) {
|
|---|
| 373 | if (delta == null) delta = new Delta(Handle.CC);
|
|---|
| 374 | if (bg == null) bg = new Color(0x00000000, true);
|
|---|
| 375 | if ((str == null) || (str.isEmpty())) str = " ";
|
|---|
| 376 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 377 | GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "!" : str);
|
|---|
| 378 | Rectangle2D bounds = gv.getVisualBounds();
|
|---|
| 379 | double width = bounds.getWidth();
|
|---|
| 380 | double height = bounds.getHeight();
|
|---|
| 381 | Symbol label = new Symbol();
|
|---|
| 382 | double lx, ly, tx, ty;
|
|---|
| 383 | switch (style) {
|
|---|
| 384 | case RRCT:
|
|---|
| 385 | width += height * 1.0;
|
|---|
| 386 | height *= 1.5;
|
|---|
| 387 | if (width < height) width = height;
|
|---|
| 388 | lx = -width / 2;
|
|---|
| 389 | ly = -height / 2;
|
|---|
| 390 | tx = lx + (height * 0.34);
|
|---|
| 391 | ty = ly + (height * 0.17);
|
|---|
| 392 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 393 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 394 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 395 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 396 | label.add(new Instr(Form.STRK, new BasicStroke(1 + (int)(height/10), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 397 | label.add(new Instr(Form.RRCT, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 398 | break;
|
|---|
| 399 | case VCLR:
|
|---|
| 400 | width += height * 1.0;
|
|---|
| 401 | height *= 2.0;
|
|---|
| 402 | if (width < height) width = height;
|
|---|
| 403 | lx = -width / 2;
|
|---|
| 404 | ly = -height / 2;
|
|---|
| 405 | tx = lx + (height * 0.27);
|
|---|
| 406 | ty = ly + (height * 0.25);
|
|---|
| 407 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 408 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 409 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 410 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 411 | int sw = 1 + (int)(height/10);
|
|---|
| 412 | double po = sw / 2;
|
|---|
| 413 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 414 | Path2D.Double p = new Path2D.Double(); 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));
|
|---|
| 415 | 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));
|
|---|
| 416 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 417 | break;
|
|---|
| 418 | case PCLR:
|
|---|
| 419 | width += height * 1.0;
|
|---|
| 420 | height *= 2.0;
|
|---|
| 421 | if (width < height) width = height;
|
|---|
| 422 | lx = -width / 2;
|
|---|
| 423 | ly = -height / 2;
|
|---|
| 424 | tx = lx + (height * 0.27);
|
|---|
| 425 | ty = ly + (height * 0.25);
|
|---|
| 426 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 427 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 428 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 429 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 430 | sw = 1 + (int)(height/10);
|
|---|
| 431 | po = sw / 2;
|
|---|
| 432 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 433 | p = new Path2D.Double(); 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));
|
|---|
| 434 | 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));
|
|---|
| 435 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 436 | label.add(new Instr(Form.SYMB, new Symbols.SubSymbol(Areas.CableFlash, 1, 0, 0, null, new Delta(Handle.CC, new AffineTransform(0,-1,1,0,-width/2,0)))));
|
|---|
| 437 | label.add(new Instr(Form.SYMB, new Symbols.SubSymbol(Areas.CableFlash, 1, 0, 0, null, new Delta(Handle.CC, new AffineTransform(0,-1,1,0,width/2,0)))));
|
|---|
| 438 | break;
|
|---|
| 439 | case HCLR:
|
|---|
| 440 | width += height * 1.5;
|
|---|
| 441 | height *= 1.5;
|
|---|
| 442 | if (width < height) width = height;
|
|---|
| 443 | lx = -width / 2;
|
|---|
| 444 | ly = -height / 2;
|
|---|
| 445 | tx = lx + (height * 0.5);
|
|---|
| 446 | ty = ly + (height * 0.17);
|
|---|
| 447 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 448 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 449 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 450 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 451 | sw = 1 + (int)(height/10);
|
|---|
| 452 | double vo = height / 4;
|
|---|
| 453 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 454 | p = new Path2D.Double(); p.moveTo(-width*0.4-sw,-ly-vo); p.lineTo(-width*0.4-sw,ly+vo); p.moveTo(-width*0.4-sw,0); p.lineTo(-width*0.4+sw,0);
|
|---|
| 455 | p.moveTo(width*0.4+sw,-ly-vo); p.lineTo(width*0.4+sw,ly+vo); p.moveTo(width*0.4-sw,0); p.lineTo(width*0.4+sw,0);
|
|---|
| 456 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 457 | break;
|
|---|
| 458 | default:
|
|---|
| 459 | lx = -width / 2;
|
|---|
| 460 | ly = -height / 2;
|
|---|
| 461 | tx = lx;
|
|---|
| 462 | ty = ly;
|
|---|
| 463 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 464 | break;
|
|---|
| 465 | }
|
|---|
| 466 | label.add(new Instr(Form.TEXT, new Caption(str, font, tc, new Delta(Handle.TL, AffineTransform.getTranslateInstance(tx, ty)))));
|
|---|
| 467 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 468 | Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, delta);
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | public static void lineText(Feature feature, String str, Font font, Color colour, double offset, double dy) {
|
|---|
| 472 | if (!str.isEmpty()) {
|
|---|
| 473 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|---|
| 474 | g2.setPaint(colour);
|
|---|
| 475 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 476 | GlyphVector gv = font.deriveFont((float)(font.getSize()*sScale)).createGlyphVector(frc, (" " + str));
|
|---|
| 477 | GeneralPath path = new GeneralPath();
|
|---|
| 478 | Point2D prev = new Point2D.Double();
|
|---|
| 479 | Point2D next = new Point2D.Double();
|
|---|
| 480 | Point2D curr = new Point2D.Double();
|
|---|
| 481 | Point2D succ = new Point2D.Double();
|
|---|
| 482 | boolean piv = false;
|
|---|
| 483 | double angle = 0;
|
|---|
| 484 | int index = 0;
|
|---|
| 485 | double gwidth = offset * (feature.geom.length * context.mile(feature) - gv.getLogicalBounds().getWidth()) + gv.getGlyphMetrics(0).getAdvance();
|
|---|
| 486 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 487 | while (git.hasComp()) {
|
|---|
| 488 | git.nextComp();
|
|---|
| 489 | boolean first = true;
|
|---|
| 490 | while (git.hasEdge()) {
|
|---|
| 491 | git.nextEdge();
|
|---|
| 492 | while (git.hasNode()) {
|
|---|
| 493 | prev = next;
|
|---|
| 494 | next = context.getPoint(git.next());
|
|---|
| 495 | angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
|
|---|
| 496 | piv = true;
|
|---|
| 497 | if (first) {
|
|---|
| 498 | curr = succ = next;
|
|---|
| 499 | first = false;
|
|---|
| 500 | } else {
|
|---|
| 501 | while (curr.distance(next) >= gwidth) {
|
|---|
| 502 | if (piv) {
|
|---|
| 503 | double rem = gwidth;
|
|---|
| 504 | double s = prev.distance(next);
|
|---|
| 505 | double p = curr.distance(prev);
|
|---|
| 506 | if ((s > 0) && (p > 0)) {
|
|---|
| 507 | double n = curr.distance(next);
|
|---|
| 508 | double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
|
|---|
| 509 | double phi = Math.asin(p / gwidth * Math.sin(theta));
|
|---|
| 510 | rem = gwidth * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
|
|---|
| 511 | }
|
|---|
| 512 | succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
|
|---|
| 513 | piv = false;
|
|---|
| 514 | } else {
|
|---|
| 515 | succ = new Point2D.Double(curr.getX() + (gwidth * Math.cos(angle)), curr.getY() + (gwidth * Math.sin(angle)));
|
|---|
| 516 | }
|
|---|
| 517 | Shape shape = gv.getGlyphOutline(index);
|
|---|
| 518 | Point2D point = gv.getGlyphPosition(index);
|
|---|
| 519 | AffineTransform at = AffineTransform.getTranslateInstance(curr.getX(), curr.getY());
|
|---|
| 520 | at.rotate(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())));
|
|---|
| 521 | at.translate(-point.getX(), -point.getY() + (dy * sScale));
|
|---|
| 522 | path.append(at.createTransformedShape(shape), false);
|
|---|
| 523 | curr = succ;
|
|---|
| 524 | if (++index < gv.getNumGlyphs()) {
|
|---|
| 525 | gwidth = gv.getGlyphMetrics(index).getAdvance();
|
|---|
| 526 | } else {
|
|---|
| 527 | g2.fill(path);
|
|---|
| 528 | return;
|
|---|
| 529 | }
|
|---|
| 530 | }
|
|---|
| 531 | }
|
|---|
| 532 | }
|
|---|
| 533 | }
|
|---|
| 534 | }
|
|---|
| 535 | }
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | public static void lightSector(Feature feature, Color col1, Color col2, double radius, double s1, double s2, boolean dir, String str) {
|
|---|
| 539 | if ((zoom >= 16) && (radius > 0.2)) {
|
|---|
| 540 | radius = 0.2 / (Math.pow(2, zoom-16));
|
|---|
| 541 | }
|
|---|
| 542 | double mid = (((s1 + s2) / 2) + (s1 > s2 ? 180 : 0)) % 360;
|
|---|
| 543 | g2.setStroke(new BasicStroke((float) (3.0 * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, new float[] {20 * (float)sScale, 20 * (float)sScale}, 0));
|
|---|
| 544 | g2.setPaint(Color.black);
|
|---|
| 545 | Point2D.Double centre = (Point2D.Double) context.getPoint(feature.geom.centre);
|
|---|
| 546 | double radial = radius * context.mile(feature);
|
|---|
| 547 | if (dir) {
|
|---|
| 548 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(mid)), centre.y + radial * Math.cos(Math.toRadians(mid))));
|
|---|
| 549 | } else {
|
|---|
| 550 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(s1)), centre.y + radial * Math.cos(Math.toRadians(s1))));
|
|---|
| 551 | g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(s2)), centre.y + radial * Math.cos(Math.toRadians(s2))));
|
|---|
| 552 | }
|
|---|
| 553 | double arcWidth = 10.0 * sScale;
|
|---|
| 554 | g2.setStroke(new BasicStroke((float)arcWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1));
|
|---|
| 555 | g2.setPaint(col1);
|
|---|
| 556 | g2.draw(new Arc2D.Double(centre.x - radial, centre.y - radial, 2 * radial, 2 * radial, -(s1 + 90), (s1 - s2 - 360) % 360, Arc2D.OPEN));
|
|---|
| 557 | if (col2 != null) {
|
|---|
| 558 | g2.setPaint(col2);
|
|---|
| 559 | g2.draw(new Arc2D.Double(centre.x - radial + arcWidth, centre.y - radial + arcWidth, 2 * (radial - arcWidth), 2 * (radial - arcWidth), -(s1 + 90), (s1 - s2 - 360) % 360, Arc2D.OPEN));
|
|---|
| 560 | }
|
|---|
| 561 | if ((str != null) && (!str.isEmpty())) {
|
|---|
| 562 | g2.setPaint(Color.black);
|
|---|
| 563 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|---|
| 564 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 565 | Font font = new Font("Arial", Font.PLAIN, 40);
|
|---|
| 566 | GeneralPath path = new GeneralPath();
|
|---|
| 567 | GlyphVector gv = font.deriveFont((float)(font.getSize()*sScale)).createGlyphVector(frc, (" " + str));
|
|---|
| 568 | double gwidth = gv.getLogicalBounds().getWidth();
|
|---|
| 569 | boolean hand = false;
|
|---|
| 570 | double offset = 0;
|
|---|
| 571 | Point2D origin;
|
|---|
| 572 | double arc = (s2 - s1 + 360) % 360;
|
|---|
| 573 | if (dir) {
|
|---|
| 574 | radial += 10 * sScale;
|
|---|
| 575 | if (mid < 180) {
|
|---|
| 576 | radial += gwidth;
|
|---|
| 577 | hand = true;
|
|---|
| 578 | }
|
|---|
| 579 | origin = new Point2D.Double(centre.x - radial * Math.sin(Math.toRadians(mid)), centre.y + radial * Math.cos(Math.toRadians(mid)));
|
|---|
| 580 | int length = gv.getNumGlyphs();
|
|---|
| 581 | for (int i = 0; i < length; i++) {
|
|---|
| 582 | Shape shape = gv.getGlyphOutline(i);
|
|---|
| 583 | Point2D point = gv.getGlyphPosition(i);
|
|---|
| 584 | AffineTransform at = AffineTransform.getTranslateInstance(origin.getX(), origin.getY());
|
|---|
| 585 | at.rotate(Math.toRadians(mid + (hand ? -90 : 90)));
|
|---|
| 586 | at.translate(-point.getX() + offset, -point.getY() + (15 * sScale));
|
|---|
| 587 | path.append(at.createTransformedShape(shape), false);
|
|---|
| 588 | offset += gv.getGlyphMetrics(i).getAdvance();
|
|---|
| 589 | g2.fill(path);
|
|---|
| 590 | }
|
|---|
| 591 | } else {
|
|---|
| 592 | double awidth = (Math.toRadians(arc) * radial);
|
|---|
| 593 | if (gwidth < awidth) {
|
|---|
| 594 | offset = 0;
|
|---|
| 595 | double phi = 0;
|
|---|
| 596 | if ((mid > 270) || (mid < 90)) {
|
|---|
| 597 | hand = true;
|
|---|
| 598 | phi = Math.toRadians(s2) - ((awidth - gwidth) / 2) /radial;
|
|---|
| 599 | radial -= 20 * sScale;
|
|---|
| 600 | } else {
|
|---|
| 601 | phi = Math.toRadians(s1) + (((awidth - gwidth) / 2)) /radial;
|
|---|
| 602 | radial += 20 * sScale;
|
|---|
| 603 | }
|
|---|
| 604 | origin = new Point2D.Double(centre.x - radial * Math.sin(phi), centre.y + radial * Math.cos(phi));
|
|---|
| 605 | int length = gv.getNumGlyphs();
|
|---|
| 606 | for (int i = 0; i < length; i++) {
|
|---|
| 607 | Shape shape = gv.getGlyphOutline(i);
|
|---|
| 608 | Point2D point = gv.getGlyphPosition(i);
|
|---|
| 609 | AffineTransform at = AffineTransform.getTranslateInstance(origin.getX(), origin.getY());
|
|---|
| 610 | at.rotate(phi + (hand ? 0 : Math.toRadians(180)));
|
|---|
| 611 | at.translate(-point.getX() + offset, -point.getY());
|
|---|
| 612 | path.append(at.createTransformedShape(shape), false);
|
|---|
| 613 | double advance = gv.getGlyphMetrics(i).getAdvance();
|
|---|
| 614 | offset += advance;
|
|---|
| 615 | phi += (hand ? -0.5 : +0.5) * advance / radial;
|
|---|
| 616 | g2.fill(path);
|
|---|
| 617 | }
|
|---|
| 618 | }
|
|---|
| 619 | }
|
|---|
| 620 | }
|
|---|
| 621 | }
|
|---|
| 622 | }
|
|---|