westdc-zf1/htdocs/js/timemap/loaders/flickr.js

93 lines
2.7 KiB
JavaScript
Raw Normal View History

2009-12-20 10:56:42 +00:00
/*
2010-06-29 08:58:09 +00:00
* Timemap.js Copyright 2010 Nick Rabinowitz.
2009-12-20 10:56:42 +00:00
* Licensed under the MIT License (see LICENSE.txt)
*/
/**
* @fileOverview
* Flickr Loader
*
* @author Nick Rabinowitz (www.nickrabinowitz.com)
*/
2010-06-29 08:58:09 +00:00
// for JSLint
/*global TimeMap */
2009-12-20 10:56:42 +00:00
/**
* @class
2010-06-29 08:58:09 +00:00
* Flickr loader: Load JSONP data from Flickr.
2009-12-20 10:56:42 +00:00
*
2010-06-29 08:58:09 +00:00
* <p>This is a loader for Flickr data. You probably want to use it with a
2009-12-20 10:56:42 +00:00
* URL for the Flickr Geo Feed API: <a href="http://www.flickr.com/services/feeds/geo/">http://www.flickr.com/services/feeds/geo/</a></p>
*
2010-06-29 08:58:09 +00:00
* <p>The loader takes a full URL, minus the JSONP callback function.</p>
*
* @augments TimeMap.loaders.jsonp
* @requires loaders/json.js
2009-12-20 10:56:42 +00:00
*
2010-06-29 08:58:09 +00:00
* @example
TimeMap.init({
2009-12-20 10:56:42 +00:00
datasets: [
{
title: "Flickr Dataset",
type: "flickr",
options: {
// This is just the latest geotagged photo stream - try adding
// an "id" or "tag" or "photoset" parameter to get what you want
url: "http://www.flickr.com/services/feeds/geo/?format=json&jsoncallback="
}
}
2010-06-29 08:58:09 +00:00
],
// etc...
});
* @see <a href="../../examples/pathlines.html">Flickr Pathlines Example</a>
2009-12-20 10:56:42 +00:00
*
2010-06-29 08:58:09 +00:00
* @param {Object} options All options for the loader
* @param {String} options.url Full JSONP url of Flickr feed to load
* @param {mixed} [options[...]] Other options (see {@link TimeMap.loaders.jsonp})
2009-12-20 10:56:42 +00:00
*/
TimeMap.loaders.flickr = function(options) {
var loader = new TimeMap.loaders.jsonp(options);
2010-06-29 08:58:09 +00:00
/**
* Preload function for Flickr feeds
* @name TimeMap.loaders.flickr#preload
* @function
* @parameter {Object} data Data to preload
* @return {Array} data Array of item data
*/
2009-12-20 10:56:42 +00:00
loader.preload = function(data) {
return data["items"];
};
2010-06-29 08:58:09 +00:00
/**
* Transform function for Flickr feeds
* @name TimeMap.loaders.flickr#transform
* @function
* @parameter {Object} data Data to transform
* @return {Object} data Transformed data for one item
*/
2009-12-20 10:56:42 +00:00
loader.transform = function(data) {
var item = {
2010-06-29 08:58:09 +00:00
title: data.title,
start: data.date_taken,
2009-12-20 10:56:42 +00:00
point: {
2010-06-29 08:58:09 +00:00
lat: data.latitude,
lon: data.longitude
2009-12-20 10:56:42 +00:00
},
options: {
2010-06-29 08:58:09 +00:00
description: data.description
2009-12-20 10:56:42 +00:00
.replace(/&gt;/g, ">")
.replace(/&lt;/g, "<")
.replace(/&quot;/g, '"')
}
};
2010-06-29 08:58:09 +00:00
if (options.transformFunction) {
2009-12-20 10:56:42 +00:00
item = options.transformFunction(item);
2010-06-29 08:58:09 +00:00
}
2009-12-20 10:56:42 +00:00
return item;
};
return loader;
2010-06-29 08:58:09 +00:00
};