mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-07-10 06:48:36 +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);
|
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>
|
</script>
|
||||||
|
|
||||||
<% events.each do |event| %>
|
|
||||||
<%= render "shared/map_marker", event: event %>
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<p>
|
<p>
|
||||||
No events found.
|
No events found.
|
||||||
|
|
|
@ -36,9 +36,9 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
|
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 %>
|
<% end %>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -1,61 +1,13 @@
|
||||||
<script>
|
<%- unless @map_marker_included_p -%>
|
||||||
(function(map) {
|
<%- content_for :head do -%>
|
||||||
<%
|
<%= javascript_include_tag "map_marker" %>
|
||||||
if event.payload[:horizontal_accuracy] && event.payload[:vertical_accuracy]
|
<%- end -%>
|
||||||
radius = (event.payload[:horizontal_accuracy].to_f + event.payload[:vertical_accuracy].to_f) / 2.0
|
<%- @map_marker_included_p = true -%>
|
||||||
elsif event.payload[:horizontal_accuracy]
|
<%- end -%>
|
||||||
radius = event.payload[:horizontal_accuracy].to_f
|
map_marker(<%= map %>, {
|
||||||
elsif event.payload[:vertical_accuracy]
|
lat: <%= location[:lat].to_json %>,
|
||||||
radius = event.payload[:vertical_accuracy].to_f
|
lng: <%= location[:lng].to_json %>,
|
||||||
elsif event.payload[:accuracy]
|
radius: <%= location[:radius].to_json %>,
|
||||||
radius = event.payload[:accuracy].to_f
|
course: <%= location[:course].to_json %>,
|
||||||
else
|
speed: <%= location[:speed].to_json %>
|
||||||
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>
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ Huginn::Application.configure do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Precompile additional assets (application.js.coffee.erb, application.css, and all non-JS/CSS are already added)
|
# 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.
|
# 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.
|
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue