PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/scala/travel/KmlGenerator.scala

https://github.com/tackley/travel-map
Scala | 41 lines | 34 code | 7 blank | 0 comment | 1 complexity | d48bf306281c8778b8403c83d95cb7ff MD5 | raw file
  1. package travel
  2. import loader.ContentItem
  3. import com.mongodb.casbah.commons.MongoDBObject
  4. import xml.{NodeSeq, Unparsed}
  5. object KmlGenerator {
  6. def kml = {
  7. println("generating real kml!!!")
  8. <kml xmlns="http://www.opengis.net/kml/2.2">
  9. <Document>
  10. <name>Guardian Travel Content</name>
  11. <description>The Guardian's GeoTagged Travel Content</description>
  12. {
  13. for {
  14. c <- ContentItem.find(MongoDBObject())
  15. lat <- c.lat
  16. long <- c.long
  17. } yield {
  18. <Placemark>
  19. <name>{c.webTitle}</name>
  20. <description>
  21. { img(c.thumbnail) + c.trailText.getOrElse("") + link(c.url)}
  22. </description>
  23. <Point>
  24. <coordinates>{long},{lat},0</coordinates>
  25. </Point>
  26. </Placemark>
  27. }
  28. }
  29. </Document>
  30. </kml>
  31. }
  32. def link(url: String) = (<p><a href={url}>See the whole article on the Guardian.</a></p>).toString()
  33. def img(thumbnail: Option[String]) = thumbnail.map(t=> <p><img src={t} width="140" height="84" /></p>.toString()) getOrElse ""
  34. }