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