| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.tdbfmt; |
| 18 |
|
| 19 |
import java.io.IOException; |
| 20 |
|
| 21 |
import uk.me.parabola.imgfmt.app.Area; |
| 22 |
import uk.me.parabola.io.FileBlock; |
| 23 |
import uk.me.parabola.io.StructuredInputStream; |
| 24 |
import uk.me.parabola.io.StructuredOutputStream; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class OverviewMapBlock extends FileBlock { |
| 41 |
public static final int BLOCK_ID = 0x42; |
| 42 |
|
| 43 |
|
| 44 |
private int mapNumber; |
| 45 |
private int parentMapNumber; |
| 46 |
|
| 47 |
private String description; |
| 48 |
|
| 49 |
private int maxLat; |
| 50 |
private int maxLong; |
| 51 |
private int minLat; |
| 52 |
private int minLong; |
| 53 |
|
| 54 |
public OverviewMapBlock() { |
| 55 |
super(BLOCK_ID); |
| 56 |
description = "overview map"; |
| 57 |
} |
| 58 |
|
| 59 |
protected OverviewMapBlock(int blockId) { |
| 60 |
super(blockId); |
| 61 |
} |
| 62 |
|
| 63 |
public OverviewMapBlock(StructuredInputStream ds) throws IOException { |
| 64 |
super(BLOCK_ID); |
| 65 |
|
| 66 |
mapNumber = ds.read4(); |
| 67 |
parentMapNumber = ds.read4(); |
| 68 |
|
| 69 |
maxLat = ds.read4(); |
| 70 |
maxLong = ds.read4(); |
| 71 |
minLat = ds.read4(); |
| 72 |
minLong = ds.read4(); |
| 73 |
|
| 74 |
description = ds.readString(); |
| 75 |
} |
| 76 |
|
| 77 |
public void writeBody(StructuredOutputStream os) throws IOException { |
| 78 |
os.write4(mapNumber); |
| 79 |
os.write4(parentMapNumber); |
| 80 |
os.write4(maxLat); |
| 81 |
os.write4(maxLong); |
| 82 |
os.write4(minLat); |
| 83 |
os.write4(minLong); |
| 84 |
os.writeString(description); |
| 85 |
} |
| 86 |
|
| 87 |
public String toString() { |
| 88 |
return "Overview: " |
| 89 |
+ mapNumber |
| 90 |
+ ", parent=" |
| 91 |
+ parentMapNumber |
| 92 |
+ " covers " |
| 93 |
+ '(' + toDegrees(minLat) + ',' + toDegrees(minLong) + ')' |
| 94 |
+ '(' + toDegrees(maxLat) + ',' + toDegrees(maxLong) + ')' |
| 95 |
+ " : " |
| 96 |
+ description |
| 97 |
; |
| 98 |
} |
| 99 |
|
| 100 |
private double toDegrees(int tdbunits) { |
| 101 |
return (double) tdbunits * 360 / Math.pow(2, 32); |
| 102 |
} |
| 103 |
|
| 104 |
public void setArea(Area bounds) { |
| 105 |
minLat = bounds.getMinLat() << 8; |
| 106 |
minLong = bounds.getMinLong() << 8; |
| 107 |
maxLat = bounds.getMaxLat() << 8; |
| 108 |
maxLong = bounds.getMaxLong() << 8; |
| 109 |
} |
| 110 |
|
| 111 |
public void setDescription(String description) { |
| 112 |
this.description = description; |
| 113 |
} |
| 114 |
|
| 115 |
public void setMapName(String mapName) { |
| 116 |
try { |
| 117 |
this.mapNumber = Integer.parseInt(mapName); |
| 118 |
} catch (NumberFormatException e) { |
| 119 |
this.mapNumber = 0; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
public void setParentMapNumber(int parentMapNumber) { |
| 124 |
this.parentMapNumber = parentMapNumber; |
| 125 |
} |
| 126 |
} |