4 <% form_tag :controller => 'geocoder', :action => 'search' do %>
5 <%= text_field 'query', 'postcode' %>
6 <%= text_field 'query', 'place_name'%>
7 <%= submit_tag 'Search' %>
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> and <a href="http://www.geonames.org/">geonames.org</a>
14 <div id="postcode-helper">
15 Enter a postcode or zip code, eg: SW15 6JH, 95472
17 <div id="placename-helper">
18 Enter a place-name, eg:Essen
22 <% if params['mlon'] and params['mlat'] %>
24 <% mlon = params['mlon'] %>
25 <% mlat = params['mlat'] %>
26 <% lon = params['mlon'] %>
27 <% lat = params['mlat'] %>
28 <% zoom = params['zoom'] || '12' %>
29 <script type="text/javascript">
30 var mlat = <%= lat %>;
31 var mlon = <%= lon %>;
33 <% elsif @user and params['lon'].nil? and params['lat'].nil? %>
34 <% lon = @user.home_lon %>
35 <% lat = @user.home_lat %>
38 <% lon = params['lon'] || '-0.1' %>
39 <% lat = params['lat'] || '51.5' %>
40 <% zoom = params['zoom'] || '4' %>
45 <script type="text/javascript">
48 var zoom = <%= zoom %>;
49 var PI = 3.14159265358979323846;
53 <% if params['scale'] and params['scale'].length > 0 then %>
54 zoom = Math.log(360.0/(( <% print params['scale'].to_f() %> ) * 512.0)) / Math.log(2.0);
57 lon = lon * 20037508.34 / 180;
58 lat = Math.log(Math.tan( (90 + lat) * PI / 360)) / (PI / 180);
59 lat = lat * 20037508.34 / 180;
61 mlon = mlon * 20037508.34 / 180;
62 mlat = Math.log(Math.tan( (90 + mlat) * PI / 360)) / (PI / 180);
63 mlat = mlat * 20037508.34 / 180;
67 <script type="text/javascript" src="/javascripts/OpenLayers.js"></script>
69 <script type="text/javascript">
71 var map, layer, markers;
72 var ie6 = ! ( window.addEventListener || window.XMLHttpRequest );
76 OpenLayers.Util.onImageLoadError = function() {
77 this.src = "http://www.openstreetmap.org/javascripts/img/404.png";
79 map = new OpenLayers.Map( "map",
80 {maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), maxZoomLevel:18, maxResolution:156543, units:'meters', projection: "EPSG:41001"} );
81 layer = new OpenLayers.Layer.LikeGoogle( "Mapnik", "http://tile.openstreetmap.org/", {type:'png'} );
83 layer = new OpenLayers.Layer.LikeGoogle( "Osmarender", "http://dev.openstreetmap.org/~ojw/Tiles/tile.php/", {type:'png'} );
89 markers = new OpenLayers.Layer.Markers("markers");
90 map.addLayer(markers);
92 marker = new OpenLayers.Marker(new OpenLayers.LonLat(mlon,mlat));
93 markers.addMarker(marker);
96 map.addControl(new OpenLayers.Control.LayerSwitcher());
97 map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
99 map.events.register("moveend", map, updateLocation);
100 document.getElementById( 'map_OpenLayers_ViewPort' ).style.position = 'absolute';
107 function updateLocation() {
108 var lonlat = map.getCenter();
110 var lon_deg = (lonlat.lon / 20037508.34) * 180;
111 var lat_deg = (lonlat.lat / 20037508.34) * 180;
112 var PI = 3.14159265358979323846;
113 lat_deg = 180/PI * (2 * Math.atan(Math.exp(lat_deg * PI / 180)) - PI / 2);
114 var zoom = map.getZoom();
116 updatelinks(lon_deg,lat_deg,zoom);
119 function getStyle( el, property ) {
121 if( el.currentStyle ) {
122 style = el.currentStyle[property];
123 } else if( window.getComputedStyle ) {
124 style = document.defaultView.getComputedStyle(el,null).getPropertyValue(property);
126 style = el.style[property];
131 function handleResize() {
132 var el = document.getElementById( 'map' );
133 var left = getStyle( el, 'left' );
134 var top = getStyle( el, 'top' );
135 var bottom = getStyle( el, 'bottom' );
136 var right = getStyle( el, 'right' );
137 var width = el.old_width;
139 width = getStyle( el, 'width' );
141 var height = el.old_height;
143 height = getStyle( el, 'height' );
146 if( el.offsetParent.nodeName == 'BODY' || el.offsetParent.nodeName == 'HTML' ) {
147 if( typeof( window.innerWidth ) == 'number' ) {
148 pwidth = window.innerWidth;
149 height = window.innerHeight;
150 } else if( document.documentElement &&
151 ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
152 pwidth = document.documentElement.clientWidth;
153 pheight = document.documentElement.clientHeight;
154 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
155 pwidth = document.body.clientWidth;
156 pheight = document.body.clientHeight;
159 pwidth = el.offsetParent.offsetWidth;
160 pheight = el.offsetParent.offsetHeight;
162 if( left != 'auto' && right != 'auto' && width == 'auto' ) {
163 el.old_width = width;
164 var new_width = (pwidth - el.offsetLeft - parseInt( right ) );
165 el.style.width = new_width + 'px';
167 if( top != 'auto' && bottom != 'auto' && height == 'auto' ) {
168 el.old_height = height;
169 var new_height = (pheight - el.offsetTop - parseInt( bottom ) );
170 el.style.height = new_height + 'px';
173 el.style.display = 'none';
174 setTimeout( function() {
175 el.style.display = '';
180 window.onresize = handleResize;
182 window.onload = init;