mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Refactor the map_marker partial.
This commit is contained in:
parent
d4bd3c7c8b
commit
951648c94e
5 changed files with 60 additions and 68 deletions
41
app/assets/javascripts/map_marker.js.coffee
Normal file
41
app/assets/javascripts/map_marker.js.coffee
Normal file
|
@ -0,0 +1,41 @@
|
|||
window.map_marker = (map, options = {}) ->
|
||||
pos = new google.maps.LatLng(options.lat, options.lng)
|
||||
|
||||
if options.radius > 0
|
||||
new google.maps.Circle
|
||||
map: map
|
||||
strokeColor: '#FF0000'
|
||||
strokeOpacity: 0.8
|
||||
strokeWeight: 2
|
||||
fillColor: '#FF0000'
|
||||
fillOpacity: 0.35
|
||||
center: pos
|
||||
radius: options.radius
|
||||
else
|
||||
new google.maps.Marker
|
||||
map: map
|
||||
position: pos
|
||||
title: 'Recorded Location'
|
||||
|
||||
if options.course
|
||||
p1 = new LatLon(pos.lat(), pos.lng())
|
||||
speed = if options.speed? then options.speed else 1
|
||||
p2 = p1.destinationPoint(options.course, Math.max(0.2, speed) * 0.1)
|
||||
|
||||
lineCoordinates = [
|
||||
pos
|
||||
new google.maps.LatLng(p2.lat(), p2.lon())
|
||||
]
|
||||
|
||||
lineSymbol =
|
||||
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
|
||||
|
||||
new google.maps.Polyline
|
||||
map: map
|
||||
path: lineCoordinates
|
||||
icons: [
|
||||
{
|
||||
icon: lineSymbol
|
||||
offset: '100%'
|
||||
}
|
||||
]
|
|
@ -14,11 +14,10 @@
|
|||
};
|
||||
|
||||
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
|
||||
<% events.each do |event| %>
|
||||
<%= render "shared/map_marker", map: 'map', location: event.location %>
|
||||
<% end %>
|
||||
</script>
|
||||
|
||||
<% events.each do |event| %>
|
||||
<%= render "shared/map_marker", event: event %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p>
|
||||
No events found.
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
};
|
||||
|
||||
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
|
||||
</script>
|
||||
|
||||
<%= render "shared/map_marker", event: @event %>
|
||||
<%= render "shared/map_marker", map: 'map', location: @event.location %>
|
||||
</script>
|
||||
<% end %>
|
||||
|
||||
<br />
|
||||
|
|
|
@ -1,61 +1,13 @@
|
|||
<script>
|
||||
(function(map) {
|
||||
<%
|
||||
if event.payload[:horizontal_accuracy] && event.payload[:vertical_accuracy]
|
||||
radius = (event.payload[:horizontal_accuracy].to_f + event.payload[:vertical_accuracy].to_f) / 2.0
|
||||
elsif event.payload[:horizontal_accuracy]
|
||||
radius = event.payload[:horizontal_accuracy].to_f
|
||||
elsif event.payload[:vertical_accuracy]
|
||||
radius = event.payload[:vertical_accuracy].to_f
|
||||
elsif event.payload[:accuracy]
|
||||
radius = event.payload[:accuracy].to_f
|
||||
else
|
||||
radius = 0
|
||||
end
|
||||
%>
|
||||
|
||||
var pos = new google.maps.LatLng(<%= event.lat %>, <%= event.lng %>);
|
||||
|
||||
<% if radius > 0 %>
|
||||
var accuracyCircle = new google.maps.Circle({
|
||||
strokeColor: '#FF0000',
|
||||
strokeOpacity: 0.8,
|
||||
strokeWeight: 2,
|
||||
fillColor: '#FF0000',
|
||||
fillOpacity: 0.35,
|
||||
map: map,
|
||||
center: pos,
|
||||
radius: <%= radius %>
|
||||
});
|
||||
<% else %>
|
||||
var marker = new google.maps.Marker({
|
||||
position: pos,
|
||||
map: map,
|
||||
title: 'Recorded Location'
|
||||
});
|
||||
<% end %>
|
||||
|
||||
|
||||
<% if event.payload[:course] && event.payload[:course].to_f > -1 %>
|
||||
var p1 = new LatLon(pos.lat(), pos.lng());
|
||||
var p2 = p1.destinationPoint(<%= event.payload[:course].to_f %>, <%= [0.2, (event.payload[:speed] || 1).to_f].max * 0.1 %>);
|
||||
|
||||
var lineCoordinates = [ pos, new google.maps.LatLng(p2.lat(), p2.lon()) ];
|
||||
|
||||
var lineSymbol = {
|
||||
path:google.maps.SymbolPath.FORWARD_CLOSED_ARROW
|
||||
};
|
||||
|
||||
var line = new google.maps.Polyline({
|
||||
path: lineCoordinates,
|
||||
icons: [
|
||||
{
|
||||
icon: lineSymbol,
|
||||
offset: '100%'
|
||||
}
|
||||
],
|
||||
map: map
|
||||
});
|
||||
<% end %>
|
||||
})(map);
|
||||
</script>
|
||||
<%- unless @map_marker_included_p -%>
|
||||
<%- content_for :head do -%>
|
||||
<%= javascript_include_tag "map_marker" %>
|
||||
<%- end -%>
|
||||
<%- @map_marker_included_p = true -%>
|
||||
<%- end -%>
|
||||
map_marker(<%= map %>, {
|
||||
lat: <%= location[:lat].to_json %>,
|
||||
lng: <%= location[:lng].to_json %>,
|
||||
radius: <%= location[:radius].to_json %>,
|
||||
course: <%= location[:course].to_json %>,
|
||||
speed: <%= location[:speed].to_json %>
|
||||
});
|
||||
|
|
|
@ -61,7 +61,7 @@ Huginn::Application.configure do
|
|||
end
|
||||
|
||||
# Precompile additional assets (application.js.coffee.erb, application.css, and all non-JS/CSS are already added)
|
||||
config.assets.precompile += %w( diagram.js graphing.js user_credentials.js )
|
||||
config.assets.precompile += %w( diagram.js graphing.js map_marker.js user_credentials.js )
|
||||
|
||||
# Ignore bad email addresses and do not raise email delivery errors.
|
||||
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
||||
|
|
Loading…
Add table
Reference in a new issue