]> git.openstreetmap.org Git - rails.git/blob - app/views/site/index.rhtml
Added single line fix for IE7/Safari and many line fix for IE6.
[rails.git] / app / views / site / index.rhtml
1
2
3 <div id="geocoder">
4   <%= start_form_tag :controller => 'geocoder', :action => 'search' %>
5   <%= text_field 'query', 'postcode'%>
6   <%= text_field 'query', 'place_name'%>
7   <%= submit_tag 'Search' %>
8   <%= end_form_tag %>
9
10   <div id="geocoder-attribution">
11     Geolocation provided by <a href="http://npemap.org.uk/">npemap.org.uk</a>,
12     <a href="http://geocoder.us/">geocoder.us</a>, <a href="http://geocoder.ca/">geocoder.ca</a>
13     and <a href="http://www.geonames.org/">geonames.org</a>
14   </div>
15   <div id="postcode-helper">
16     eg: SW15 6JH, 95472 or H2L4C1
17   </div>
18   <div id="placename-helper">
19     eg:Essen
20   </div>
21 </div>
22
23 <% if params['mlon'] and params['mlat'] %>
24 <% marker = true %>
25 <% mlon = params['mlon'] %> 
26 <% mlat = params['mlat'] %>
27 <% lon =  params['mlon'] %>
28 <% lat =  params['mlat']  %>
29 <% zoom =  params['zoom'] || '12' %>
30 <script type="text/javascript">
31   var mlat = <%= lat %>;
32   var mlon = <%= lon %>;
33 </script>
34 <% elsif @user and params['lon'].nil? and params['lat'].nil? %> 
35 <% lon =  @user.home_lon %>
36 <% lat =  @user.home_lat %>
37 <% zoom = '10' %>
38 <%else%>
39 <% lon =  params['lon'] || '-0.1' %>
40 <% lat =  params['lat'] || '51.5' %>
41 <% zoom =  params['zoom'] || '4' %>
42 <% end %>
43
44
45
46 <script type="text/javascript">
47   var lat = <%= lat %>;
48   var lon = <%= lon %>;
49   var zoom = <%= zoom %>;
50   var PI = 3.14159265358979323846;
51
52
53
54   <% if params['scale'] and params['scale'].length > 0 then %>
55   zoom = Math.log(360.0/(( <% print params['scale'].to_f() %> ) * 512.0)) / Math.log(2.0);
56   <% end %>
57   zoom = zoom;
58   lon = lon * 20037508.34 / 180;
59   lat = Math.log(Math.tan( (90 + lat) * PI / 360)) / (PI / 180);
60   lat = lat * 20037508.34 / 180;
61   <% if marker %>
62   mlon = mlon * 20037508.34 / 180;
63   mlat = Math.log(Math.tan( (90 + mlat) * PI / 360)) / (PI / 180);
64   mlat = mlat * 20037508.34 / 180;
65   <%end%>
66
67 </script>
68 <script type="text/javascript" src="/javascripts/OpenLayers.js"></script>
69
70 <script type="text/javascript">
71   <!--
72   var map, layer, markers;
73   var ie6 = ! ( window.addEventListener || window.XMLHttpRequest );
74
75   function init(){
76
77     OpenLayers.Util.onImageLoadError = function() {
78       this.src = "http://www.openstreetmap.org/javascripts/img/404.png";
79     }
80     map = new OpenLayers.Map( "map", 
81         {maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), maxZoomLevel:18, maxResolution:156543, units:'meters', projection: "EPSG:41001"} );
82     layer = new OpenLayers.Layer.LikeGoogle( "Mapnik", "http://tile.openstreetmap.org/", {type:'png'} );
83     map.addLayer(layer);
84     layer = new OpenLayers.Layer.LikeGoogle( "Osmarender", "http://dev.openstreetmap.org/~ojw/Tiles/tile.php/", {type:'png'} );
85     map.addLayer(layer);
86
87     //Marker stuff
88
89     <% if marker %>
90     markers = new OpenLayers.Layer.Markers("markers");
91     map.addLayer(markers); 
92
93     marker = new OpenLayers.Marker(new OpenLayers.LonLat(mlon,mlat));
94     markers.addMarker(marker);
95     <%end%>
96
97       map.addControl(new OpenLayers.Control.LayerSwitcher());
98     map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
99
100     map.events.register("moveend", map, function() { 
101         var lonlat = map.getCenter();
102
103         var lon_deg = (lonlat.lon / 20037508.34) * 180;
104         var lat_deg = (lonlat.lat / 20037508.34) * 180;
105         var PI = 3.14159265358979323846;
106         lat_deg = 180/PI * (2 * Math.atan(Math.exp(lat_deg * PI / 180)) - PI / 2);
107         var zoom = map.getZoom();
108         updatelinks(lon_deg,lat_deg,zoom);
109         });
110     document.getElementById( 'map_OpenLayers_ViewPort' ).style.position = 'absolute';
111     if( ie6 ) {
112       handleResize();
113     }
114   }        
115
116   function getStyle( el, property ) {
117     var style;
118     if( el.currentStyle ) {
119         style = el.currentStyle[property];
120     } else if( window.getComputedStyle ) {
121         style = document.defaultView.getComputedStyle(el,null).getPropertyValue(property);
122     } else {
123         style = el.style[property];
124     }
125     return style;
126   }
127   
128   function handleResize() {
129     var el = document.getElementById( 'map' );
130     var left = getStyle( el, 'left' );
131     var top = getStyle( el, 'top' );
132     var bottom = el.old_bottom;
133     if( ! bottom ) {
134       bottom = getStyle( el, 'bottom' );
135     }
136     var right = el.old_right;
137     if( ! right ) {
138         right = getStyle( el, 'right' );
139     }
140     var width = el.old_width;
141     if( ! width ) {
142         width = getStyle( el, 'width' );
143     }
144     var height = el.old_height;
145     if( ! height ) {
146         height = getStyle( el, 'height' );
147     }
148     var pwidth, pheight;
149     if( el.offsetParent.nodeName == 'BODY' || el.offsetParent.nodeName == 'HTML' ) {
150       if( typeof( window.innerWidth ) == 'number' ) {
151           pwidth = window.innerWidth;
152           height = window.innerHeight;
153       } else if( document.documentElement &&
154           ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
155           pwidth = document.documentElement.clientWidth;
156           pheight = document.documentElement.clientHeight;
157       } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
158           pwidth = document.body.clientWidth;
159           pheight = document.body.clientHeight;
160       }
161     } else {
162       pwidth = el.offsetParent.offsetWidth;
163       pheight = el.offsetParent.offsetHeight;
164     }
165     if( left != 'auto' && right != 'auto' && width == 'auto' ) {
166       el.old_width = width;
167       var new_width = (pwidth - el.offsetLeft - parseInt( right ) );
168       el.style.width = new_width + 'px';
169     }
170     if( top != 'auto' && bottom != 'auto' && height == 'auto' ) {
171       el.old_height = height;
172       var new_height = (pheight - el.offsetHeight - parseInt( bottom ) );
173       el.style.height = new_height + 'px';
174     }
175   }
176
177 if( ie6 ) {
178   window.onresize = handleResize;
179 }
180 window.onload = init;
181 // -->
182 </script>