Changeset 29152 in osm
- Timestamp:
- 2013-01-01T16:08:15+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/smed2/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/s57/S57val.java
r29150 r29152 27 27 28 28 public static class AttVal { 29 Att att; 30 Conv conv; 31 Object val; 29 public Att att; 30 public Conv conv; 31 public Object val; 32 32 AttVal(Att a, Conv c, Object v) { 33 33 att = a; conv = c; val = v; -
applications/editors/josm/plugins/smed2/src/seamap/Map.java
r29151 r29152 14 14 import java.util.HashMap; 15 15 16 import s57.S57att.Att; 17 import s57.S57obj.Obj; 18 import s57.S57val.Conv; 16 import s57.S57att; 17 import s57.S57att.*; 18 import s57.S57obj; 19 import s57.S57obj.*; 20 import s57.S57val; 21 import s57.S57val.*; 19 22 20 23 public class Map { 21 24 22 public enum Fflag { NODE, WAY, AREA } 25 public enum Fflag { 26 UNKN, NODE, WAY, AREA 27 } 23 28 24 29 public class AttItem { 25 30 Conv conv; 26 31 Object val; 27 }28 32 29 public class ObjItem { 30 int idx; 31 ArrayList<EnumMap<Att, AttItem>> atts; 33 AttItem(Conv iconv, Object ival) { 34 conv = iconv; 35 val = ival; 36 } 32 37 } 33 38 … … 38 43 public Obj type; 39 44 public EnumMap<Att, AttItem> atts; 40 public EnumMap<Obj, ArrayList<ObjItem>> objs; 45 public EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>> objs; 46 47 Feature() { 48 clean(); 49 } 50 51 void clean() { 52 id = 0; 53 flag = Fflag.UNKN; 54 refs = new ArrayList<Long>(); 55 type = Obj.UNKOBJ; 56 atts = new EnumMap<Att, AttItem>(Att.class); 57 objs = new EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>>(Obj.class); 58 } 41 59 } 42 60 43 61 public class Coord { 44 62 double lat; 45 63 double lon; 46 Coord (double ilat, double ilon) { 64 65 Coord(double ilat, double ilon) { 47 66 lat = ilat; 48 67 lon = ilon; 49 68 } 50 69 } 51 70 52 71 public HashMap<Long, Coord> nodes; 53 72 public HashMap<Long, ArrayList<Long>> ways; 54 73 public HashMap<Long, ArrayList<Long>> mpolys; 55 74 public ArrayList<Feature> features; 56 57 public Map () { 75 76 private Feature feature; 77 78 public Map() { 58 79 nodes = new HashMap<Long, Coord>(); 59 80 ways = new HashMap<Long, ArrayList<Long>>(); 60 81 mpolys = new HashMap<Long, ArrayList<Long>>(); 82 feature = new Feature(); 61 83 features = new ArrayList<Feature>(); 84 features.add(feature); 62 85 } 63 86 64 87 public void addNode(long id, double lat, double lon) { 65 88 nodes.put(id, new Coord(lat, lon)); 89 if (feature.type == Obj.UNKOBJ) { 90 feature.clean(); 91 } else { 92 feature = new Feature(); 93 features.add(feature); 94 } 66 95 } 67 96 68 97 public void addWay(long id) { 69 98 ways.put(id, new ArrayList<Long>()); 99 if (feature.type == Obj.UNKOBJ) { 100 feature.clean(); 101 } else { 102 feature = new Feature(); 103 features.add(feature); 104 } 70 105 } 71 106 72 107 public void addToWay(long way, long node) { 73 108 ways.get(way).add(node); 74 109 } 75 public void addRelation(long id) { 110 111 public void addMpoly(long id) { 76 112 mpolys.put(id, new ArrayList<Long>()); 77 113 } 78 79 public void addToRelation(long rel, long way) { 80 mpolys.get(rel).add(way); 114 115 public void addToMpoly(long id, long way) { 116 mpolys.get(id).add(way); 117 } 118 119 public void addTag(String key, String val) { 120 String subkeys[] = key.split(":"); 121 if ((subkeys.length > 1) && subkeys[0].equals("seamark")) { 122 Obj obj = S57obj.enumType(subkeys[1]); 123 if ((subkeys.length > 2) && (obj != Obj.UNKOBJ)) { 124 int idx = 0; 125 Att att = Att.UNKATT; 126 try { 127 idx = Integer.parseInt(subkeys[2]); 128 if (subkeys.length == 4) { 129 att = s57.S57att.enumAttribute(subkeys[3], obj); 130 } 131 } catch (Exception e) { 132 att = S57att.enumAttribute(subkeys[2], obj); 133 } 134 HashMap<Integer, EnumMap<Att, AttItem>> items = feature.objs.get(obj); 135 if (items == null) { 136 items = new HashMap<Integer, EnumMap<Att, AttItem>>(); 137 feature.objs.put(obj, items); 138 } 139 EnumMap<Att, AttItem> atts = items.get(idx); 140 if (atts == null) { 141 atts = new EnumMap<Att, AttItem>(Att.class); 142 } 143 AttVal attval = S57val.convertValue(val, att); 144 atts.put(att, new AttItem(attval.conv, attval.val)); 145 } else { 146 if (subkeys[1].equals("type")) { 147 feature.type = S57obj.enumType(val); 148 } else { 149 Att att = S57att.enumAttribute(subkeys[1], Obj.UNKOBJ); 150 if (att != Att.UNKATT) { 151 AttVal attval = S57val.convertValue(val, att); 152 feature.atts.put(att, new AttItem(attval.conv, attval.val)); 153 } 154 } 155 } 156 } 81 157 } 82 158 } -
applications/editors/josm/plugins/smed2/src/smed2/Smed2Action.java
r29151 r29152 1 1 package smed2; 2 2 3 import java.awt.Dimension; 4 import java.awt.event.ActionEvent; 5 import java.util.Collection; 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.util.*; 6 import java.util.Map.Entry; 6 7 7 import javax.swing.JFrame; 8 import javax.swing.SwingUtilities; 9 import javax.swing.WindowConstants; 8 import javax.swing.*; 10 9 11 10 import static org.openstreetmap.josm.tools.I18n.tr; … … 17 16 import org.openstreetmap.josm.data.SelectionChangedListener; 18 17 import org.openstreetmap.josm.data.imagery.ImageryInfo; 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 23 import org.openstreetmap.josm.data.osm.event.DataChangedEvent; 24 import org.openstreetmap.josm.data.osm.event.DataSetListener; 25 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 26 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 27 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent; 28 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent; 29 import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent; 30 import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent; 31 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 32 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 18 import org.openstreetmap.josm.data.osm.*; 19 import org.openstreetmap.josm.data.osm.event.*; 33 20 import org.openstreetmap.josm.Main; 34 21 35 22 import s57.S57dat; 23 import seamap.Map; 36 24 37 25 import panels.PanelMain; … … 46 34 public static PanelMain panelMain = null; 47 35 public ImageryLayer rendering; 36 public Map map = null; 48 37 public Collection<OsmPrimitive> data = null; 49 38 … … 130 119 panelS57.setVisible(false); 131 120 frame.add(panelS57); 132 System.out.println("hello"); 121 // System.out.println("hello"); 133 122 rendering = ImageryLayer.create(new ImageryInfo("OpenSeaMap")); 134 123 Main.main.addLayer(rendering); … … 140 129 frame.setVisible(false); 141 130 frame.dispose(); 131 data = null; 132 map = null; 142 133 } 143 134 isOpen = false; … … 146 137 @Override 147 138 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 148 System.out.println(newLayer);149 139 if (oldLayer != null) { 150 140 oldLayer.data.removeDataSetListener(dataSetListener); 151 141 } 152 153 142 if (newLayer != null) { 154 143 newLayer.data.addDataSetListener(dataSetListener); 155 144 data = newLayer.data.allPrimitives(); 156 } else { 145 map = new Map(); 146 for (OsmPrimitive osm : data) { 147 if (osm instanceof Node) { 148 map.addNode(((Node)osm).getId(), ((Node)osm).getCoor().lat(), ((Node)osm).getCoor().lon()); 149 } else if (osm instanceof Way) { 150 map.addWay(((Way)osm).getId()); 151 } 152 for (Entry<String, String> entry : osm.getKeys().entrySet()) { 153 map.addTag(entry.getKey(), entry.getValue()); 154 } 155 } 156 } else { 157 157 data = null; 158 map = null; 158 159 } 159 160 }
Note:
See TracChangeset
for help on using the changeset viewer.