Ignore:
Timestamp:
2013-03-19T20:46:10+01:00 (11 years ago)
Author:
zverik
Message:

another iteration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/CalibrationObject.java

    r29371 r29376  
    22
    33import java.util.Map;
    4 import org.openstreetmap.josm.data.osm.*;
     4import org.openstreetmap.josm.data.coor.LatLon;
     5import org.openstreetmap.josm.data.osm.Node;
     6import org.openstreetmap.josm.data.osm.OsmPrimitive;
     7import org.openstreetmap.josm.data.osm.Way;
    58
    69/**
     
    912 */
    1013public class CalibrationObject extends ImageryOffsetBase {
    11     private OsmPrimitive object;
    12     private long lastUserId;
     14    private LatLon[] geometry;
    1315
    14     public CalibrationObject(OsmPrimitive object, long lastUserId) {
    15         this.object = object;
    16         this.lastUserId = lastUserId;
     16    public CalibrationObject(LatLon[] geometry) {
     17        this.geometry = geometry;
    1718    }
    1819
    19     public CalibrationObject(OsmPrimitive object) {
    20         this(object, 0);
     20    public CalibrationObject( OsmPrimitive p ) {
     21        if( p instanceof Node )
     22            geometry = new LatLon[] { ((Node)p).getCoor() };
     23        else if( p instanceof Way ) {
     24            geometry = new LatLon[((Way)p).getNodesCount()];
     25            for( int i = 0; i < geometry.length; i++ )
     26                geometry[i] = ((Way)p).getNode(i).getCoor();
     27        } else
     28            throw new IllegalArgumentException("Calibration Object can be created either from node or a way");
    2129    }
    2230
    23     public long getLastUserId() {
    24         return lastUserId;
     31    public LatLon[] getGeometry() {
     32        return geometry;
    2533    }
    2634
    27     public OsmPrimitive getObject() {
    28         return object;
    29     }
    30    
    3135    @Override
    3236    public void putServerParams( Map<String, String> map ) {
    3337        super.putServerParams(map);
    34         map.put("object", object instanceof Node ? "node" : "way");
    35         map.put("id", String.valueOf(object.getId()));
     38        StringBuilder sb = new StringBuilder();
     39        for( int i = 0; i < geometry.length; i++ ) {
     40            if( i > 0 )
     41                sb.append(',');
     42            sb.append(geometry[i].lon()).append(' ').append(geometry[i].lat());
     43        }
     44        map.put("geometry", sb.toString());
    3645    }
    3746
    3847    @Override
    3948    public String toString() {
    40         return "CalibrationObject{" + "object=" + object + ", lastUserId=" + lastUserId + "position=" + position + ", date=" + date + ", author=" + author + ", description=" + description + ", abandonDate=" + abandonDate + '}';
     49        return "CalibrationObject{" + geometry.length + "nodes; position=" + position + ", date=" + date + ", author=" + author + ", description=" + description + ", abandonDate=" + abandonDate + '}';
    4150    }
    4251}
Note: See TracChangeset for help on using the changeset viewer.