]> git.openstreetmap.org Git - rails.git/blob - app/views/site/index.rhtml
add mappam... also stuff in user controller that must have been done by TomH?
[rails.git] / app / views / site / index.rhtml
1 <%= render :partial => 'search' %>
2
3 <% if params['mlon'] and params['mlat'] %>
4 <% marker = true %>
5 <% mlon = params['mlon'] %> 
6 <% mlat = params['mlat'] %>
7 <% lon =  params['mlon'] %>
8 <% lat =  params['mlat']  %>
9 <% zoom =  params['zoom'] || '12' %>
10 <% elsif @user and params['lon'].nil? and params['lat'].nil? %> 
11 <% lon =  @user.home_lon %>
12 <% lat =  @user.home_lat %>
13 <% zoom = '10' %>
14 <%else%>
15 <% lon =  params['lon'] || '-0.1' %>
16 <% lat =  params['lat'] || '51.5' %>
17 <% zoom =  params['zoom'] || '4' %>
18 <% end %>
19
20 <script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
21 <%= javascript_include_tag 'map.js' %>
22
23     <% unless @user %>
24     <script src="http://www.mappam.com/javascripts/mappam.js" type="text/javascript"></script>
25
26     <% end %>
27
28
29 <script type="text/javascript">
30   <!--
31   var ie6 = ! ( window.addEventListener || window.XMLHttpRequest );
32   var map;
33
34   function init(){
35     var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
36     var zoom = <%= zoom %>;
37
38     <% if params['scale'] and params['scale'].length > 0 then %>
39     zoom = scaleToZoom(<%= params['scale'].to_f() %>);
40     <% end %>
41
42     var map = createMap("map", centre, zoom);
43
44     <% if marker %>
45     addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
46     <% end %>
47
48     map.events.register("moveend", map, updateLocation);
49     updateLocation();
50
51     <% unless @user %>
52      if( window.location.host.match( /^www/ ) ) { 
53         mappam.register( map, '10011756636067178496', '1');
54       } else {
55         mappam.register( map, '6738410720121976832', '1');
56       }
57
58     <% end %>
59
60     document.getElementById('map_OpenLayers_ViewPort').style.position = 'absolute';
61     if ( ie6 ) {
62       handleResize();
63     }
64   }        
65
66   function updateLocation() {
67     var lonlat = mercatorToLonLat(map.getCenter());
68     var zoom = map.getZoom();
69
70     updatelinks(lonlat.lon, lonlat.lat, zoom);
71   }
72
73   function getStyle( el, property ) {
74     var style;
75     if( el.currentStyle ) {
76         style = el.currentStyle[property];
77     } else if( window.getComputedStyle ) {
78         style = document.defaultView.getComputedStyle(el,null).getPropertyValue(property);
79     } else {
80         style = el.style[property];
81     }
82     return style;
83   }
84   
85   function handleResize() {
86     var el = document.getElementById( 'map' );
87     var left = getStyle( el, 'left' );
88     var top = getStyle( el, 'top' );
89     var bottom = getStyle( el, 'bottom' );
90     var right = getStyle( el, 'right' );
91     var width = el.old_width;
92     if( ! width ) {
93         width = getStyle( el, 'width' );
94     }
95     var height = el.old_height;
96     if( ! height ) {
97         height = getStyle( el, 'height' );
98     }
99     var pwidth, pheight;
100     if( el.offsetParent.nodeName == 'BODY' || el.offsetParent.nodeName == 'HTML' ) {
101       if( typeof( window.innerWidth ) == 'number' ) {
102           pwidth = window.innerWidth;
103           height = window.innerHeight;
104       } else if( document.documentElement &&
105           ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
106           pwidth = document.documentElement.clientWidth;
107           pheight = document.documentElement.clientHeight;
108       } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
109           pwidth = document.body.clientWidth;
110           pheight = document.body.clientHeight;
111       }
112     } else {
113       pwidth = el.offsetParent.offsetWidth;
114       pheight = el.offsetParent.offsetHeight;
115     }
116     if( left != 'auto' && right != 'auto' && width == 'auto' ) {
117       el.old_width = width;
118       var new_width = (pwidth - el.offsetLeft - parseInt( right ) );
119       el.style.width = new_width + 'px';
120     }
121     if( top != 'auto' && bottom != 'auto' && height == 'auto' ) {
122       el.old_height = height;
123       var new_height = (pheight - el.offsetTop - parseInt( bottom ) );
124       el.style.height = new_height + 'px';
125     }
126     map.updateSize();
127     el.style.display = 'none';
128     setTimeout( function() {
129         el.style.display = '';
130         }, 200 );
131   }
132
133   if ( ie6 ) {
134     window.onresize = handleResize;
135   }
136
137   window.onload = init;
138 // -->
139 </script>