Changeset 29266 in osm for applications/editors/josm/plugins/smed2/src/seamap/Renderer.java
- Timestamp:
- 2013-02-19T18:02:02+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/seamap/Renderer.java
r29215 r29266 10 10 package seamap; 11 11 12 import java.awt.BasicStroke; 13 import java.awt.Color; 14 import java.awt.Font; 15 import java.awt.Graphics2D; 16 import java.awt.Rectangle; 17 import java.awt.RenderingHints; 18 import java.awt.geom.AffineTransform; 19 import java.awt.geom.GeneralPath; 20 import java.awt.geom.Path2D; 21 import java.awt.geom.Point2D; 22 import java.util.ArrayList; 23 import java.util.HashMap; 24 25 import s57.S57att.Att; 26 import s57.S57obj.Obj; 12 import java.awt.*; 13 import java.awt.geom.*; 14 import java.util.*; 15 16 import s57.S57att.*; 17 import s57.S57obj.*; 27 18 import s57.S57val.*; 28 19 import s57.S57val; … … 71 62 } 72 63 73 public static double signedArea(Feature feature) {74 if (feature.flag == Fflag.AREA) {75 ArrayList<Long> way;76 if (map.mpolys.containsKey(feature.refs)) {77 way = map.ways.get(map.mpolys.get(feature.refs));78 } else {79 way = map.ways.get(feature.refs);80 }81 Coord coord = map.nodes.get(way.get(0));82 double llon = coord.lon;83 double llat = coord.lat;84 double sigma = 0.0;85 for (long node : way) {86 coord = map.nodes.get(node);87 double lat = coord.lat;88 double lon = coord.lon;89 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));90 llon = lon;91 llat = lat;92 }93 return sigma;94 }95 return 0;96 }97 98 public boolean handOfArea(Feature feature) {99 return (signedArea(feature) < 0);100 }101 102 public static double calcArea(Feature feature) {103 return Math.abs(signedArea(feature)) * 3444 * 3444 / 2.0;104 }105 106 public static Coord findCentroid(Feature feature) {107 Coord coord;108 ArrayList<Long> way;109 if (map.mpolys.containsKey(feature.refs)) {110 way = map.ways.get(map.mpolys.get(feature.refs).get(0));111 } else {112 way = map.ways.get(feature.refs);113 }114 switch (feature.flag) {115 case NODE:116 return map.nodes.get(feature.refs);117 case LINE:118 coord = map.nodes.get(way.get(1));119 break;120 case AREA:121 default:122 coord = map.nodes.get(way.get(0));123 }124 double slat = 0.0;125 double slon = 0.0;126 double sarc = 0.0;127 double llat = coord.lat;128 double llon = coord.lon;129 for (long node : way) {130 coord = map.nodes.get(node);131 double lon = coord.lon;132 double lat = coord.lat;133 double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));134 slat += (lat * arc);135 slon += (lon * arc);136 sarc += arc;137 llat = lat;138 llon = lon;139 }140 return map.new Coord((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0));141 }142 143 64 public static void symbol(Feature feature, Symbol symbol, Obj obj, Delta delta) { 144 Point2D point = helper.getPoint(f indCentroid(feature));65 Point2D point = helper.getPoint(feature.centre); 145 66 if (obj == null) { 146 67 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), delta, null); … … 171 92 172 93 public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, int ratio) { 173 if (feature.flag != Fflag. NODE) {94 if (feature.flag != Fflag.POINT) { 174 95 Rectangle prect = symbolSize(prisymb); 175 96 Rectangle srect = symbolSize(secsymb); … … 180 101 double psize = Math.abs(prect.getY()) * sScale; 181 102 double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0; 182 if (map.outers.containsKey(feature.refs)) { 183 ways.addAll(map.mpolys.get(map.outers.get(feature.refs))); 184 } else { 185 if (map.mpolys.containsKey(feature.refs)) { 186 ways.addAll(map.mpolys.get(feature.refs)); 187 } else { 188 ways.add(feature.refs); 189 } 190 } 103 // if (map.outers.containsKey(feature.refs)) { 104 // ways.addAll(map.mpolys.get(map.outers.get(feature.refs))); 105 // } else { 106 // if (map.mpolys.containsKey(feature.refs)) { 107 // ways.addAll(map.mpolys.get(feature.refs)); 108 // } else { 109 // ways.add(feature.refs); 110 // } 111 // } 191 112 Point2D prev = new Point2D.Double(); 192 113 Point2D next = new Point2D.Double(); … … 201 122 for (long way : ways) { 202 123 boolean first = true; 203 for (long node : map.ways.get(way)) { 124 /* for (long node : map.ways.get(way)) { 204 125 prev = next; 205 next = helper.getPoint(map. nodes.get(node));126 next = helper.getPoint(map.points.get(node)); 206 127 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX()); 207 128 piv = true; … … 246 167 } 247 168 } 248 } 169 */ } 249 170 } 250 171 } … … 252 173 253 174 public static void lineVector (Feature feature, LineStyle style) { 254 if (feature.flag != Fflag. NODE) {175 if (feature.flag != Fflag.POINT) { 255 176 ArrayList<Long> ways = new ArrayList<Long>(); 256 if (map.outers.containsKey(feature.refs)) { 257 ways.addAll(map.mpolys.get(map.outers.get(feature.refs))); 258 } else { 259 if (map.mpolys.containsKey(feature.refs)) { 260 ways.addAll(map.mpolys.get(feature.refs)); 261 } else { 262 ways.add(feature.refs); 263 } 264 } 177 // if (map.outers.containsKey(feature.refs)) { 178 // ways.addAll(map.mpolys.get(map.outers.get(feature.refs))); 179 // } else { 180 // if (map.mpolys.containsKey(feature.refs)) { 181 // ways.addAll(map.mpolys.get(feature.refs)); 182 // } else { 183 // ways.add(feature.refs); 184 // } 185 // } 265 186 Path2D.Double p = new Path2D.Double(); 266 187 p.setWindingRule(GeneralPath.WIND_EVEN_ODD); 267 188 for (long way : ways) { 268 189 boolean first = true; 269 for (long node : map.ways.get(way)) { 270 Point2D point = helper.getPoint(map. nodes.get(node));190 /* for (long node : map.ways.get(way)) { 191 Point2D point = helper.getPoint(map.points.get(node)); 271 192 if (first) { 272 193 p.moveTo(point.getX(), point.getY()); … … 294 215 g2.setPaint(style.fill); 295 216 g2.fill(p); 296 } 217 */ } 297 218 } 298 219 } … … 301 222 Symbol label = new Symbol(); 302 223 label.add(new Instr(Prim.TEXT, new Caption(str, font, colour, (delta == null) ? new Delta(Handle.CC, null) : delta))); 303 Point2D point = helper.getPoint(f indCentroid(feature));224 Point2D point = helper.getPoint(feature.centre); 304 225 Symbols.drawSymbol(g2, label, tScale, point.getX(), point.getY(), null, null); 305 226 }
Note:
See TracChangeset
for help on using the changeset viewer.