| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.map; |
| 18 |
|
| 19 |
import uk.me.parabola.imgfmt.FileExistsException; |
| 20 |
import uk.me.parabola.imgfmt.FileNotWritableException; |
| 21 |
import uk.me.parabola.imgfmt.FileSystemParam; |
| 22 |
import uk.me.parabola.imgfmt.Utils; |
| 23 |
import uk.me.parabola.imgfmt.app.Area; |
| 24 |
import uk.me.parabola.imgfmt.app.Label; |
| 25 |
import uk.me.parabola.imgfmt.app.dem.DEMFile; |
| 26 |
import uk.me.parabola.imgfmt.app.labelenc.CodeFunctions; |
| 27 |
import uk.me.parabola.imgfmt.app.lbl.LBLFile; |
| 28 |
import uk.me.parabola.imgfmt.app.net.NETFile; |
| 29 |
import uk.me.parabola.imgfmt.app.net.NODFile; |
| 30 |
import uk.me.parabola.imgfmt.app.srt.Sort; |
| 31 |
import uk.me.parabola.imgfmt.app.trergn.InternalFiles; |
| 32 |
import uk.me.parabola.imgfmt.app.trergn.MapObject; |
| 33 |
import uk.me.parabola.imgfmt.app.trergn.PointOverview; |
| 34 |
import uk.me.parabola.imgfmt.app.trergn.PolygonOverview; |
| 35 |
import uk.me.parabola.imgfmt.app.trergn.PolylineOverview; |
| 36 |
import uk.me.parabola.imgfmt.app.trergn.RGNFile; |
| 37 |
import uk.me.parabola.imgfmt.app.trergn.Subdivision; |
| 38 |
import uk.me.parabola.imgfmt.app.trergn.TREFile; |
| 39 |
import uk.me.parabola.imgfmt.app.trergn.Zoom; |
| 40 |
import uk.me.parabola.imgfmt.fs.FileSystem; |
| 41 |
import uk.me.parabola.imgfmt.sys.ImgFS; |
| 42 |
import uk.me.parabola.log.Logger; |
| 43 |
import uk.me.parabola.mkgmap.combiners.OverviewBuilder; |
| 44 |
import uk.me.parabola.util.Configurable; |
| 45 |
import uk.me.parabola.util.EnhancedProperties; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public class Map implements InternalFiles, Configurable { |
| 61 |
private static final Logger log = Logger.getLogger(Map.class); |
| 62 |
private String filename; |
| 63 |
private String mapName; |
| 64 |
private int mapId; |
| 65 |
private FileSystem fileSystem; |
| 66 |
|
| 67 |
private TREFile treFile; |
| 68 |
private RGNFile rgnFile; |
| 69 |
private LBLFile lblFile; |
| 70 |
private NETFile netFile; |
| 71 |
private NODFile nodFile; |
| 72 |
private DEMFile demFile; |
| 73 |
private boolean isOverviewCombined; |
| 74 |
|
| 75 |
|
| 76 |
private Map() { |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public static Map createMap(String mapname, String outputdir, FileSystemParam params, String mapnumber, Sort sort, boolean overviewCombined) |
| 94 |
throws FileExistsException, FileNotWritableException |
| 95 |
{ |
| 96 |
Map m = new Map(); |
| 97 |
m.mapName = mapname; |
| 98 |
String outFilename = Utils.joinPath(outputdir, mapname, "img"); |
| 99 |
|
| 100 |
FileSystem fs = ImgFS.createFs(outFilename, params); |
| 101 |
m.filename = outFilename; |
| 102 |
m.fileSystem = fs; |
| 103 |
|
| 104 |
m.rgnFile = new RGNFile(m.fileSystem.create(mapnumber + ".RGN")); |
| 105 |
m.treFile = new TREFile(m.fileSystem.create(mapnumber + ".TRE")); |
| 106 |
m.lblFile = new LBLFile(m.fileSystem.create(mapnumber + ".LBL"), sort); |
| 107 |
m.isOverviewCombined = overviewCombined; |
| 108 |
|
| 109 |
int mapid; |
| 110 |
try { |
| 111 |
mapid = Integer.parseInt(mapnumber); |
| 112 |
} catch (NumberFormatException e) { |
| 113 |
mapid = 0; |
| 114 |
} |
| 115 |
m.mapId = mapid; |
| 116 |
m.treFile.setMapId(mapid); |
| 117 |
m.fileSystem = fs; |
| 118 |
|
| 119 |
return m; |
| 120 |
} |
| 121 |
|
| 122 |
public void config(EnhancedProperties props) { |
| 123 |
boolean isOverviewComponent = OverviewBuilder.isOverviewImg(mapName); |
| 124 |
|
| 125 |
if (!isOverviewComponent && !isOverviewCombined) { |
| 126 |
try { |
| 127 |
if (props.containsKey("route") || props.containsKey("net") || props.containsKey("housenumbers")) { |
| 128 |
addNet(); |
| 129 |
} |
| 130 |
if (props.containsKey("route")) { |
| 131 |
addNod(); |
| 132 |
} |
| 133 |
} catch (FileExistsException e) { |
| 134 |
log.warn("Could not add NET and/or NOD sections"); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
treFile.config(props); |
| 139 |
} |
| 140 |
if (!isOverviewComponent && (!isOverviewCombined || props.containsKey("overview-dem-dist"))) { |
| 141 |
|
| 142 |
if (props.containsKey("dem")) { |
| 143 |
try { |
| 144 |
addDem(); |
| 145 |
} catch (FileExistsException e) { |
| 146 |
log.warn("Could not add DEM section"); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
private void addNet() throws FileExistsException { |
| 153 |
netFile = new NETFile(fileSystem.create(mapName + ".NET")); |
| 154 |
} |
| 155 |
|
| 156 |
private void addNod() throws FileExistsException { |
| 157 |
nodFile = new NODFile(fileSystem.create(mapName + ".NOD"), true); |
| 158 |
} |
| 159 |
|
| 160 |
private void addDem() throws FileExistsException { |
| 161 |
demFile = new DEMFile(fileSystem.create(mapId + ".DEM"), true); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public void setBounds(Area area) { |
| 170 |
treFile.setBounds(area); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public void addCopyright(String str) { |
| 179 |
Label cpy = lblFile.newLabel(str, false); |
| 180 |
treFile.addCopyright(cpy); |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public void addInfo(String msg) { |
| 193 |
int codePage = lblFile.getCodePage(); |
| 194 |
CodeFunctions functions = CodeFunctions.createEncoderForLBL(0, codePage); |
| 195 |
treFile.addInfo(functions.getEncoder().encodeText(msg)); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
public Zoom createZoom(int level, int bits) { |
| 212 |
return treFile.createZoom(level, bits); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
public Subdivision topLevelSubdivision(Area area, Zoom zoom) { |
| 225 |
zoom.setInherited(true); |
| 226 |
|
| 227 |
InternalFiles ifiles = this; |
| 228 |
Subdivision sub = Subdivision.topLevelSubdivision(ifiles, area, zoom); |
| 229 |
rgnFile.startDivision(sub); |
| 230 |
return sub; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
public Subdivision createSubdivision(Subdivision parent, Area area, Zoom zoom) |
| 247 |
{ |
| 248 |
log.debug("creating division"); |
| 249 |
return parent.createSubdivision(this, area, zoom); |
| 250 |
} |
| 251 |
|
| 252 |
public void addPointOverview(PointOverview ov) { |
| 253 |
treFile.addPointOverview(ov); |
| 254 |
} |
| 255 |
|
| 256 |
public void addPolylineOverview(PolylineOverview ov) { |
| 257 |
treFile.addPolylineOverview(ov); |
| 258 |
} |
| 259 |
|
| 260 |
public void addPolygonOverview(PolygonOverview ov) { |
| 261 |
treFile.addPolygonOverview(ov); |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public void addPoiDisplayFlags(int flags) { |
| 269 |
treFile.addPoiDisplayFlags(flags); |
| 270 |
} |
| 271 |
|
| 272 |
public void addMapObject(MapObject item) { |
| 273 |
rgnFile.addMapObject(item); |
| 274 |
} |
| 275 |
|
| 276 |
public void setSort(Sort sort) { |
| 277 |
lblFile.setSort(sort); |
| 278 |
if (netFile != null) |
| 279 |
netFile.setSort(sort); |
| 280 |
} |
| 281 |
|
| 282 |
public void setLabelCharset(String desc, boolean forceUpper) { |
| 283 |
lblFile.setCharacterType(desc, forceUpper); |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public void close() { |
| 292 |
fileSystem.close(); |
| 293 |
} |
| 294 |
|
| 295 |
public String getFilename() { |
| 296 |
return filename; |
| 297 |
} |
| 298 |
|
| 299 |
public RGNFile getRgnFile() { |
| 300 |
return rgnFile; |
| 301 |
} |
| 302 |
|
| 303 |
public LBLFile getLblFile() { |
| 304 |
return lblFile; |
| 305 |
} |
| 306 |
|
| 307 |
public TREFile getTreFile() { |
| 308 |
return treFile; |
| 309 |
} |
| 310 |
|
| 311 |
public NETFile getNetFile() { |
| 312 |
return netFile; |
| 313 |
} |
| 314 |
|
| 315 |
public NODFile getNodFile() { |
| 316 |
return nodFile; |
| 317 |
} |
| 318 |
|
| 319 |
public DEMFile getDemFile() { |
| 320 |
return demFile; |
| 321 |
} |
| 322 |
} |