-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
map.html.erb
114 lines (95 loc) · 4.1 KB
/
map.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&language=en&key=AIzaSyDWgc7p4WWFsO3y0MTe50vF4l4NUPcPuwE"></script>
<div class="container">
<form method="GET" action="/users/map" id="search">
<div class="row">
<div class="col-lg-1">
<label for="search"><%= t('users.map.search') %></label>
</div>
<div class="form-group col-lg-1">
<select name="tag" id="tag_type" class="form-control" value="<%= params[:tag] %>">
<option></option>
<option><%= t('users.map.skill') %></option>
<option><%= t('users.map.gear') %></option>
<option><%= t('users.map.role') %></option>
<option><%= t('users.map.tool') %></option>
</select>
</div>
<div class="form-group col-lg-2">
<input id="tag_value" type="text" name="value" class="form-control" value="<%= params[:value] %>">
</div>
</div>
<div class="row">
<div class="col-lg-1">
<label for="search location"><%= t('users.map.location') %></label>
</div>
<div class="form-group col-lg-3">
<input type="text" name="country" class="form-control" id="country" value="<%= params[:country] %>">
</div>
</div>
<div class="row">
<div class="col-lg-offset-1">
<input type="submit" id="submit" value="Search" class="btn btn-primary">
</div>
</div>
</form>
<br >
<div id="users_map" class="row"></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#tag_type").val("<%= params[:tag] %>");
<% if @location_tags %>
$("#users_map").html("<div id='map' class='col-lg-12' style='height:500px;'></div>");
var user_map = L.map('map').setView([15,0], 2);
L.tileLayer("https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png",{
attribution: "<a href='https://openstreetmap.org'>OSM</a> tiles by <a href='https://mapbox.com'>MapBox</a>"
}).addTo(user_map);
<% @location_tags.each do |location_tag, user_tag| %>
var marker = L.marker([<%= location_tag[0] %>, <%= location_tag[1] %>]).addTo(user_map);
var contents = "";
<% user_tag.each do |tag| %>
contents += "<b><%= tag.value %></b><br />"
<% end %>
marker.bindPopup(contents)
marker.openPopup()
<% end %>
<% elsif @users %>
$('#users_map').html("<div id='map' class='col-lg-12' style='height:500px;'></div>");
<% if !@country.nil? and !@country.empty? %>
<% geo_location = Geocoder.search("#{@country}").first || "" %>
var user_map = L.map('map').setView([<%= geo_location.latitude %>, <%= geo_location.longitude %>], 4);
<% else %>
var user_map = L.map('map').setView([15,0], 2);
<% end %>
L.tileLayer("https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png",{
attribution: "<a href='https://openstreetmap.org'>OSM</a> tiles by <a href='https://mapbox.com'>MapBox</a>"
}).addTo(user_map);
<% @users.each do |user| %>
<% location_privacy = user.user.location_privacy %>
<% if !location_privacy %>
var options = {
radius : 20,
opacity: 0.5,
duration: 200,
lng: function(d){ return d[1]; },
lat: function(d){ return d[0]; },
value: function(d){ return d.length; },
valueFloor: 0,
valueCeil: undefined,
colorRange: ['#f7fbff', '#08306b'],
onmouseover: function(d, node, layer) {},
onmouseout: function(d, node, layer) {},
onclick: function(d, node, layer) {}
}
var hexlayer = L.hexbinLayer(options).addTo(user_map);
hexlayer.colorScale().range(["white", "grey"]);
hexlayer.data([[<%= user.location_tag.lat %>, <%= user.location_tag.lon %>]]);
<% else %>
var marker = L.marker([<%= user.location_tag.lat %>, <%= user.location_tag.lon %>]);
marker.addTo(user_map);
marker.bindPopup("<b><%= user.name %></b>");
<% end %>
<% end %>
<% end %>
});
</script>