Changeset 19532 in osm for applications/editors/josm/plugins/routes/src/org
- Timestamp:
- 2010-01-15T21:42:20+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/PathBuilder.java
r17380 r19532 14 14 public class PathBuilder { 15 15 16 private Map<Way, BitSet> wayRoutes = new HashMap<Way, BitSet>(); 16 private Map<Way, BitSet> wayRoutes = new HashMap<Way, BitSet>(); 17 private Collection<ConvertedWay> convertedWays; 17 18 18 19 public void addWay(Way way, RouteDefinition route) { … … 30 31 31 32 public Collection<ConvertedWay> getConvertedWays() { 32 Map<WayEnd, ConvertedWay> ways = new HashMap<WayEnd, ConvertedWay>(); 33 if (convertedWays == null) { 34 Map<WayEnd, ConvertedWay> ways = new HashMap<WayEnd, ConvertedWay>(); 33 35 34 for (Entry<Way, BitSet> wayEntry:wayRoutes.entrySet()) {35 ConvertedWay way = new ConvertedWay(wayEntry.getValue(), wayEntry.getKey());36 for (Entry<Way, BitSet> wayEntry:wayRoutes.entrySet()) { 37 ConvertedWay way = new ConvertedWay(wayEntry.getValue(), wayEntry.getKey()); 36 38 37 ConvertedWay wayBefore = ways.get(way.getStart());38 ConvertedWay wayAfter = ways.get(way.getStop());39 ConvertedWay wayBefore = ways.get(way.getStart()); 40 ConvertedWay wayAfter = ways.get(way.getStop()); 39 41 40 if (wayBefore != null) {41 removeWay(ways, wayBefore);42 way.connect(wayBefore);43 }42 if (wayBefore != null) { 43 removeWay(ways, wayBefore); 44 way.connect(wayBefore); 45 } 44 46 45 if (wayAfter != null) { 46 removeWay(ways, wayAfter); 47 way.connect(wayAfter); 47 if (wayAfter != null) { 48 removeWay(ways, wayAfter); 49 way.connect(wayAfter); 50 } 51 52 ways.put(way.getStart(), way); 53 ways.put(way.getStop(), way); 48 54 } 49 55 50 ways.put(way.getStart(), way); 51 ways.put(way.getStop(), way); 56 Set<ConvertedWay> uniqueWays = new HashSet<ConvertedWay>(); 57 uniqueWays.addAll(ways.values()); 58 convertedWays = uniqueWays; 52 59 } 53 54 Set<ConvertedWay> uniqueWays = new HashSet<ConvertedWay>(); 55 uniqueWays.addAll(ways.values()); 56 return uniqueWays; 60 return convertedWays; 57 61 } 58 62 … … 63 67 64 68 public void clear() { 69 convertedWays = null; 65 70 wayRoutes.clear(); 66 71 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteLayer.java
r18597 r19532 16 16 import org.openstreetmap.josm.data.osm.RelationMember; 17 17 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 19 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 20 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 21 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 18 22 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 19 23 import org.openstreetmap.josm.gui.MapView; … … 27 31 import org.openstreetmap.josm.tools.ImageProvider; 28 32 29 public class RouteLayer extends Layer {33 public class RouteLayer extends Layer implements DataSetListenerAdapter.Listener { 30 34 31 35 private final PathPainter pathPainter; 32 36 private final PathBuilder pathBuilder = new PathBuilder(); 33 37 private final List<RouteDefinition> routes = new ArrayList<RouteDefinition>(); 38 private volatile boolean datasetChanged = true; 34 39 35 40 public RouteLayer(RoutesXMLLayer xmlLayer) { … … 53 58 pathPainter = new NarrowLinePainter(this); 54 59 } 60 61 DatasetEventManager.getInstance().addDatasetListener(new DataSetListenerAdapter(this), FireMode.IMMEDIATELY); 55 62 } 56 63 … … 103 110 } 104 111 105 pathBuilder.clear(); 112 if (datasetChanged) { 113 datasetChanged = false; 114 pathBuilder.clear(); 106 115 107 for (Relation relation:dataset.getRelations()) { 108 for (RouteDefinition route:routes) { 109 if (route.matches(relation)) { 110 addRelation(relation, route); 116 for (Relation relation:dataset.getRelations()) { 117 for (RouteDefinition route:routes) { 118 if (route.matches(relation)) { 119 addRelation(relation, route); 120 } 111 121 } 112 122 } 113 }114 123 115 for (Way way:dataset.getWays()) { 116 for (RouteDefinition route:routes) { 117 if (route.matches(way)) { 118 pathBuilder.addWay(way, route); 124 for (Way way:dataset.getWays()) { 125 for (RouteDefinition route:routes) { 126 if (route.matches(way)) { 127 pathBuilder.addWay(way, route); 128 } 119 129 } 120 130 } … … 128 138 g.setStroke(stroke); 129 139 g.setColor(color); 140 130 141 } 131 142 … … 139 150 } 140 151 152 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 153 datasetChanged = true; 154 } 155 141 156 }
Note:
See TracChangeset
for help on using the changeset viewer.