Changeset 29202 in osm for applications/editors/josm/plugins/smed2/src
- Timestamp:
- 2013-01-17T12:08:28+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/smed2/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/seamap/Renderer.java
r29200 r29202 11 11 12 12 import java.awt.BasicStroke; 13 import java.awt.Color; 14 import java.awt.Font; 13 15 import java.awt.Graphics2D; 16 import java.awt.Rectangle; 14 17 import java.awt.RenderingHints; 18 import java.awt.font.TextLayout; 15 19 import java.awt.geom.GeneralPath; 16 20 import java.awt.geom.Path2D; … … 25 29 import seamap.SeaMap; 26 30 import seamap.SeaMap.*; 31 import symbols.Areas; 27 32 import symbols.Symbols; 28 33 import symbols.Symbols.*; … … 69 74 public static double calcArea(Feature feature) { 70 75 if (feature.flag == Fflag.AREA) { 71 ArrayList<Long> way = map.ways.get(feature.refs); 76 ArrayList<Long> way; 77 if (map.mpolys.containsKey(feature.refs)) { 78 way = map.ways.get(map.mpolys.get(feature.refs)); 79 } else { 80 way = map.ways.get(feature.refs); 81 } 72 82 Coord coord = map.nodes.get(way.get(0)); 73 83 double llon = coord.lon; … … 89 99 public static Coord findCentroid(Feature feature) { 90 100 Coord coord; 91 ArrayList<Long> way = map.ways.get(feature.refs); 101 ArrayList<Long> way; 102 if (map.mpolys.containsKey(feature.refs)) { 103 way = map.ways.get(map.mpolys.get(feature.refs)); 104 } else { 105 way = map.ways.get(feature.refs); 106 } 92 107 switch (feature.flag) { 93 108 case NODE: … … 142 157 public static void lineVector (Feature feature, LineStyle style) { 143 158 if (feature.flag != Fflag.NODE) { 144 Long mpoly = map.outers.get(feature.refs);145 159 ArrayList<Long> ways = new ArrayList<Long>(); 146 if (m poly != null) {147 ways.addAll(map.mpolys.get(m poly));160 if (map.outers.containsKey(feature.refs)) { 161 ways.addAll(map.mpolys.get(map.outers.get(feature.refs))); 148 162 } else { 149 ways.add(feature.refs); 163 if (map.mpolys.containsKey(feature.refs)) { 164 ways.addAll(map.mpolys.get(feature.refs)); 165 } else { 166 ways.add(feature.refs); 167 } 150 168 } 151 169 Path2D.Double p = new Path2D.Double(); … … 168 186 System.arraycopy(style.dash, 0, dash, 0, style.dash.length); 169 187 for (int i = 0; i < style.dash.length; i++) { 170 dash[i] *= (float) (sScale);188 dash[i] *= (float) sScale; 171 189 } 172 190 g2.setStroke(new BasicStroke((float) (style.width * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, dash, 0)); … … 184 202 } 185 203 186 public static void labelText (Feature feature, String str, TextStyle style, Delta delta) { 204 public static void labelText (Feature feature, String str, Font font, Delta delta) { 205 Symbol label = new Symbol(); 206 label.add(new Instr(Prim.FILL, Color.black)); 207 label.add(new Instr(Prim.TEXT, new Caption(str, font, delta))); 208 Point2D point = helper.getPoint(findCentroid(feature)); 209 Symbols.drawSymbol(g2, label, tScale, point.getX(), point.getY(), delta, null); 210 } 211 212 public static void lineText (Feature feature, String str, Font font, double offset, double dy) { 187 213 188 214 } 189 190 public static void lineText (Feature feature, String str, TextStyle style, double offset, Delta delta) {191 192 }193 215 } -
applications/editors/josm/plugins/smed2/src/seamap/Rules.java
r29199 r29202 103 103 104 104 private static void shoreline(Feature feature) { 105 CatSLC cat = (CatSLC) Renderer.getAttVal(feature, feature.type, 0, Att.CATSLC);106 105 if (zoom >= 12) { 107 switch ( cat) {106 switch ((CatSLC) Renderer.getAttVal(feature, feature.type, 0, Att.CATSLC)) { 108 107 case SLC_TWAL: 109 108 WatLEV lev = (WatLEV) Renderer.getAttVal(feature, feature.type, 0, Att.WATLEV); … … 111 110 Renderer.lineVector(feature, new LineStyle(Color.black, 10, new float[] { 40, 40 }, null)); 112 111 if (zoom >= 15) 113 Renderer.lineText(feature, "(covers)", new TextStyle(new Font("Arial", Font.PLAIN, 80)), 0.5, new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, 20)));112 Renderer.lineText(feature, "(covers)", new Font("Arial", Font.PLAIN, 80), 0.5, 20); 114 113 } else { 115 114 Renderer.lineVector(feature, new LineStyle(Color.black, 10, null, null)); 116 115 } 117 116 if (zoom >= 15) 118 Renderer.lineText(feature, "Training Wall", new TextStyle(new Font("Arial", Font.PLAIN, 80)), 0.5, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -20)));117 Renderer.lineText(feature, "Training Wall", new Font("Arial", Font.PLAIN, 80), 0.5, -20); 119 118 } 120 119 } … … 149 148 AttItem name = feature.atts.get(Att.OBJNAM); 150 149 if ((zoom >= 10) && (name != null)) 151 Renderer.labelText(feature, (String) name.val, new TextStyle(new Font("Arial", Font.BOLD, 150)), null);150 Renderer.labelText(feature, (String) name.val, new Font("Arial", Font.BOLD, 150), null); 152 151 break; 153 152 case TSELNE: … … 171 170 } 172 171 if ((zoom >= 15) && (name != null)) 173 Renderer.labelText(feature, (String) name.val, new TextStyle(new Font("Arial", Font.BOLD, 80)), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -90)));172 Renderer.labelText(feature, (String) name.val, new Font("Arial", Font.BOLD, 80), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -90))); 174 173 break; 175 174 case MARCUL: … … 196 195 Renderer.lineVector(feature, new LineStyle(Color.black, 8, new float[] { 25, 25 }, null)); 197 196 if ((zoom >= 12) && (name != null)) 198 Renderer.labelText(feature, (String) name.val, new TextStyle(new Font("Arial", Font.PLAIN, 100)), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 0)));197 Renderer.labelText(feature, (String) name.val, new Font("Arial", Font.PLAIN, 100), new Delta(Handle.CC, AffineTransform.getTranslateInstance(0, 0))); 199 198 break; 200 199 case RESARE: … … 210 209 Renderer.lineVector(feature, new LineStyle(Color.black, 20, new float[] { 40, 40 }, null)); 211 210 if ((zoom >= 15) && (name != null)) 212 Renderer.labelText(feature, (String) name.val, new TextStyle(new Font("Arial", Font.BOLD, 80)), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, 10)));211 Renderer.labelText(feature, (String) name.val, new Font("Arial", Font.BOLD, 80), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, 10))); 213 212 } 214 213 break; 215 214 case SEAARE: 215 switch ((CatSEA) Renderer.getAttVal(feature, feature.type, 0, Att.CATSEA)) { 216 case SEA_RECH: 217 break; 218 case SEA_BAY: 219 break; 220 case SEA_SHOL: 221 break; 222 case SEA_GAT: 223 case SEA_NRRW: 224 break; 225 } 216 226 break; 217 227 case SNDWAV: -
applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java
r29200 r29202 120 120 private Feature feature; 121 121 private ArrayList<Long> list; 122 private long mpid;123 122 124 123 public SeaMap() { … … 154 153 list = new ArrayList<Long>(); 155 154 mpolys.put(id, list); 156 mpid = id; 155 feature = new Feature(); 156 feature.refs = id; 157 feature.flag = Fflag.AREA; 157 158 } 158 159 … … 164 165 if (outer) { 165 166 list.add(0, way); 166 outers.put(way, mpid);167 outers.put(way, feature.refs); 167 168 } else { 168 169 list.add(way); -
applications/editors/josm/plugins/smed2/src/smed2/MapImage.java
r29198 r29202 64 64 public void paint(Graphics2D g2, MapView mv, Bounds bb) { 65 65 Rectangle rect = Main.map.mapView.getBounds(); 66 g2.setBackground(new Color(0xb5d0d0));67 g2.clearRect(rect.x, rect.y, rect.width, rect.height);66 // g2.setBackground(new Color(0xb5d0d0)); 67 // g2.clearRect(rect.x, rect.y, rect.width, rect.height); 68 68 g2.setPaint(Color.black); 69 69 g2.setFont(new Font("Arial", Font.BOLD, 20)); -
applications/editors/josm/plugins/smed2/src/smed2/Smed2Action.java
r29198 r29202 207 207 if (data != null) { 208 208 for (OsmPrimitive osm : data) { 209 if ((osm instanceof Node) || (osm instanceof Way)) { 210 if (osm instanceof Node) { 211 map.addNode(((Node) osm).getUniqueId(), ((Node) osm).getCoor().lat(), ((Node) osm).getCoor().lon()); 212 } else { 213 map.addWay(((Way) osm).getUniqueId()); 214 for (Node node : ((Way) osm).getNodes()) { 215 map.addToWay((node.getUniqueId())); 216 } 217 } 218 for (Entry<String, String> entry : osm.getKeys().entrySet()) { 219 map.addTag(entry.getKey(), entry.getValue()); 220 } 221 map.tagsDone(osm.getUniqueId()); 209 if (osm instanceof Node) { 210 map.addNode(((Node) osm).getUniqueId(), ((Node) osm).getCoor().lat(), ((Node) osm).getCoor().lon()); 211 } else if (osm instanceof Way) { 212 map.addWay(((Way) osm).getUniqueId()); 213 for (Node node : ((Way) osm).getNodes()) { 214 map.addToWay((node.getUniqueId())); 215 } 222 216 } else if ((osm instanceof Relation) && ((Relation) osm).isMultipolygon()) { 223 217 map.addMpoly(((Relation) osm).getUniqueId()); … … 227 221 } 228 222 } 223 for (Entry<String, String> entry : osm.getKeys().entrySet()) { 224 map.addTag(entry.getKey(), entry.getValue()); 225 } 226 map.tagsDone(osm.getUniqueId()); 229 227 } 230 228 } -
applications/editors/josm/plugins/smed2/src/symbols/Notices.java
r29198 r29202 51 51 private static final Symbol Sport = new Symbol(); 52 52 static { 53 Sport.add(new Instr(Prim.TEXT, new Caption("SPORT", new TextStyle(new Font("Arial", Font.BOLD, 15)), (float)-25.0, (float)5.0)));53 Sport.add(new Instr(Prim.TEXT, new Caption("SPORT", new Font("Arial", Font.BOLD, 15), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 0))))); 54 54 } 55 55 private static final Symbol Turn = new Symbol(); … … 65 65 private static final Symbol VHF = new Symbol(); 66 66 static { 67 VHF.add(new Instr(Prim.TEXT, new Caption("VHF", new TextStyle(new Font("Arial", Font.BOLD, 20)), (float)-20.0, (float)-5.0)));67 VHF.add(new Instr(Prim.TEXT, new Caption("VHF", new Font("Arial", Font.BOLD, 20), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 0))))); 68 68 } 69 69 private static final Symbol Waterbike = new Symbol(); -
applications/editors/josm/plugins/smed2/src/symbols/Symbols.java
r29199 r29202 15 15 import java.awt.Graphics2D; 16 16 import java.awt.Rectangle; 17 import java.awt.font.TextLayout; 17 18 import java.awt.geom.*; 18 19 import java.util.ArrayList; … … 59 60 Object params; 60 61 61 Instr(Prim itype, Object iparams) {62 public Instr(Prim itype, Object iparams) { 62 63 type = itype; 63 64 params = iparams; … … 85 86 } 86 87 87 public static class TextStyle {88 Font font;89 90 public TextStyle(Font ifont) {91 font = ifont;92 }93 }94 95 88 public static class Caption { 96 89 String str; 97 TextStyle style; 98 float x; 99 float y; 100 101 public Caption(String istr, TextStyle istyle, float ix, float iy) { 90 Font font; 91 Delta dd; 92 93 public Caption(String istr, Font ifont, Delta idd) { 102 94 str = istr; 103 style = istyle; 104 x = ix; 105 y = iy; 95 font = ifont; 96 dd = idd; 106 97 } 107 98 } … … 167 158 switch (dd.h) { 168 159 case CC: 169 dx = bbox.x + (bbox.width / 2.0);170 dy = bbox.y + (bbox.height / 2.0);160 dx -= bbox.x + (bbox.width / 2.0); 161 dy -= bbox.y + (bbox.height / 2.0); 171 162 break; 172 163 case TL: 173 dx = bbox.x;174 dy = bbox.y;164 dx -= bbox.x; 165 dy -= bbox.y; 175 166 break; 176 167 case TR: 177 dx = bbox.x + bbox.width;178 dy = bbox.y;168 dx -= bbox.x + bbox.width; 169 dy -= bbox.y; 179 170 break; 180 171 case TC: 181 dx = bbox.x + (bbox.width / 2.0);182 dy = bbox.y;172 dx -= bbox.x + (bbox.width / 2.0); 173 dy -= bbox.y; 183 174 break; 184 175 case LC: 185 dx = bbox.x;186 dy = bbox.y + (bbox.height / 2.0);176 dx -= bbox.x; 177 dy -= bbox.y + (bbox.height / 2.0); 187 178 break; 188 179 case RC: 189 dx = bbox.x + bbox.width;190 dy = bbox.y + (bbox.height / 2.0);180 dx -= bbox.x + bbox.width; 181 dy -= bbox.y + (bbox.height / 2.0); 191 182 break; 192 183 case BL: 193 dx = bbox.x;194 dy = bbox.y + bbox.height;184 dx -= bbox.x; 185 dy -= bbox.y + bbox.height; 195 186 break; 196 187 case BR: 197 dx = bbox.x + bbox.width;198 dy = bbox.y + bbox.height;188 dx -= bbox.x + bbox.width; 189 dy -= bbox.y + bbox.height; 199 190 break; 200 191 case BC: 201 dx = bbox.x + (bbox.width / 2.0);202 dy = bbox.y + bbox.height;192 dx -= bbox.x + (bbox.width / 2.0); 193 dy -= bbox.y + bbox.height; 203 194 break; 204 195 } 205 g2.translate( -dx, -dy);196 g2.translate(dx, dy); 206 197 } 207 198 break; … … 296 287 case TEXT: 297 288 Caption c = (Caption) item.params; 298 g2.setFont(c.style.font); 299 g2.drawString(c.str, c.x, c.y); 289 TextLayout layout = new TextLayout(c.str, c.font, g2.getFontRenderContext()); 290 Rectangle2D bb = layout.getBounds(); 291 dx = 0; 292 dy = 0; 293 if (c.dd != null) { 294 g2.transform(c.dd.t); 295 switch (c.dd.h) { 296 case CC: 297 dx -= bb.getX() + (bb.getWidth() / 2.0); 298 dy -= bb.getY() + (bb.getHeight() / 2.0); 299 break; 300 case TL: 301 dx -= bb.getX(); 302 dy -= bb.getY(); 303 break; 304 case TR: 305 dx -= bb.getX() + bb.getWidth(); 306 dy -= bb.getY(); 307 break; 308 case TC: 309 dx -= bb.getX() + (bb.getWidth() / 2.0); 310 dy -= bb.getY(); 311 break; 312 case LC: 313 dx -= bb.getX(); 314 dy -= bb.getY() + (bb.getHeight() / 2.0); 315 break; 316 case RC: 317 dx -= bb.getX() + bb.getWidth(); 318 dy -= bb.getY() + (bb.getHeight() / 2.0); 319 break; 320 case BL: 321 dx -= bb.getX(); 322 dy -= bb.getY() + bb.getHeight(); 323 break; 324 case BR: 325 dx -= bb.getX() + bb.getWidth(); 326 dy -= bb.getY() + bb.getHeight(); 327 break; 328 case BC: 329 dx -= bb.getX() + (bb.getWidth() / 2.0); 330 dy -= bb.getY() + bb.getHeight(); 331 break; 332 } 333 } 334 layout.draw(g2, (float)dx, (float)dy); 300 335 break; 301 336 }
Note:
See TracChangeset
for help on using the changeset viewer.