GeoRSS aggregator and Layar augmented reality server
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

79 rader
1.9 KiB

  1. module PostsHelper
  2. def post_to_poi(post, subscription)
  3. # http://layar.com/documentation/browser/api/getpois-response/
  4. if subscription.layer.icon_url.blank?
  5. image_url = "%s%s/assets/layar-icons/tal-logo-100.png" % [ request.protocol, request.env['HTTP_HOST'] ]
  6. else
  7. image_url = subscription.layer.icon_url
  8. end
  9. scale = 1.0
  10. scale = 2.0 if post.distance < 50
  11. scale = post.distance / 1000 if post.distance > 1000
  12. res = {
  13. :id => post.id,
  14. :imageURL => image_url,
  15. :anchor => {
  16. :geolocation => {
  17. :lat => post.lat,
  18. :lon => post.lon,
  19. :alt => 0
  20. }
  21. },
  22. :text => {
  23. :title => decode_entities(post.title),
  24. :description => clean_description(post.summary),
  25. :footnote => "From #{post.feed_title}"
  26. },
  27. :actions => [
  28. {
  29. :label => "Read more...",
  30. :uri => post.url,
  31. :contentType => "text/html",
  32. :method => "GET",
  33. :activityType => 1
  34. },
  35. ]
  36. }
  37. unless subscription.icon_url.blank?
  38. res[:object] = {
  39. :contentType => "image/vnd.layar.generic",
  40. :url => subscription.icon_url,
  41. :reducedURL => subscription.icon_url,
  42. :size => subscription.icon_size
  43. }
  44. # http://layar.com/documentation/browser/api/getpois-response/hotspots/
  45. res[:transform] = {
  46. :rotate => {
  47. :rel => true,
  48. :axis => { :x => 0, :y => 0, :z => 1 },
  49. :angle => 0
  50. },
  51. :translate => { :x => 0, :y => -0.075, :z => ENV['APOLLO_TRANSLATE_Z'] || 1.75 },
  52. :scale => scale
  53. }
  54. end
  55. res
  56. end
  57. def decode_entities(s)
  58. HTMLEntities.new.decode s
  59. end
  60. def clean_description(s)
  61. if s.nil?
  62. return ""
  63. end
  64. if s.size > 137
  65. s = s[0..136] + '...'
  66. end
  67. decode_entities(s.gsub(/<.+?>/, ''))
  68. end
  69. end