| 1 | /* Copyright 2013 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 s57.S57val.*;
|
|---|
| 19 | import s57.S57map;
|
|---|
| 20 | import s57.S57map.*;
|
|---|
| 21 | import symbols.Areas;
|
|---|
| 22 | import symbols.Symbols;
|
|---|
| 23 | import symbols.Symbols.*;
|
|---|
| 24 |
|
|---|
| 25 | public class Renderer {
|
|---|
| 26 |
|
|---|
| 27 | 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, 0.138 };
|
|---|
| 28 |
|
|---|
| 29 | static final EnumMap<ColCOL, Color> bodyColours = new EnumMap<ColCOL, Color>(ColCOL.class);
|
|---|
| 30 | static {
|
|---|
| 31 | bodyColours.put(ColCOL.COL_UNK, new Color(0, true));
|
|---|
| 32 | bodyColours.put(ColCOL.COL_WHT, new Color(0xffffff));
|
|---|
| 33 | bodyColours.put(ColCOL.COL_BLK, new Color(0x000000));
|
|---|
| 34 | bodyColours.put(ColCOL.COL_RED, new Color(0xd40000));
|
|---|
| 35 | bodyColours.put(ColCOL.COL_GRN, new Color(0x00d400));
|
|---|
| 36 | bodyColours.put(ColCOL.COL_BLU, Color.blue);
|
|---|
| 37 | bodyColours.put(ColCOL.COL_YEL, new Color(0xffd400));
|
|---|
| 38 | bodyColours.put(ColCOL.COL_GRY, Color.gray);
|
|---|
| 39 | bodyColours.put(ColCOL.COL_BRN, new Color(0x8b4513));
|
|---|
| 40 | bodyColours.put(ColCOL.COL_AMB, new Color(0xfbf00f));
|
|---|
| 41 | bodyColours.put(ColCOL.COL_VIO, new Color(0xee82ee));
|
|---|
| 42 | bodyColours.put(ColCOL.COL_ORG, Color.orange);
|
|---|
| 43 | bodyColours.put(ColCOL.COL_MAG, new Color(0xf000f0));
|
|---|
| 44 | bodyColours.put(ColCOL.COL_PNK, Color.pink);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | static final EnumMap<ColPAT, Patt> pattMap = new EnumMap<ColPAT, Patt>(ColPAT.class);
|
|---|
| 48 | static {
|
|---|
| 49 | pattMap.put(ColPAT.PAT_UNKN, Patt.Z);
|
|---|
| 50 | pattMap.put(ColPAT.PAT_HORI, Patt.H);
|
|---|
| 51 | pattMap.put(ColPAT.PAT_VERT, Patt.V);
|
|---|
| 52 | pattMap.put(ColPAT.PAT_DIAG, Patt.D);
|
|---|
| 53 | pattMap.put(ColPAT.PAT_BRDR, Patt.B);
|
|---|
| 54 | pattMap.put(ColPAT.PAT_SQUR, Patt.S);
|
|---|
| 55 | pattMap.put(ColPAT.PAT_CROS, Patt.C);
|
|---|
| 56 | pattMap.put(ColPAT.PAT_SALT, Patt.X);
|
|---|
| 57 | pattMap.put(ColPAT.PAT_STRP, Patt.H);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | public enum LabelStyle { NONE, RRCT, RECT, ELPS, CIRC, VCLR, PCLR, HCLR }
|
|---|
| 61 |
|
|---|
| 62 | static MapContext context;
|
|---|
| 63 | static S57map map;
|
|---|
| 64 | static double sScale;
|
|---|
| 65 | static Graphics2D g2;
|
|---|
| 66 | static int zoom;
|
|---|
| 67 |
|
|---|
| 68 | public static void reRender(Graphics2D g, int z, double factor, S57map m, MapContext c) {
|
|---|
| 69 | g2 = g;
|
|---|
| 70 | zoom = z;
|
|---|
| 71 | context = c;
|
|---|
| 72 | map = m;
|
|---|
| 73 | sScale = symbolScale[zoom] * factor;
|
|---|
| 74 | if (map != null) {
|
|---|
| 75 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|---|
| 76 | g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
|
|---|
| 77 | g2.setStroke(new BasicStroke(0, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
|
|---|
| 78 | Rules.rules();
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | public static void symbol(Feature feature, Symbol symbol) {
|
|---|
| 83 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 84 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, null);
|
|---|
| 85 | }
|
|---|
| 86 | public static void symbol(Feature feature, Symbol symbol, Scheme scheme) {
|
|---|
| 87 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 88 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, null);
|
|---|
| 89 | }
|
|---|
| 90 | public static void symbol(Feature feature, Symbol symbol, Delta delta) {
|
|---|
| 91 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 92 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, delta);
|
|---|
| 93 | }
|
|---|
| 94 | public static void symbol(Feature feature, Symbol symbol, Scheme scheme, Delta delta) {
|
|---|
| 95 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 96 | Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), scheme, delta);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | public static void cluster(Feature feature, ArrayList<Symbol> symbols) {
|
|---|
| 100 | Rectangle2D.Double bbox = null;
|
|---|
| 101 | if (symbols.size() > 4) {
|
|---|
| 102 | for (Instr instr : symbols.get(0)) {
|
|---|
| 103 | if (instr.type == Form.BBOX) {
|
|---|
| 104 | bbox = (Rectangle2D.Double) instr.params;
|
|---|
| 105 | break;
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 | if (bbox == null) return;
|
|---|
| 109 | }
|
|---|
| 110 | switch (symbols.size()) {
|
|---|
| 111 | case 1:
|
|---|
| 112 | symbol(feature, symbols.get(0), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 113 | break;
|
|---|
| 114 | case 2:
|
|---|
| 115 | symbol(feature, symbols.get(0), new Delta(Handle.RC, new AffineTransform()));
|
|---|
| 116 | symbol(feature, symbols.get(1), new Delta(Handle.LC, new AffineTransform()));
|
|---|
| 117 | break;
|
|---|
| 118 | case 3:
|
|---|
| 119 | symbol(feature, symbols.get(0), new Delta(Handle.BC, new AffineTransform()));
|
|---|
| 120 | symbol(feature, symbols.get(1), new Delta(Handle.TR, new AffineTransform()));
|
|---|
| 121 | symbol(feature, symbols.get(2), new Delta(Handle.TL, new AffineTransform()));
|
|---|
| 122 | break;
|
|---|
| 123 | case 4:
|
|---|
| 124 | symbol(feature, symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
|
|---|
| 125 | symbol(feature, symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
|
|---|
| 126 | symbol(feature, symbols.get(2), new Delta(Handle.TR, new AffineTransform()));
|
|---|
| 127 | symbol(feature, symbols.get(3), new Delta(Handle.TL, new AffineTransform()));
|
|---|
| 128 | break;
|
|---|
| 129 | case 5:
|
|---|
| 130 | symbol(feature, symbols.get(0), new Delta(Handle.BR, new AffineTransform()));
|
|---|
| 131 | symbol(feature, symbols.get(1), new Delta(Handle.BL, new AffineTransform()));
|
|---|
| 132 | symbol(feature, symbols.get(2), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 133 | symbol(feature, symbols.get(3), new Delta(Handle.TC, new AffineTransform()));
|
|---|
| 134 | symbol(feature, symbols.get(4), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 135 | break;
|
|---|
| 136 | case 6:
|
|---|
| 137 | symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 138 | symbol(feature, symbols.get(1), new Delta(Handle.BC, new AffineTransform()));
|
|---|
| 139 | symbol(feature, symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 140 | symbol(feature, symbols.get(3), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 141 | symbol(feature, symbols.get(4), new Delta(Handle.TC, new AffineTransform()));
|
|---|
| 142 | symbol(feature, symbols.get(5), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 143 | break;
|
|---|
| 144 | case 7:
|
|---|
| 145 | symbol(feature, symbols.get(0), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 146 | symbol(feature, symbols.get(1), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 147 | symbol(feature, symbols.get(2), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 148 | symbol(feature, symbols.get(3), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 149 | symbol(feature, symbols.get(4), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 150 | symbol(feature, symbols.get(5), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 151 | symbol(feature, symbols.get(6), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 152 | break;
|
|---|
| 153 | case 8:
|
|---|
| 154 | symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 155 | symbol(feature, symbols.get(1), new Delta(Handle.BL, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 156 | symbol(feature, symbols.get(2), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 157 | symbol(feature, symbols.get(3), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 158 | symbol(feature, symbols.get(4), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 159 | symbol(feature, symbols.get(5), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 160 | symbol(feature, symbols.get(6), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 161 | symbol(feature, symbols.get(7), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 162 | break;
|
|---|
| 163 | case 9:
|
|---|
| 164 | symbol(feature, symbols.get(0), new Delta(Handle.BR, AffineTransform.getTranslateInstance(-bbox.width/2, -bbox.height/2)));
|
|---|
| 165 | symbol(feature, symbols.get(1), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -bbox.height/2)));
|
|---|
| 166 | symbol(feature, symbols.get(2), new Delta(Handle.BL, AffineTransform.getTranslateInstance(bbox.width/2, -bbox.height/2)));
|
|---|
| 167 | symbol(feature, symbols.get(3), new Delta(Handle.RC, AffineTransform.getTranslateInstance(-bbox.width/2, 0)));
|
|---|
| 168 | symbol(feature, symbols.get(4), new Delta(Handle.CC, new AffineTransform()));
|
|---|
| 169 | symbol(feature, symbols.get(5), new Delta(Handle.LC, AffineTransform.getTranslateInstance(bbox.width/2, 0)));
|
|---|
| 170 | symbol(feature, symbols.get(6), new Delta(Handle.TR, AffineTransform.getTranslateInstance(-bbox.width/2, bbox.height/2)));
|
|---|
| 171 | symbol(feature, symbols.get(7), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, bbox.height/2)));
|
|---|
| 172 | symbol(feature, symbols.get(8), new Delta(Handle.TL, AffineTransform.getTranslateInstance(bbox.width/2, bbox.height/2)));
|
|---|
| 173 | break;
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | private static Rectangle2D.Double symbolSize(Symbol symbol) {
|
|---|
| 178 | Symbol ssymb = symbol;
|
|---|
| 179 | while (ssymb != null) {
|
|---|
| 180 | for (Instr item : symbol) {
|
|---|
| 181 | if (item.type == Form.BBOX) {
|
|---|
| 182 | return (Rectangle2D.Double) item.params;
|
|---|
| 183 | }
|
|---|
| 184 | if (item.type == Form.SYMB) {
|
|---|
| 185 | ssymb = ((SubSymbol) item.params).instr;
|
|---|
| 186 | break;
|
|---|
| 187 | }
|
|---|
| 188 | }
|
|---|
| 189 | if (ssymb == symbol)
|
|---|
| 190 | break;
|
|---|
| 191 | }
|
|---|
| 192 | return null;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, Symbol tersymb, int ratio, Color col) {
|
|---|
| 196 | if ((feature.geom.prim == Pflag.NOSP) || (feature.geom.prim == Pflag.POINT))
|
|---|
| 197 | return;
|
|---|
| 198 | Rectangle2D.Double prect = symbolSize(prisymb);
|
|---|
| 199 | Rectangle2D.Double srect = symbolSize(secsymb);
|
|---|
| 200 | Rectangle2D.Double trect = symbolSize(tersymb);
|
|---|
| 201 | if (srect == null)
|
|---|
| 202 | ratio = 0;
|
|---|
| 203 | if (prect != null) {
|
|---|
| 204 | double psize = Math.abs(prect.getY()) * sScale;
|
|---|
| 205 | double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
|
|---|
| 206 | double tsize = (trect != null) ? Math.abs(srect.getY()) * sScale : 0;
|
|---|
| 207 | Point2D prev = new Point2D.Double();
|
|---|
| 208 | Point2D next = new Point2D.Double();
|
|---|
| 209 | Point2D curr = new Point2D.Double();
|
|---|
| 210 | Point2D succ = new Point2D.Double();
|
|---|
| 211 | boolean gap = true;
|
|---|
| 212 | boolean piv = false;
|
|---|
| 213 | double len = 0;
|
|---|
| 214 | double angle = 0;
|
|---|
| 215 | int stcount = ratio;
|
|---|
| 216 | boolean stflag = false;
|
|---|
| 217 | Symbol symbol = prisymb;
|
|---|
| 218 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 219 | while (git.hasMore()) {
|
|---|
| 220 | git.getMore();
|
|---|
| 221 | boolean first = true;
|
|---|
| 222 | while (git.hasNext()) {
|
|---|
| 223 | prev = next;
|
|---|
| 224 | next = context.getPoint(git.next());
|
|---|
| 225 | angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
|
|---|
| 226 | piv = true;
|
|---|
| 227 | if (first) {
|
|---|
| 228 | curr = succ = next;
|
|---|
| 229 | gap = (space > 0);
|
|---|
| 230 | stcount = ratio - 1;
|
|---|
| 231 | symbol = prisymb;
|
|---|
| 232 | len = gap ? psize * space * 0.5 : psize;
|
|---|
| 233 | first = false;
|
|---|
| 234 | } else {
|
|---|
| 235 | while (curr.distance(next) >= len) {
|
|---|
| 236 | if (piv) {
|
|---|
| 237 | double rem = len;
|
|---|
| 238 | double s = prev.distance(next);
|
|---|
| 239 | double p = curr.distance(prev);
|
|---|
| 240 | if ((s > 0) && (p > 0)) {
|
|---|
| 241 | double n = curr.distance(next);
|
|---|
| 242 | double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
|
|---|
| 243 | double phi = Math.asin(p / len * Math.sin(theta));
|
|---|
| 244 | rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
|
|---|
| 245 | }
|
|---|
| 246 | succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
|
|---|
| 247 | piv = false;
|
|---|
| 248 | } else {
|
|---|
| 249 | succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
|
|---|
| 250 | }
|
|---|
| 251 | if (!gap) {
|
|---|
| 252 | Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Scheme(col),
|
|---|
| 253 | new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))));
|
|---|
| 254 | }
|
|---|
| 255 | if (space > 0)
|
|---|
| 256 | gap = !gap;
|
|---|
| 257 | curr = succ;
|
|---|
| 258 | len = gap ? (psize * space) : (--stcount == 0) ? (stflag ? tsize : ssize) : psize;
|
|---|
| 259 | if (stcount == 0) {
|
|---|
| 260 | symbol = stflag ? tersymb : secsymb;
|
|---|
| 261 | if (trect != null) stflag = !stflag;
|
|---|
| 262 | stcount = ratio;
|
|---|
| 263 | } else {
|
|---|
| 264 | symbol = prisymb;
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| 267 | }
|
|---|
| 268 | }
|
|---|
| 269 | }
|
|---|
| 270 | }
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | public static void lineVector(Feature feature, LineStyle style) {
|
|---|
| 274 | Path2D.Double p = new Path2D.Double();
|
|---|
| 275 | p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
|
|---|
| 276 | Point2D point;
|
|---|
| 277 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 278 | while (git.hasMore()) {
|
|---|
| 279 | git.getMore();
|
|---|
| 280 | point = context.getPoint(git.next());
|
|---|
| 281 | p.moveTo(point.getX(), point.getY());
|
|---|
| 282 | while (git.hasNext()) {
|
|---|
| 283 | point = context.getPoint(git.next());
|
|---|
| 284 | p.lineTo(point.getX(), point.getY());
|
|---|
| 285 | }
|
|---|
| 286 | }
|
|---|
| 287 | if (style.line != null) {
|
|---|
| 288 | if (style.dash != null) {
|
|---|
| 289 | float[] dash = new float[style.dash.length];
|
|---|
| 290 | System.arraycopy(style.dash, 0, dash, 0, style.dash.length);
|
|---|
| 291 | for (int i = 0; i < style.dash.length; i++) {
|
|---|
| 292 | dash[i] *= (float) sScale;
|
|---|
| 293 | }
|
|---|
| 294 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, dash, 0));
|
|---|
| 295 | } else {
|
|---|
| 296 | g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
|
|---|
| 297 | }
|
|---|
| 298 | g2.setPaint(style.line);
|
|---|
| 299 | g2.draw(p);
|
|---|
| 300 | }
|
|---|
| 301 | if (style.fill != null) {
|
|---|
| 302 | g2.setPaint(style.fill);
|
|---|
| 303 | g2.fill(p);
|
|---|
| 304 | }
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | public static void lineCircle(Feature feature, LineStyle style, double radius, UniHLU units) {
|
|---|
| 308 | switch (units) {
|
|---|
| 309 | case HLU_FEET:
|
|---|
| 310 | radius /= 6076;
|
|---|
| 311 | break;
|
|---|
| 312 | case HLU_KMTR:
|
|---|
| 313 | radius /= 1.852;
|
|---|
| 314 | break;
|
|---|
| 315 | case HLU_HMTR:
|
|---|
| 316 | radius /= 18.52;
|
|---|
| 317 | break;
|
|---|
| 318 | case HLU_SMIL:
|
|---|
| 319 | radius /= 1.15078;
|
|---|
| 320 | break;
|
|---|
| 321 | case HLU_NMIL:
|
|---|
| 322 | break;
|
|---|
| 323 | default:
|
|---|
| 324 | radius /= 1852;
|
|---|
| 325 | break;
|
|---|
| 326 | }
|
|---|
| 327 | radius *= context.mile(feature);
|
|---|
| 328 | Symbol circle = new Symbol();
|
|---|
| 329 | if (style.fill != null) {
|
|---|
| 330 | circle.add(new Instr(Form.FILL, style.fill));
|
|---|
| 331 | circle.add(new Instr(Form.RSHP, new Ellipse2D.Double(-radius,-radius,radius*2,radius*2)));
|
|---|
| 332 | }
|
|---|
| 333 | circle.add(new Instr(Form.FILL, style.line));
|
|---|
| 334 | circle.add(new Instr(Form.STRK, new BasicStroke(style.width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, style.dash, 0)));
|
|---|
| 335 | circle.add(new Instr(Form.ELPS, new Ellipse2D.Double(-radius,-radius,radius*2,radius*2)));
|
|---|
| 336 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 337 | Symbols.drawSymbol(g2, circle, 1, point.getX(), point.getY(), null, null);
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 | public static void fillPattern(Feature feature, BufferedImage image) {
|
|---|
| 342 | Path2D.Double p = new Path2D.Double();
|
|---|
| 343 | p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
|
|---|
| 344 | Point2D point;
|
|---|
| 345 | switch (feature.geom.prim) {
|
|---|
| 346 | case POINT:
|
|---|
| 347 | point = context.getPoint(feature.geom.centre);
|
|---|
| 348 | g2.drawImage(image, new AffineTransformOp(AffineTransform.getScaleInstance(sScale, sScale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
|
|---|
| 349 | (int)(point.getX() - (50 * sScale)), (int)(point.getY() - (50 * sScale)));
|
|---|
| 350 | break;
|
|---|
| 351 | case AREA:
|
|---|
| 352 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 353 | while (git.hasMore()) {
|
|---|
| 354 | git.getMore();
|
|---|
| 355 | point = context.getPoint(git.next());
|
|---|
| 356 | p.moveTo(point.getX(), point.getY());
|
|---|
| 357 | while (git.hasNext()) {
|
|---|
| 358 | point = context.getPoint(git.next());
|
|---|
| 359 | p.lineTo(point.getX(), point.getY());
|
|---|
| 360 | }
|
|---|
| 361 | }
|
|---|
| 362 | g2.setPaint(new TexturePaint(image, new Rectangle(0, 0, 1 + (int)(100 * sScale), 1 + (int)(100 * sScale))));
|
|---|
| 363 | g2.fill(p);
|
|---|
| 364 | break;
|
|---|
| 365 | default:
|
|---|
| 366 | break;
|
|---|
| 367 | }
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | public static void labelText(Feature feature, String str, Font font, Color tc) {
|
|---|
| 371 | labelText(feature, str, font, tc, LabelStyle.NONE, null, null, null);
|
|---|
| 372 | }
|
|---|
| 373 | public static void labelText(Feature feature, String str, Font font, Color tc, Delta delta) {
|
|---|
| 374 | labelText(feature, str, font, tc, LabelStyle.NONE, null, null, delta);
|
|---|
| 375 | }
|
|---|
| 376 | public static void labelText(Feature feature, String str, Font font, Color tc, LabelStyle style, Color fg) {
|
|---|
| 377 | labelText(feature, str, font, tc, style, fg, null, null);
|
|---|
| 378 | }
|
|---|
| 379 | public static void labelText(Feature feature, String str, Font font, Color tc, LabelStyle style, Color fg, Color bg) {
|
|---|
| 380 | labelText(feature, str, font, tc, style, fg, bg, null);
|
|---|
| 381 | }
|
|---|
| 382 | public static void labelText(Feature feature, String str, Font font, Color tc, LabelStyle style, Color fg, Delta delta) {
|
|---|
| 383 | labelText(feature, str, font, tc, style, fg, null, delta);
|
|---|
| 384 | }
|
|---|
| 385 | public static void labelText(Feature feature, String str, Font font, Color tc, LabelStyle style, Color fg, Color bg, Delta delta) {
|
|---|
| 386 | if (delta == null) delta = new Delta(Handle.CC);
|
|---|
| 387 | if (bg == null) bg = new Color(0x00000000, true);
|
|---|
| 388 | if ((str == null) || (str.isEmpty())) str = " ";
|
|---|
| 389 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 390 | GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "!" : str);
|
|---|
| 391 | Rectangle2D bounds = gv.getVisualBounds();
|
|---|
| 392 | double width = bounds.getWidth();
|
|---|
| 393 | double height = bounds.getHeight();
|
|---|
| 394 | Symbol label = new Symbol();
|
|---|
| 395 | double lx, ly, tx, ty;
|
|---|
| 396 | switch (style) {
|
|---|
| 397 | case RRCT:
|
|---|
| 398 | width += height * 1.0;
|
|---|
| 399 | height *= 1.5;
|
|---|
| 400 | if (width < height) width = height;
|
|---|
| 401 | lx = -width / 2;
|
|---|
| 402 | ly = -height / 2;
|
|---|
| 403 | tx = lx + (height * 0.34);
|
|---|
| 404 | ty = ly + (height * 0.17);
|
|---|
| 405 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 406 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 407 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 408 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 409 | label.add(new Instr(Form.STRK, new BasicStroke(1 + (int)(height/10), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 410 | label.add(new Instr(Form.RRCT, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 411 | break;
|
|---|
| 412 | case VCLR:
|
|---|
| 413 | width += height * 1.0;
|
|---|
| 414 | height *= 2.0;
|
|---|
| 415 | if (width < height) width = height;
|
|---|
| 416 | lx = -width / 2;
|
|---|
| 417 | ly = -height / 2;
|
|---|
| 418 | tx = lx + (height * 0.27);
|
|---|
| 419 | ty = ly + (height * 0.25);
|
|---|
| 420 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 421 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 422 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 423 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 424 | int sw = 1 + (int)(height/10);
|
|---|
| 425 | double po = sw / 2;
|
|---|
| 426 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 427 | 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));
|
|---|
| 428 | 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));
|
|---|
| 429 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 430 | break;
|
|---|
| 431 | case PCLR:
|
|---|
| 432 | width += height * 1.0;
|
|---|
| 433 | height *= 2.0;
|
|---|
| 434 | if (width < height) width = height;
|
|---|
| 435 | lx = -width / 2;
|
|---|
| 436 | ly = -height / 2;
|
|---|
| 437 | tx = lx + (height * 0.27);
|
|---|
| 438 | ty = ly + (height * 0.25);
|
|---|
| 439 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 440 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 441 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 442 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 443 | sw = 1 + (int)(height/10);
|
|---|
| 444 | po = sw / 2;
|
|---|
| 445 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 446 | 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));
|
|---|
| 447 | 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));
|
|---|
| 448 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 449 | 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)))));
|
|---|
| 450 | 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)))));
|
|---|
| 451 | break;
|
|---|
| 452 | case HCLR:
|
|---|
| 453 | width += height * 1.5;
|
|---|
| 454 | height *= 1.5;
|
|---|
| 455 | if (width < height) width = height;
|
|---|
| 456 | lx = -width / 2;
|
|---|
| 457 | ly = -height / 2;
|
|---|
| 458 | tx = lx + (height * 0.5);
|
|---|
| 459 | ty = ly + (height * 0.17);
|
|---|
| 460 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 461 | label.add(new Instr(Form.FILL, bg));
|
|---|
| 462 | label.add(new Instr(Form.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
|
|---|
| 463 | label.add(new Instr(Form.FILL, fg));
|
|---|
| 464 | sw = 1 + (int)(height/10);
|
|---|
| 465 | double vo = height / 4;
|
|---|
| 466 | label.add(new Instr(Form.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
|
|---|
| 467 | 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);
|
|---|
| 468 | 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);
|
|---|
| 469 | label.add(new Instr(Form.PLIN, p));
|
|---|
| 470 | break;
|
|---|
| 471 | default:
|
|---|
| 472 | lx = -width / 2;
|
|---|
| 473 | ly = -height / 2;
|
|---|
| 474 | tx = lx;
|
|---|
| 475 | ty = ly;
|
|---|
| 476 | label.add(new Instr(Form.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
|
|---|
| 477 | break;
|
|---|
| 478 | }
|
|---|
| 479 | label.add(new Instr(Form.TEXT, new Caption(str, font, tc, new Delta(Handle.TL, AffineTransform.getTranslateInstance(tx, ty)))));
|
|---|
| 480 | Point2D point = context.getPoint(feature.geom.centre);
|
|---|
| 481 | Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, delta);
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 | public static void lineText(Feature feature, String str, Font font, Color colour, double offset, double dy) {
|
|---|
| 485 | // Rectangle prect = symbolSize(prisymb);
|
|---|
| 486 | if (!str.isEmpty()) {
|
|---|
| 487 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|---|
| 488 | FontRenderContext frc = g2.getFontRenderContext();
|
|---|
| 489 | GlyphVector gv = font.deriveFont((float)(font.getSize()*sScale)).createGlyphVector(frc, str);
|
|---|
| 490 | // double psize = Math.abs(prect.getX());
|
|---|
| 491 | Point2D prev = new Point2D.Double();
|
|---|
| 492 | Point2D next = new Point2D.Double();
|
|---|
| 493 | Point2D curr = new Point2D.Double();
|
|---|
| 494 | Point2D succ = new Point2D.Double();
|
|---|
| 495 | boolean piv = false;
|
|---|
| 496 | double len = 0;
|
|---|
| 497 | double angle = 0;
|
|---|
| 498 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 499 | while (git.hasMore()) {
|
|---|
| 500 | git.getMore();
|
|---|
| 501 | boolean first = true;
|
|---|
| 502 | while (git.hasNext()) {
|
|---|
| 503 | prev = next;
|
|---|
| 504 | next = context.getPoint(git.next());
|
|---|
| 505 | angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
|
|---|
| 506 | piv = true;
|
|---|
| 507 | if (first) {
|
|---|
| 508 | curr = succ = next;
|
|---|
| 509 | // len = psize;
|
|---|
| 510 | first = false;
|
|---|
| 511 | } else {
|
|---|
| 512 | while (curr.distance(next) >= len) {
|
|---|
| 513 | if (piv) {
|
|---|
| 514 | double rem = len;
|
|---|
| 515 | double s = prev.distance(next);
|
|---|
| 516 | double p = curr.distance(prev);
|
|---|
| 517 | if ((s > 0) && (p > 0)) {
|
|---|
| 518 | double n = curr.distance(next);
|
|---|
| 519 | double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
|
|---|
| 520 | double phi = Math.asin(p / len * Math.sin(theta));
|
|---|
| 521 | rem = len * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
|
|---|
| 522 | }
|
|---|
| 523 | succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
|
|---|
| 524 | piv = false;
|
|---|
| 525 | } else {
|
|---|
| 526 | succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
|
|---|
| 527 | }
|
|---|
| 528 | // Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())) + Math.toRadians(90))), null);
|
|---|
| 529 | curr = succ;
|
|---|
| 530 | // len = psize;
|
|---|
| 531 | }
|
|---|
| 532 | }
|
|---|
| 533 | }
|
|---|
| 534 | }
|
|---|
| 535 | }
|
|---|
| 536 | }
|
|---|
| 537 | }
|
|---|