* @throws IOException
*/
public MapTile getMapTileChild(int childnumber) throws IOException, SAXException, ParserConfigurationException {
MapTile result = null;
ConnectionList cl = getSubmaptile()[childnumber];
if (cl != null) {
// find the first file connection, ignore the rest
try {
result = new MapTile(getDirectory(), new File(new File(
getFilename()).getParent(), ((ConnectionURL) cl
.getConnections().get(0)).getUrl()).getPath(), defaultType);
result.setDepth(getDepth()+1);
result.setCoordinates(getSubRegion(getCoordinates(), MapTileXML.getSubmaptileConstant(childnumber)));
} catch(IOException e) {
// could not be loaded, create new tile
result = null;
}
}
if (result == null) {
// generate a connection using an unused filename
MapTile newMapTile = new MapTile(defaultType);
newMapTile.setDirectory(getDirectory());
File path = new File(getFilename()).getParentFile();
String spath = null;
if (path == null) {
spath = "";
} else {
spath = path.getPath() + File.separator;
}
newMapTile.setFilename(spath + childnumber + File.separator + "0.mxml");
// ConnectionList newSubmaptileList[] = new ConnectionList[4];
// for(int i=0; i<4; i++) {
// newSubmaptileList[i] = new ConnectionList();
// newSubmaptileList[i].addConnection(new ConnectionURL(new File(newMapTile.getFilename()).getParentFile().getPath() + File.separator + i + File.separator + "0.mxml"));
// }
// newMapTile.setSubmaptile(newSubmaptileList);
newMapTile.setCoordinates(getSubRegion(getCoordinates(), MapTileXML.getSubmaptileConstant(childnumber)));
newMapTile.setDepth(getDepth()+1);
getSubmaptile()[childnumber] = new ConnectionList();
getSubmaptile()[childnumber].addConnection(new ConnectionURL(relativeFilename(getFilename(), newMapTile.getFilename())));
// persist the new map tile
// newMapTile.write(getDirectory());