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);