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