Changeset 29184 in osm for applications/editors
- Timestamp:
- 2013-01-08T21:26:40+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/smed2/src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/seamap/Renderer.java
r29175 r29184 14 14 import java.awt.geom.Point2D; 15 15 import java.util.ArrayList; 16 import java.util.EnumMap;17 16 import java.util.HashMap; 18 17 … … 43 42 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 44 43 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); 45 Rules. MainRules(map, zoom);44 Rules.rules(map, zoom); 46 45 } 47 46 } 48 47 49 public static EnumMap<Att, AttItem>getAtts(Feature feature, Obj obj, int idx) {50 HashMap<Integer, EnumMap<Att, AttItem>> objs = feature.objs.get(obj);48 public static AttMap getAtts(Feature feature, Obj obj, int idx) { 49 HashMap<Integer, AttMap> objs = feature.objs.get(obj); 51 50 if (objs == null) return null; 52 51 else return objs.get(idx); … … 54 53 55 54 public static Object getAttVal(Feature feature, Obj obj, int idx, Att att) { 56 EnumMap<Att, AttItem>atts = getAtts(feature, obj, idx);55 AttMap atts = getAtts(feature, obj, idx); 57 56 if (atts == null) return S57val.nullVal(att); 58 57 else { … … 62 61 } 63 62 } 63 64 public static Coord findCentroid(Feature feature) { 65 double slon = 0.0; 66 double slat = 0.0; 67 double sarc = 0.0; 68 double llon = 0.0; 69 double llat = 0.0; 70 if (feature.flag == Fflag.NODE) { 71 return map.nodes.get(feature.refs); 72 } 73 ArrayList<Long> way = map.ways.get(feature.refs); 74 if (feature.flag == Fflag.WAY) { 75 llon = map.nodes.get(way.get(1)).lon; 76 llat = map.nodes.get(way.get(1)).lat; 77 } else { 78 llon = map.nodes.get(way.get(0)).lon; 79 llat = map.nodes.get(way.get(0)).lat; 80 } 81 for (long node : way) { 82 double lon = map.nodes.get(node).lon; 83 double lat = map.nodes.get(node).lat; 84 double arc = Math.sqrt(Math.pow((lon-llon), 2) + Math.pow((lat-llat), 2)); 85 slon += (lon * arc); 86 slat += (lat * arc); 87 sarc += arc; 88 llon = lon; 89 llat = lat; 90 } 91 return map.new Coord((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0)); 92 } 64 93 65 94 public static void symbol(Feature feature, ArrayList<Instr> symbol, Obj obj) { 66 Point2D point = helper.getPoint( map.nodes.get(feature.refs));95 Point2D point = helper.getPoint(findCentroid(feature)); 67 96 ArrayList<ColCOL> colours = (ArrayList<ColCOL>) getAttVal(feature, obj, 0, Att.COLOUR); 68 97 ArrayList<ColPAT> pattern = (ArrayList<ColPAT>) getAttVal(feature, obj, 0, Att.COLPAT); -
applications/editors/josm/plugins/smed2/src/seamap/Rules.java
r29176 r29184 28 28 static int zoom; 29 29 30 public static void MainRules (SeaMap m, int z) {30 public static void rules (SeaMap m, int z) { 31 31 map = m; 32 32 zoom = z; … … 123 123 ArrayList<Instr> fncSym = Landmarks.Funcs.get(fncs.get(0)); 124 124 if ((fncs.get(0) == FncFNC.FNC_CHCH) && (cats.get(0) == CatLMK.LMK_TOWR)) catSym = Landmarks.ChurchTower; 125 if ((cats.get(0) == CatLMK.LMK_UNKN) && (fncs.get(0) == FncFNC.FNC_UNKN)) catSym = Beacons.LightMajor; 125 126 Renderer.symbol(feature, catSym, feature.type); 126 127 Renderer.symbol(feature, fncSym, feature.type); -
applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java
r29174 r29184 15 15 16 16 import s57.S57att; 17 import s57.S57att. *;17 import s57.S57att.Att; 18 18 import s57.S57obj; 19 19 import s57.S57obj.*; … … 37 37 } 38 38 39 public class AttMap extends EnumMap<Att, AttItem> { 40 private static final long serialVersionUID = 1L; 41 public AttMap() { 42 super(Att.class); 43 } 44 } 45 46 public class ObjTab extends HashMap<Integer, AttMap> { 47 private static final long serialVersionUID = 1L; 48 public ObjTab() { 49 super(); 50 } 51 } 52 53 public class ObjMap extends EnumMap<Obj, ObjTab> { 54 private static final long serialVersionUID = 1L; 55 public ObjMap() { 56 super(Obj.class); 57 } 58 } 59 60 public class NodeTab extends HashMap<Long, Coord> { 61 private static final long serialVersionUID = 1L; 62 public NodeTab() { 63 super(); 64 } 65 } 66 67 public class WayTab extends HashMap<Long, ArrayList<Long>> { 68 private static final long serialVersionUID = 1L; 69 public WayTab() { 70 super(); 71 } 72 } 73 74 public class FtrMap extends EnumMap<Obj, ArrayList<Feature>> { 75 private static final long serialVersionUID = 1L; 76 public FtrMap() { 77 super(Obj.class); 78 } 79 } 80 81 public class FtrTab extends HashMap<Long, Feature> { 82 private static final long serialVersionUID = 1L; 83 public FtrTab() { 84 super(); 85 } 86 } 87 39 88 public class Feature { 40 89 public Fflag flag; 41 90 public long refs; 42 91 public Obj type; 43 public EnumMap<Att, AttItem>atts;44 public EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>>objs;92 public AttMap atts; 93 public ObjMap objs; 45 94 46 95 Feature() { … … 48 97 refs = 0; 49 98 type = Obj.UNKOBJ; 50 atts = new EnumMap<Att, AttItem>(Att.class);51 objs = new EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>>(Obj.class);99 atts = new AttMap(); 100 objs = new ObjMap(); 52 101 } 53 102 } … … 57 106 public double lon; 58 107 59 Coord(double ilat, double ilon) {108 public Coord(double ilat, double ilon) { 60 109 lat = ilat; 61 110 lon = ilon; … … 63 112 } 64 113 65 public HashMap<Long, Coord> nodes; 66 public HashMap<Long, ArrayList<Long>> ways; 67 public HashMap<Long, ArrayList<Long>> mpolys; 68 public EnumMap<Obj, ArrayList<Feature>> features; 114 public NodeTab nodes; 115 public WayTab ways; 116 public WayTab mpolys; 117 public FtrMap features; 118 public FtrTab index; 69 119 70 120 private Feature feature; … … 72 122 73 123 public SeaMap() { 74 nodes = new HashMap<Long, Coord>();75 ways = new HashMap<Long, ArrayList<Long>>();76 mpolys = new HashMap<Long, ArrayList<Long>>();124 nodes = new NodeTab(); 125 ways = new WayTab(); 126 mpolys = new WayTab(); 77 127 feature = new Feature(); 78 features = new EnumMap<Obj, ArrayList<Feature>>(Obj.class); 128 features = new FtrMap(); 129 index = new FtrTab(); 79 130 } 80 131 … … 84 135 feature.refs = id; 85 136 feature.flag = Fflag.NODE; 137 } 138 139 public void moveNode(long id, double lat, double lon) { 140 nodes.put(id, new Coord(lat, lon)); 86 141 } 87 142 … … 110 165 } 111 166 112 public void tagsDone() { 113 if (feature.type != Obj.UNKOBJ) { 114 if ((feature.flag == Fflag.WAY) && (list.size() > 0) && (list.get(0) == list.get(list.size() - 1))) { 167 public void tagsDone(long id) { 168 if ((feature.type != Obj.UNKOBJ) && !((feature.flag == Fflag.WAY) && (list.size() < 2))) { 169 index.put(id, feature); 170 if ((feature.flag == Fflag.WAY) && (list.size() > 0) && (list.get(0).equals(list.get(list.size() - 1)))) { 115 171 feature.flag = Fflag.AREA; 116 172 } … … 137 193 att = S57att.enumAttribute(subkeys[2], obj); 138 194 } 139 HashMap<Integer, EnumMap<Att, AttItem>>items = feature.objs.get(obj);195 ObjTab items = feature.objs.get(obj); 140 196 if (items == null) { 141 items = new HashMap<Integer, EnumMap<Att, AttItem>>();197 items = new ObjTab(); 142 198 feature.objs.put(obj, items); 143 199 } 144 EnumMap<Att, AttItem>atts = items.get(idx);200 AttMap atts = items.get(idx); 145 201 if (atts == null) { 146 atts = new EnumMap<Att, AttItem>(Att.class);202 atts = new AttMap(); 147 203 items.put(idx, atts); 148 204 } -
applications/editors/josm/plugins/smed2/src/smed2/MapImage.java
r29175 r29184 2 2 3 3 import java.awt.Color; 4 import java.awt.Font; 4 5 import java.awt.Graphics2D; 6 import java.awt.Rectangle; 5 7 import java.awt.geom.Point2D; 6 8 … … 18 20 import seamap.MapHelper; 19 21 import seamap.Renderer; 20 import seamap.SeaMap;21 22 import seamap.SeaMap.Coord; 22 23 23 24 public class MapImage extends ImageryLayer implements ZoomChangeListener, MapHelper { 24 25 25 private S eaMap mapdata;26 private Smed2Action dlg; 26 27 27 28 double top; … … 33 34 int zoom; 34 35 35 public MapImage(ImageryInfo info, S eaMap map) {36 public MapImage(ImageryInfo info, Smed2Action d) { 36 37 super(info); 38 dlg = d; 39 MapView.addZoomChangeListener(this); 37 40 zoomChanged(); 38 MapView.addZoomChangeListener(this);39 mapdata = map;40 41 } 41 42 … … 62 63 @Override 63 64 public void paint(Graphics2D g2, MapView mv, Bounds bb) { 64 g2.setPaint(new Color(0xb5d0d0)); 65 g2.fill(Main.map.mapView.getBounds()); 66 Renderer.reRender(g2, zoom, Math.pow(2, (zoom-12)), mapdata, this); 65 Rectangle rect = Main.map.mapView.getBounds(); 66 g2.setBackground(new Color(0xb5d0d0)); 67 g2.clearRect(rect.x, rect.y, rect.width, rect.height); 68 g2.setPaint(Color.black); 69 g2.setFont(new Font("Arial", Font.BOLD, 20)); 70 g2.drawString(("Z" + zoom), (rect.x + rect.width - 40), (rect.y + rect.height - 10)); 71 Renderer.reRender(g2, zoom, Math.pow(2, (zoom-12)), dlg.map, this); 67 72 } 68 73 -
applications/editors/josm/plugins/smed2/src/smed2/Smed2Action.java
r29175 r29184 23 23 24 24 import panels.PanelMain; 25 import panels.ShowFrame; 25 26 26 27 public class Smed2Action extends JosmAction implements EditLayerChangeListener, SelectionChangedListener { … … 28 29 private static final long serialVersionUID = 1L; 29 30 private static String editor = tr("SeaMap Editor"); 30 public static JFrame frame = null; 31 public static JFrame editFrame = null; 32 public static ShowFrame showFrame = null; 31 33 public static S57dat panelS57; 32 34 private boolean isOpen = false; … … 45 47 @Override 46 48 public void nodeMoved(NodeMovedEvent e) { 47 // reMap(); 49 if (map != null) { 50 Node node = e.getNode(); 51 map.moveNode(node.getUniqueId(), node.getCoor().lat(), node.getCoor().lon()); 52 } 48 53 } 49 54 … … 81 86 public Smed2Action() { 82 87 super(editor, "Smed2", editor, null, true); 83 MapView.addEditLayerChangeListener(this);84 DataSet.addSelectionListener(this);85 88 } 86 89 … … 92 95 createFrame(); 93 96 else 94 frame.toFront();97 editFrame.toFront(); 95 98 isOpen = true; 96 99 } … … 99 102 100 103 protected void createFrame() { 101 frame = new JFrame(editor); 102 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 103 frame.setResizable(true); 104 frame.setAlwaysOnTop(false); 105 106 frame.addWindowListener(new java.awt.event.WindowAdapter() { 104 editFrame = new JFrame(editor); 105 editFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 106 editFrame.addWindowListener(new java.awt.event.WindowAdapter() { 107 107 public void windowClosing(java.awt.event.WindowEvent e) { 108 108 closeDialog(); 109 109 } 110 110 }); 111 frame.setSize(new Dimension(480, 480)); 112 frame.setLocation(100, 200); 113 frame.setAlwaysOnTop(true); 114 frame.setVisible(true); 111 editFrame.setSize(new Dimension(480, 480)); 112 editFrame.setLocation(100, 200); 113 editFrame.setResizable(true); 114 editFrame.setAlwaysOnTop(true); 115 editFrame.setVisible(true); 115 116 panelMain = new PanelMain(); 116 frame.add(panelMain);117 editFrame.add(panelMain); 117 118 panelS57 = new S57dat(); 118 119 panelS57.setVisible(false); 119 frame.add(panelS57); 120 editFrame.add(panelS57); 121 122 showFrame = new ShowFrame("Seamark Inspector"); 123 showFrame.setSize(new Dimension(300, 300)); 124 Rectangle rect = Main.map.mapView.getBounds(); 125 showFrame.setLocation(50, (rect.y + rect.height - 200)); 126 showFrame.setResizable(false); 127 showFrame.setAlwaysOnTop(true); 128 showFrame.setVisible(false); 129 120 130 // System.out.println("hello"); 121 rendering = new MapImage(new ImageryInfo("OpenSeaMap"), map);131 rendering = new MapImage(new ImageryInfo("OpenSeaMap"), this); 122 132 rendering.setBackgroundLayer(true); 123 133 Main.main.addLayer(rendering); 124 reMap(); 134 MapView.addEditLayerChangeListener(this); 135 DataSet.addSelectionListener(this); 136 editLayerChanged(Main.main.getEditLayer(), Main.main.getEditLayer()); 125 137 } 126 138 … … 129 141 Main.main.removeLayer(rendering); 130 142 MapView.removeEditLayerChangeListener(this); 131 frame.setVisible(false);132 frame.dispose();133 //data = null;134 //map = null;143 editFrame.setVisible(false); 144 editFrame.dispose(); 145 data = null; 146 map = null; 135 147 } 136 148 isOpen = false; … … 145 157 newLayer.data.addDataSetListener(dataSetListener); 146 158 data = newLayer.data.allPrimitives(); 147 reMap(); 159 makeMap(); 160 if (rendering != null) rendering.zoomChanged(); 148 161 } else { 149 162 data = null; … … 153 166 154 167 @Override 155 public void selectionChanged(Collection<? extends OsmPrimitive> arg0) { 156 // TODO Auto-generated method stub 157 158 } 159 160 void reMap() { 168 public void selectionChanged(Collection<? extends OsmPrimitive> selection) { 169 Node nextNode = null; 170 Node node = null; 171 172 if (selection.size() == 0) showFrame.setVisible(false); 173 for (OsmPrimitive osm : selection) { 174 if (osm instanceof Node) { 175 nextNode = (Node) osm; 176 if (selection.size() == 1) { 177 if (nextNode.compareTo(node) != 0) { 178 node = nextNode; 179 showFrame.setVisible(true); 180 showFrame.showFeature(node, map); 181 } 182 } else { 183 showFrame.setVisible(false); 184 } 185 } 186 } 187 if (nextNode == null) { 188 node = null; 189 } 190 } 191 192 void makeMap() { 161 193 map = new SeaMap(); 162 194 if (data != null) { … … 174 206 map.addTag(entry.getKey(), entry.getValue()); 175 207 } 176 map.tagsDone( );208 map.tagsDone(osm.getUniqueId()); 177 209 } else if ((osm instanceof Relation) && ((Relation) osm).isMultipolygon()) { 178 210 map.addMpoly(((Relation) osm).getUniqueId());
Note:
See TracChangeset
for help on using the changeset viewer.