in archived/SimpleImaging/js/js/scenario1.js [296:403]
function saveHandler() {
WinJS.log && WinJS.log("Updating properties...", "sample", "status");
ImageProperties.title = id("propertiesTitle").value;
// Keywords are stored as an array of strings. Split the textarea text by newlines.
ImageProperties.keywords.clear();
if (id("propertiesKeywords").value !== "") {
var keywordsArray = id("propertiesKeywords").value.split("\n");
keywordsArray.forEach(function (keyword) {
ImageProperties.keywords.append(keyword);
});
}
var properties = new Windows.Foundation.Collections.PropertySet();
// When writing the rating, use the "System.Rating" property key.
// ImageProperties.rating does not handle setting the value to 0 (no stars/unrated).
properties["System.Rating"] = Helpers.convertStarsToSystemRating(
id("propertiesRating").selectedIndex
);
var gpsWriteFailed = false;
var latitude = [
parseInt(id("propertiesLatDeg").value),
parseInt(id("propertiesLatMin").value),
parseFloat(id("propertiesLatSec").value)
];
var longitude = [
parseInt(id("propertiesLongDeg").value),
parseInt(id("propertiesLongMin").value),
parseFloat(id("propertiesLongSec").value)
];
var latitudeRef = id("propertiesLatRef").value.toUpperCase();
var longitudeRef = id("propertiesLongRef").value.toUpperCase();
// Perform some simple validation on the GPS data before storing the values.
if ((latitude[0] >= 0 && latitude[0] <= 90) &&
(latitude[1] >= 0 && latitude[1] <= 60) &&
(latitude[2] >= 0 && latitude[2] <= 60) &&
(latitudeRef === "N" || latitudeRef === "S") &&
(longitude[0] >= 0 && longitude[0] <= 180) &&
(latitude[1] >= 0 && longitude[1] <= 60) &&
(longitude[2] >= 0 && longitude[2] <= 60) &&
(longitudeRef === "E" || longitudeRef === "W")) {
properties["System.GPS.LatitudeRef"] = latitudeRef;
properties["System.GPS.LongitudeRef"] = longitudeRef;
// The Latitude and Longitude properties are read-only. Instead,
// write to System.GPS.LatitudeNumerator, LatitudeDenominator, etc.
// These are length 3 arrays of integers. For simplicity, the
// seconds data is rounded to the nearest 10000th.
var latNum = new Uint32Array([
latitude[0],
latitude[1],
parseInt(latitude[2] * 10000)
]);
var longNum = new Uint32Array([
longitude[0],
longitude[1],
parseInt(longitude[2] * 10000)
]);
var latDen = new Uint32Array([1, 1, 10000]);
var longDen = new Uint32Array([1, 1, 10000]);
properties["System.GPS.LatitudeNumerator"] = latNum;
properties["System.GPS.LongitudeNumerator"] = longNum;
properties["System.GPS.LatitudeDenominator"] = latDen;
properties["System.GPS.LongitudeDenominator"] = longDen;
} else {
gpsWriteFailed = true;
}
ImageProperties.savePropertiesAsync(properties).done(function () {
WinJS.log && WinJS.log(
gpsWriteFailed ? "GPS data invalid; other properties successfully updated" :
"All properties successfully updated",
"sample",
"status"
);
}, function (error) {
switch (error.number) {
case E_INVALIDARG:
// Some imaging formats, such as PNG and BMP, do not support Windows properties.
// Other formats do not support all Windows properties.
// For example, JPEG does not support System.FlagStatus.
WinJS.log && WinJS.log(
"Error: One or more properties may not be supported by this file format.",
"sample",
"error"
);
break;
default:
WinJS.log && WinJS.log("Failed to update properties: " + error.message, "sample", "error");
break;
}
resetSessionState();
});
}