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