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