1 <script type="text/javascript">
2 var nearest = [], friends = [];
3 <% friends = @user.friends.collect { |f| f.befriendee } %>
4 <% friends.each do |friend| %>
5 <% if !friend.home_lat.nil? and !friend.home_lon.nil? %>
7 display_name : "<%= escape_javascript(friend.display_name) %>",
8 home_lat : <%= friend.home_lat %>,
9 home_lon : <%= friend.home_lon %>
13 <% nearest = @user.nearby - friends %>
14 <% nearest.each do |nearby| %>
16 display_name : "<%= escape_javascript(nearby.display_name) %>",
17 home_lat : <%= nearby.home_lat %>,
18 home_lon : <%= nearby.home_lon %>
23 <% if @user.home_lat.nil? or @user.home_lon.nil? %>
24 <% lon = h(params['lon'] || '-0.1') %>
25 <% lat = h(params['lat'] || '51.5') %>
26 <% zoom = h(params['zoom'] || '4') %>
29 <% mlon = @user.home_lon %>
30 <% mlat = @user.home_lat %>
31 <% lon = @user.home_lon %>
32 <% lat = @user.home_lat %>
36 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
37 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
38 <%= javascript_include_tag 'map.js' %>
40 <script type="text/javascript">
44 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
47 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
48 var zoom = <%= zoom %>;
50 <% if params['scale'] and params['scale'].length > 0 then %>
51 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
54 var map = createMap("map");
56 setMapCenter(centre, zoom);
59 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>), null, "<%= t 'user.map.your location' %>");
62 var near_icon = OpenLayers.Marker.defaultIcon();
63 near_icon.url = OpenLayers.Util.getImagesLocation() + "marker-green.png";;
64 var i = nearest.length;
66 var description = i18n('<%= t 'user.map.nearby mapper'%>', { nearby_user: '<a href="/user/'+nearest[i].display_name+'">'+nearest[i].display_name+'</a>' });
67 var nearmarker = addMarkerToMap(new OpenLayers.LonLat(nearest[i].home_lon, nearest[i].home_lat), near_icon.clone(), description);
70 var friend_icon = OpenLayers.Marker.defaultIcon();
71 friend_icon.url = OpenLayers.Util.getImagesLocation() + "marker-blue.png";;
72 var i = friends.length;
74 var description = i18n('<%= t 'user.map.friend'%>', { friend_user: '<a href="/user/'+friends[i].display_name+'">'+friends[i].display_name+'</a>' });
75 var friendmarker = addMarkerToMap(new OpenLayers.LonLat(friends[i].home_lon, friends[i].home_lat), friend_icon.clone(), description);
78 if (document.getElementById('updatehome')) {
79 map.events.register("click", map, setHome);
83 function setHome( e ) {
86 if (document.getElementById('updatehome').checked) {
87 var lonlat = getEventPosition(e);
89 document.getElementById('homerow').className = '';
90 document.getElementById('home_lat').value = lonlat.lat;
91 document.getElementById('home_lon').value = lonlat.lon;
94 removeMarkerFromMap(marker);
97 marker = addMarkerToMap(lonlat, null, "<%= t 'user.map.your location' %>");
101 window.onload = init;