Debian Codegraph @

src/uk/me/parabola/tdbfmt/OverviewMapBlock.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: 23-Sep-2007
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 * The overview map provides a low-detail image for the detailed maps. It
28 * allows you to see what areas the detail maps cover so they can be selected
29 * in programs such as QLandkarte and Garmin's MapSource.
30 *
31 * In addition to a low detail map, the overview map contains a number of type
32 * 0x4a polygons. These definition areas a labeled after and correspond to
33 * the detail map img files.
34 *
35 * The detail maps contain a background polygon (type 0x4b) that matches the
36 * definition area in the overview map.
37 *
38 * @author Steve Ratcliffe
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 }