1 <%= render :partial => 'search' %>
3 <% if params['mlon'] and params['mlat'] %>
5 <% mlon = params['mlon'] %>
6 <% mlat = params['mlat'] %>
9 <% if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] %>
11 <% minlon = params['minlon'] %>
12 <% minlat = params['minlat'] %>
13 <% maxlon = params['maxlon'] %>
14 <% maxlat = params['maxlat'] %>
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 %>
36 <% zoom = params['zoom'] || '5' %>
37 <% layers = params['layers'] %>
40 <script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
41 <%= javascript_include_tag 'map.js' %>
44 <script src="http://www.mappam.com/javascripts/mappam.js" type="text/javascript"></script>
48 <script type="text/javascript">
50 var ie = navigator.appName.indexOf("Microsoft Internet Explorer") != -1;
54 var map = createMap("map");
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);
61 map.zoomToExtent(bbox);
63 var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
64 var zoom = <%= zoom %>;
66 <% if params['scale'] and params['scale'].length > 0 then %>
67 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
70 map.setCenter(centre, zoom);
74 addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
78 setMapLayers("<%= layers %>");
81 map.events.register("moveend", map, updateLocation);
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');
92 document.getElementById('map_OpenLayers_ViewPort').style.position = 'absolute';
98 function updateLocation() {
99 var lonlat = mercatorToLonLat(map.getCenter());
100 var zoom = map.getZoom();
101 var layers = getMapLayers();
103 updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
105 document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
108 function getStyle( el, property ) {
110 if( el.currentStyle ) {
111 style = el.currentStyle[property];
112 } else if( window.getComputedStyle ) {
113 style = document.defaultView.getComputedStyle(el,null).getPropertyValue(property);
115 style = el.style[property];
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;
129 width = getStyle( el, 'width' );
131 var height = el.old_height;
133 height = getStyle( el, 'height' );
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;
149 pwidth = el.offsetParent.offsetWidth;
150 pheight = el.offsetParent.offsetHeight;
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';
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';
163 el.style.display = 'none';
164 setTimeout( function() { el.style.display = ''; }, 200 );
168 window.onresize = handleResize;
171 window.onload = init;