| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.trergn; |
| 18 |
|
| 19 |
import java.io.IOException; |
| 20 |
import java.io.OutputStream; |
| 21 |
|
| 22 |
import uk.me.parabola.imgfmt.app.Coord; |
| 23 |
import uk.me.parabola.imgfmt.app.ImgFileWriter; |
| 24 |
import uk.me.parabola.imgfmt.app.lbl.POIRecord; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class Point extends MapObject { |
| 36 |
|
| 37 |
private POIRecord poi; |
| 38 |
|
| 39 |
public Point(Subdivision div) { |
| 40 |
setSubdiv(div); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public void write(ImgFileWriter file) { |
| 50 |
boolean hasSubtype = false; |
| 51 |
int type = getType(); |
| 52 |
int subtype = 0; |
| 53 |
if ((type & 0xff) != 0) { |
| 54 |
hasSubtype = true; |
| 55 |
subtype = type & 0xff; |
| 56 |
} |
| 57 |
type >>= 8; |
| 58 |
|
| 59 |
file.put1u(type); |
| 60 |
|
| 61 |
int off = getLabel().getOffset(); |
| 62 |
if (poi != null) { |
| 63 |
off = poi.getOffset(); |
| 64 |
off |= 0x400000; |
| 65 |
} |
| 66 |
if (hasSubtype) |
| 67 |
off |= 0x800000; |
| 68 |
|
| 69 |
file.put3u(off); |
| 70 |
file.put2s(getDeltaLong()); |
| 71 |
file.put2s(getDeltaLat()); |
| 72 |
if (hasSubtype) |
| 73 |
file.put1u(subtype); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public void write(OutputStream stream) throws IOException { |
| 82 |
assert hasExtendedType(); |
| 83 |
int type = getType(); |
| 84 |
int labelOff = getLabel().getOffset(); |
| 85 |
byte[] extraBytes = getExtTypeExtraBytes(); |
| 86 |
|
| 87 |
if (poi != null) { |
| 88 |
labelOff = poi.getOffset(); |
| 89 |
labelOff |= 0x400000; |
| 90 |
} |
| 91 |
if(labelOff != 0) |
| 92 |
type |= 0x20; |
| 93 |
if(extraBytes != null) |
| 94 |
type |= 0x80; |
| 95 |
stream.write(type >> 8); |
| 96 |
stream.write(type); |
| 97 |
|
| 98 |
int deltaLong = getDeltaLong(); |
| 99 |
int deltaLat = getDeltaLat(); |
| 100 |
stream.write(deltaLong); |
| 101 |
stream.write(deltaLong >> 8); |
| 102 |
stream.write(deltaLat); |
| 103 |
stream.write(deltaLat >> 8); |
| 104 |
|
| 105 |
if(labelOff != 0) { |
| 106 |
stream.write(labelOff); |
| 107 |
stream.write(labelOff >> 8); |
| 108 |
stream.write(labelOff >> 16); |
| 109 |
} |
| 110 |
|
| 111 |
if(extraBytes != null) |
| 112 |
stream.write(extraBytes); |
| 113 |
} |
| 114 |
|
| 115 |
public void setPOIRecord(POIRecord poirecord) { |
| 116 |
this.poi = poirecord; |
| 117 |
} |
| 118 |
|
| 119 |
public POIRecord getPOIRecord() { |
| 120 |
if (poi == null) |
| 121 |
return new POIRecord(); |
| 122 |
return poi; |
| 123 |
} |
| 124 |
|
| 125 |
public Coord getLocation() { |
| 126 |
int shift = getSubdiv().getShift(); |
| 127 |
return new Coord(getSubdiv().getLatitude() + (getDeltaLat() << shift), |
| 128 |
getSubdiv().getLongitude() + (getDeltaLong() << shift)); |
| 129 |
} |
| 130 |
} |