1 <%= render :partial => 'search', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
5 <% if params['mlon'] and params['mlat'] %>
7 <% mlon = params['mlon'] %>
8 <% mlat = params['mlat'] %>
11 <% if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] %>
13 <% minlon = params['minlon'] %>
14 <% minlat = params['minlat'] %>
15 <% maxlon = params['maxlon'] %>
16 <% maxlat = params['maxlat'] %>
19 <% if params['lon'] and params['lat'] %>
20 <% lon = params['lon'] %>
21 <% lat = params['lat'] %>
22 <% zoom = params['zoom'] || '5' %>
23 <% layers = params['layers'] %>
24 <% elsif params['mlon'] and params['mlat'] %>
25 <% lon = params['mlon'] %>
26 <% lat = params['mlat'] %>
27 <% zoom = params['zoom'] || '12' %>
28 <% layers = params['layers'] %>
29 <% elsif cookies.key?("location") %>
30 <% lon,lat,zoom,layers = cookies["location"].value.first.split(",") %>
31 <% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
32 <% lon = @user.home_lon %>
33 <% lat = @user.home_lat %>
36 <% session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location] %>
37 <% if session[:location] %>
39 <% minlon = session[:location][:minlon] %>
40 <% minlat = session[:location][:minlat] %>
41 <% maxlon = session[:location][:maxlon] %>
42 <% maxlat = session[:location][:maxlat] %>
46 <% zoom = params['zoom'] || '5' %>
47 <% layers = params['layers'] %>
51 <script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
52 <%= javascript_include_tag 'map.js' %>
55 <script type="text/javascript">
57 var brokenContentSize = $("content").offsetWidth == 0;
62 map = createMap("map");
65 var min = lonLatToMercator(new OpenLayers.LonLat(<%= minlon %>, <%= minlat %>));
66 var max = lonLatToMercator(new OpenLayers.LonLat(<%= maxlon %>, <%= maxlat %>));
67 var bbox = new OpenLayers.Bounds(min.lon, min.lat, max.lon, max.lat);
69 map.zoomToExtent(bbox);
71 var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
72 var zoom = <%= zoom %>;
74 <% if params['scale'] and params['scale'].length > 0 then %>
75 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
78 map.setCenter(centre, zoom);
82 marker = addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
86 setMapLayers("<%= layers %>");
89 map.events.register("moveend", map, updateLocation);
95 function setPosition(lat, lon, zoom) {
96 var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
98 map.setCenter(centre, zoom);
101 removeMarkerFromMap(marker);
103 marker = addMarkerToMap(centre);
106 function updateLocation() {
107 var lonlat = mercatorToLonLat(map.getCenter());
108 var zoom = map.getZoom();
109 var layers = getMapLayers();
111 updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
113 document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
116 function resizeContent() {
117 var content = $("content");
118 var rightMargin = parseInt(getStyle(content, "right"));
119 var bottomMargin = parseInt(getStyle(content, "bottom"));
121 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
122 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
125 function resizeMap() {
126 var centre = map.getCenter();
127 var zoom = map.getZoom();
128 var search_results_width = $("search_results").offsetWidth;
130 if (search_results_width > 0) {
131 search_results_width = search_results_width + 5
134 $("map").style.left = (search_results_width) + "px";
135 $("map").style.width = ($("content").offsetWidth - search_results_width) + "px";
136 $("map").style.height = ($("content").offsetHeight - 2) + "px";
138 map.setCenter(centre, zoom);
141 function handleResize() {
142 if (brokenContentSize) {
149 window.onresize = handleResize;
150 window.onload = init;