usermap.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. function scrapeNotices(user)
  2. {
  3. var notices = [];
  4. $(".notice").each(function(){
  5. var notice = getNoticeFromElement($(this));
  6. if (user) {
  7. notice['user'] = user;
  8. } else {
  9. notice['user'] = getUserFromElement($(this));
  10. }
  11. if(notice['geo'])
  12. notices.push(notice);
  13. });
  14. return notices;
  15. }
  16. function scrapeUser()
  17. {
  18. var avatarURL = $(".entity_profile .entity_depiction img.avatar").attr('src');
  19. var profileURL = $(".entity_profile .entity_nickname .url").attr('href');
  20. var nickname = $(".entity_profile .entity_nickname .nickname").text();
  21. return {
  22. 'profile_image_url': avatarURL,
  23. 'profile_url': profileURL,
  24. 'screen_name': nickname
  25. };
  26. }
  27. function getNoticeFromElement(noticeElement)
  28. {
  29. var notice = {};
  30. if(noticeElement.find(".geo").length) {
  31. var latlon = noticeElement.find(".geo").attr('title').split(";");
  32. notice['geo']={'coordinates': [
  33. parseFloat(latlon[0]),
  34. parseFloat(latlon[1])] };
  35. }
  36. notice['html'] = noticeElement.find(".e-content").html();
  37. notice['url'] = noticeElement.find("a.timestamp").attr('href');
  38. notice['created_at'] = noticeElement.find("abbr.published").text();
  39. return notice;
  40. }
  41. function getUserFromElement(noticeElement)
  42. {
  43. var avatarURL = noticeElement.find("img.avatar").attr('src');
  44. var profileURL = noticeElement.find(".author a.url").attr('href');
  45. var nickname = noticeElement.find(".author .nickname").text();
  46. return {
  47. 'profile_image_url': avatarURL,
  48. 'profile_url': profileURL,
  49. 'screen_name': nickname
  50. };
  51. }
  52. function showMapstraction(element, notices) {
  53. if(element instanceof jQuery) element = element[0];
  54. if(! $.isArray(notices)) notices = [notices];
  55. var mapstraction = new mxn.Mapstraction(element, _provider);
  56. var minLat = 181.0;
  57. var maxLat = -181.0;
  58. var minLon = 181.0;
  59. var maxLon = -181.0;
  60. for (var i in notices)
  61. {
  62. var n = notices[i];
  63. var lat = n['geo']['coordinates'][0];
  64. var lon = n['geo']['coordinates'][1];
  65. if (lat < minLat) {
  66. minLat = lat;
  67. }
  68. if (lat > maxLat) {
  69. maxLat = lat;
  70. }
  71. if (lon < minLon) {
  72. minLon = lon;
  73. }
  74. if (lon > maxLon) {
  75. maxLon = lon;
  76. }
  77. pt = new mxn.LatLonPoint(lat, lon);
  78. mkr = new mxn.Marker(pt);
  79. mkr.setIcon(n['user']['profile_image_url'], [24, 24]);
  80. mkr.setInfoBubble('<a href="'+ n['user']['profile_url'] + '">' + n['user']['screen_name'] + '</a>' + ' ' + n['html'] +
  81. '<br/><a href="'+ n['url'] + '">'+ n['created_at'] + '</a>');
  82. mapstraction.addMarker(mkr);
  83. }
  84. bounds = new mxn.BoundingBox(minLat, minLon, maxLat, maxLon);
  85. mapstraction.setBounds(bounds);
  86. }