source: subversion/sites/rails_port/app/views/user/_map.html.erb @ 20422

Revision 20422, 2.9 KB checked in by tomhughes, 4 years ago (diff)

Improve user popups on friend/nearby mapper maps.

Line 
1<% friends = @user.friends.collect { |f| f.befriendee }.select { |f| !f.home_lat.nil? and !f.home_lon.nil? } %>
2<% nearest = @user.nearby - friends %>
3
4<% if @user.home_lat.nil? or @user.home_lon.nil? %>
5  <% lon = h(params['lon'] || '-0.1') %>
6  <% lat = h(params['lat'] || '51.5') %>
7  <% zoom = h(params['zoom'] || '4') %>
8<% else %>
9  <% marker = true %>
10  <% mlon = @user.home_lon %>
11  <% mlat = @user.home_lat %>
12  <% lon =  @user.home_lon %>
13  <% lat =  @user.home_lat %>
14  <% zoom =  '12' %>
15<% end %>
16
17<%= javascript_include_tag '/openlayers/OpenLayers.js' %>
18<%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
19<%= javascript_include_tag 'map.js' %>
20
21<script type="text/javascript">
22  <!--
23  var marker;
24
25  OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
26
27  function init(){
28    var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
29    var zoom = <%= zoom %>;
30
31    <% if params['scale'] and params['scale'].length > 0 then %>
32    zoom = scaleToZoom(<%= params['scale'].to_f() %>);
33    <% end %>
34
35    var map = createMap("map");
36
37    setMapCenter(centre, zoom);
38
39    <% if marker %>
40    marker = addMarkerToMap(
41      new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>), null,
42      '<%= escape_javascript(render :partial => "popup", :object => @user, :locals => { :type => "your location" }) %>'
43    );
44    <% end %>
45
46    var near_icon = OpenLayers.Marker.defaultIcon();
47    near_icon.url = OpenLayers.Util.getImagesLocation() + "marker-green.png";
48    <% nearest.each do |u| %>
49      addMarkerToMap(new OpenLayers.LonLat(
50        <%= u.home_lon %>, <%= u.home_lat %>), near_icon.clone(),
51        '<%= escape_javascript(render :partial => "popup", :object => u, :locals => { :type => "nearby mapper" }) %>'
52      );
53    <% end %>
54
55    var friend_icon = OpenLayers.Marker.defaultIcon();
56    friend_icon.url = OpenLayers.Util.getImagesLocation() + "marker-blue.png";
57    <% friends.each do |u| %>
58      addMarkerToMap(new OpenLayers.LonLat(
59        <%= u.home_lon %>, <%= u.home_lat %>), friend_icon.clone(),
60        '<%= escape_javascript(render :partial => "popup", :object => u, :locals => { :type => "friend" }) %>'
61      );
62    <% end %>
63
64    if (document.getElementById('updatehome')) {
65      map.events.register("click", map, setHome);
66    }
67  }       
68
69  function setHome( e ) {
70    closeMapPopup();
71
72    if (document.getElementById('updatehome').checked) {
73      var lonlat = getEventPosition(e);
74
75      document.getElementById('homerow').className = '';
76      document.getElementById('home_lat').value = lonlat.lat;
77      document.getElementById('home_lon').value = lonlat.lon;
78
79      if (marker) {
80        removeMarkerFromMap(marker);
81      }
82
83      marker = addMarkerToMap(
84        lonlat, null,
85        '<%= escape_javascript(render :partial => "popup", :object => @user, :locals => { :type => "your location" }) %>'
86      );
87    }
88  }
89
90  window.onload = init;
91// -->
92</script>
Note: See TracBrowser for help on using the repository browser.