error(tr("Version ''{0}'' of session file is not supported. Expected: 0.1", version));
}
Element viewportEl = getElementByTagName(root, "viewport");
if (viewportEl != null) {
EastNorth center = null;
Element centerEl = getElementByTagName(viewportEl, "center");
if (centerEl != null && centerEl.hasAttribute("lat") && centerEl.hasAttribute("lon")) {
try {
LatLon centerLL = new LatLon(Double.parseDouble(centerEl.getAttribute("lat")), Double.parseDouble(centerEl.getAttribute("lon")));
center = Projections.project(centerLL);
} catch (NumberFormatException ex) {
Main.warn(ex);
}
}
if (center != null) {
Element scaleEl = getElementByTagName(viewportEl, "scale");
if (scaleEl != null && scaleEl.hasAttribute("meter-per-pixel")) {
try {
double meterPerPixel = Double.parseDouble(scaleEl.getAttribute("meter-per-pixel"));
Projection proj = Main.getProjection();
// Get a "typical" distance in east/north units that
// corresponds to a couple of pixels. Shouldn't be too
// large, to keep it within projection bounds and
// not too small to avoid rounding errors.
double dist = 0.01 * proj.getDefaultZoomInPPD();
LatLon ll1 = proj.eastNorth2latlon(new EastNorth(center.east() - dist, center.north()));
LatLon ll2 = proj.eastNorth2latlon(new EastNorth(center.east() + dist, center.north()));
double meterPerEasting = ll1.greatCircleDistance(ll2) / dist / 2;
double scale = meterPerPixel / meterPerEasting; // unit: easting per pixel
viewport = new ViewportData(center, scale);
} catch (NumberFormatException ex) {
Main.warn(ex);