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