Changeset 29272 in osm for applications/editors/josm
- Timestamp:
- 2013-02-21T21:01:44+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/smed2/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java
r29271 r29272 201 201 202 202 public boolean hasNext() { 203 return (edge != null) && ((it == null) || ( forward && it.hasNext()) || (!forward && it.hasPrevious()));203 return (edge != null) && ((it == null) || (edge.nodes.isEmpty()) || (forward && it.hasNext()) || (!forward && it.hasPrevious())); 204 204 } 205 205 … … 371 371 372 372 public void tagsDone(long id) { 373 if ((feature.type != Obj.UNKOBJ) && !((edge != null) && (edge.last == 0))) {374 index.put(id, feature);375 if (features.get(feature.type) == null) {376 features.put(feature.type, new ArrayList<Feature>());377 }378 features.get(feature.type).add(feature);379 }380 373 switch (feature.flag) { 381 374 case POINT: … … 432 425 break; 433 426 } 434 feature.centre = findCentroid(feature); 427 if ((feature.type != Obj.UNKOBJ) && !((edge != null) && (edge.last == 0))) { 428 index.put(id, feature); 429 if (features.get(feature.type) == null) { 430 features.put(feature.type, new ArrayList<Feature>()); 431 } 432 feature.centre = findCentroid(feature); 433 features.get(feature.type).add(feature); 434 } 435 435 } 436 436 … … 461 461 462 462 public Snode findCentroid(Feature feature) { 463 double lat, lon, slat, slon, sarc, llat, llon; 464 lat = lon = slat = slon = sarc = llat = llon = 0; 463 double lat, lon, slat, slon, llat, llon; 464 llat = llon = lat = lon = slat = slon = 0; 465 double sarc = 0; 466 boolean first = true; 465 467 switch (feature.flag) { 466 468 case POINT: … … 473 475 lat = node.lat; 474 476 lon = node.lon; 475 sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 477 if (first) { 478 first = false; 479 } else { 480 sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 481 } 476 482 llat = lat; 477 483 llon = lon; … … 479 485 double harc = sarc / 2; 480 486 sarc = 0; 487 first = true; 481 488 eit = new EdgeIterator(edge, true); 482 489 while (eit.hasNext()) { … … 484 491 lat = node.lat; 485 492 lon = node.lon; 486 sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 487 if (sarc > harc) 488 break; 493 if (first) { 494 first = false; 495 } else { 496 sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 497 if (sarc > harc) 498 break; 499 } 489 500 harc -= sarc; 490 501 llat = lat; … … 497 508 BoundIterator bit = new BoundIterator(bound); 498 509 while (bit.hasNext()) { 499 llon = lon;500 llat = lat;501 510 Snode node = bit.next(); 502 511 lat = node.lat; 503 512 lon = node.lon; 504 double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 505 slat += (lat * arc); 506 slon += (lon * arc); 507 sarc += arc; 513 if (first) { 514 first = false; 515 } else { 516 double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat))); 517 slat += (lat * arc); 518 slon += (lon * arc); 519 sarc += arc; 520 } 521 llon = lon; 522 llat = lat; 508 523 } 509 524 return new Snode((sarc > 0.0 ? slat / sarc : 0.0), (sarc > 0.0 ? slon / sarc : 0.0)); -
applications/editors/josm/plugins/smed2/src/smed2/Smed2Action.java
r29266 r29272 35 35 public MapImage rendering; 36 36 public SeaMap map = null; 37 public Collection<OsmPrimitive>data = null;37 public DataSet data = null; 38 38 39 39 private final DataSetListener dataSetListener = new DataSetListener() { … … 46 46 @Override 47 47 public void nodeMoved(NodeMovedEvent e) { 48 if (map != null) { 49 makeMap(); 50 } 48 System.out.println("NodeMovedEvent"); 51 49 } 52 50 … … 154 152 if (newLayer != null) { 155 153 newLayer.data.addDataSetListener(dataSetListener); 156 data = newLayer.data .allPrimitives();154 data = newLayer.data; 157 155 makeMap(); 158 156 if (rendering != null) rendering.zoomChanged(); … … 205 203 map = new SeaMap(); 206 204 if (data != null) { 207 for (OsmPrimitive osm : data) { 208 if (osm instanceof Node) { 209 map.addNode(((Node) osm).getUniqueId(), ((Node) osm).getCoor().lat(), ((Node) osm).getCoor().lon()); 210 } else if (osm instanceof Way) { 211 map.addEdge(((Way) osm).getUniqueId()); 212 for (Node node : ((Way) osm).getNodes()) { 213 map.addToEdge((node.getUniqueId())); 214 } 215 } else if ((osm instanceof Relation) && ((Relation) osm).isMultipolygon()) { 216 map.addArea(((Relation) osm).getUniqueId()); 217 for (RelationMember mem : ((Relation) osm).getMembers()) { 205 for (Node node : data.getNodes()) { 206 map.addNode(node.getUniqueId(), node.getCoor().lat(), node.getCoor().lon()); 207 for (Entry<String, String> entry : node.getKeys().entrySet()) { 208 map.addTag(entry.getKey(), entry.getValue()); 209 } 210 map.tagsDone(node.getUniqueId()); 211 } 212 for (Way way : data.getWays()) { 213 map.addEdge(way.getUniqueId()); 214 for (Node node : way.getNodes()) { 215 map.addToEdge((node.getUniqueId())); 216 } 217 for (Entry<String, String> entry : way.getKeys().entrySet()) { 218 map.addTag(entry.getKey(), entry.getValue()); 219 } 220 map.tagsDone(way.getUniqueId()); 221 } 222 for (Relation rel : data.getRelations()) { 223 if (rel.isMultipolygon()) { 224 map.addArea(rel.getUniqueId()); 225 for (RelationMember mem : rel.getMembers()) { 218 226 if (mem.getType() == OsmPrimitiveType.WAY) 219 227 map.addToArea(mem.getUniqueId(), (mem.getRole().equals("outer"))); 220 228 } 221 229 } 222 for (Entry<String, String> entry : osm.getKeys().entrySet()) {230 for (Entry<String, String> entry : rel.getKeys().entrySet()) { 223 231 map.addTag(entry.getKey(), entry.getValue()); 224 232 } 225 map.tagsDone( osm.getUniqueId());233 map.tagsDone(rel.getUniqueId()); 226 234 } 227 235 }
Note:
See TracChangeset
for help on using the changeset viewer.