Skip to content

Instantly share code, notes, and snippets.

@bogardpd

bogardpd/map.rb

Created Sep 30, 2019
Embed
What would you like to do?
/app/classes/map.rb KML LineStrings (Routes)
#/app/classes/map.rb
def kml_routes(routes, name)
return nil unless routes.any?
routes = routes.map{|r| r.sort_by{|x| @airport_details[x][:iata]}}.uniq.sort_by{|y| [@airport_details[y[0]][:iata], @airport_details[y[1]][:iata]]}
return content_tag(:Folder) do
concat content_tag(:name, name)
concat safe_join(routes.map{|r| kml_route(r)})
end
end
def kml_route(airport_pair)
detail = airport_pair.map{|a| @airport_details[a]}
return content_tag(:Placemark) do
concat content_tag(:name, detail.map{|a| a[:iata]}.join("–"))
concat content_tag(:styleUrl, "#flightPath")
concat (content_tag(:LineString) do
concat content_tag(:tessellate, "1")
concat content_tag(:coordinates, detail.map{|a| "#{a[:longitude]},#{a[:latitude]},0"}.join(" "))
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.