_show.html.erb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <% content_for :head do -%>
  2. <%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=#{@agent.options[:api_key]}" %>
  3. <%= javascript_include_tag "map_marker" %>
  4. <% end -%>
  5. <h3>Recent Event Map</h3>
  6. <% events = @agent.events.with_location.order("id desc").limit(500) %>
  7. <% if events.length > 0 %>
  8. <div id="map_canvas" style="width:800px; height:800px"></div>
  9. <script type="text/javascript">
  10. var mapOptions = {
  11. center: new google.maps.LatLng(<%= events.first.lat %>, <%= events.first.lng %>),
  12. zoom: 15,
  13. mapTypeId: google.maps.MapTypeId.ROADMAP
  14. };
  15. var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  16. var circles = [];
  17. var points = [];
  18. <% events.each do |event| %>
  19. var loc = <%= Utils.jsonify(event.location) %>;
  20. if (loc.radius > 1) {
  21. circles.push(map_marker(map, loc));
  22. }
  23. delete loc.radius;
  24. points.push(map_marker(map, loc));
  25. <% end %>
  26. function toggleAccuracy(group, map) {
  27. for (var i = 0; i < group.length; i++) {
  28. group[i].setMap(map);
  29. }
  30. }
  31. toggleAccuracy(circles, null);
  32. $(document).ready(function() {
  33. $("input#toggle").on("click", function() {
  34. if($(this).is(":checked")){
  35. toggleAccuracy(circles, map);
  36. toggleAccuracy(points, null);
  37. } else {
  38. toggleAccuracy(circles, null);
  39. toggleAccuracy(points, map);
  40. }
  41. });
  42. if(circles.length > 0){
  43. $(".toggle-accuracy").removeClass("hidden");
  44. }
  45. });
  46. </script>
  47. <% else %>
  48. <p>
  49. No events found.
  50. </p>
  51. <% end %>
  52. <div class="hidden toggle-accuracy checkbox">
  53. <label>
  54. <input id="toggle" type="checkbox" value="">
  55. Show accuracy of locations
  56. </label>
  57. </div>
  58. <h3>POST URL</h3>
  59. <p>
  60. Location data containing <code>latitude</code> and <code>longitude</code> can be posted to this URL:<br/>
  61. <ul>
  62. <li><code class="selectable-text"><%= web_requests_url(user_id: @agent.user_id, agent_id: @agent.id, secret: @agent.options['secret']) %></code></li>
  63. </ul>
  64. </p>
  65. <p>The data can also include <code>radius</code>, <code>speed</code>, and <code>course</code> values.</p>