1 <% content_for :left_menu do %>
2 <%= link_to "Map key", "http://wiki.openstreetmap.org/index.php/Map_Key" %>
5 <%= render :partial => 'search', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
9 <% if params['mlon'] and params['mlat'] %>
11 <% mlon = params['mlon'] %>
12 <% mlat = params['mlat'] %>
15 <% if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] %>
17 <% minlon = params['minlon'] %>
18 <% minlat = params['minlat'] %>
19 <% maxlon = params['maxlon'] %>
20 <% maxlat = params['maxlat'] %>
23 <% if params['lon'] and params['lat'] %>
24 <% lon = params['lon'] %>
25 <% lat = params['lat'] %>
26 <% zoom = params['zoom'] || '5' %>
27 <% layers = params['layers'] %>
28 <% elsif params['mlon'] and params['mlat'] %>
29 <% lon = params['mlon'] %>
30 <% lat = params['mlat'] %>
31 <% zoom = params['zoom'] || '12' %>
32 <% layers = params['layers'] %>
33 <% elsif cookies.key?("location") %>
34 <% lon,lat,zoom,layers = cookies["location"].value.first.split(",") %>
35 <% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
36 <% lon = @user.home_lon %>
37 <% lat = @user.home_lat %>
40 <% session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location] %>
41 <% if session[:location] %>
43 <% minlon = session[:location][:minlon] %>
44 <% minlat = session[:location][:minlat] %>
45 <% maxlon = session[:location][:maxlon] %>
46 <% maxlat = session[:location][:maxlat] %>
50 <% zoom = params['zoom'] || '5' %>
51 <% layers = params['layers'] %>
55 <script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
56 <%= javascript_include_tag 'map.js' %>
59 <script type="text/javascript">
61 var brokenContentSize = $("content").offsetWidth == 0;
66 map = createMap("map");
69 var min = lonLatToMercator(new OpenLayers.LonLat(<%= minlon %>, <%= minlat %>));
70 var max = lonLatToMercator(new OpenLayers.LonLat(<%= maxlon %>, <%= maxlat %>));
71 var bbox = new OpenLayers.Bounds(min.lon, min.lat, max.lon, max.lat);
73 map.zoomToExtent(bbox);
75 var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
76 var zoom = <%= zoom %>;
78 <% if params['scale'] and params['scale'].length > 0 then %>
79 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
82 map.setCenter(centre, zoom);
86 marker = addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
90 setMapLayers("<%= layers %>");
93 map.events.register("moveend", map, updateLocation);
99 function setPosition(lat, lon, zoom) {
100 var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
102 map.setCenter(centre, zoom);
105 removeMarkerFromMap(marker);
107 marker = addMarkerToMap(centre, getArrowIcon());
110 function updateLocation() {
111 var lonlat = mercatorToLonLat(map.getCenter());
112 var zoom = map.getZoom();
113 var layers = getMapLayers();
115 updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
117 document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
120 function resizeContent() {
121 var content = $("content");
122 var rightMargin = parseInt(getStyle(content, "right"));
123 var bottomMargin = parseInt(getStyle(content, "bottom"));
125 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
126 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
129 function resizeMap() {
130 var centre = map.getCenter();
131 var zoom = map.getZoom();
132 var search_results_width = $("search_results").offsetWidth;
134 if (search_results_width > 0) {
135 search_results_width = search_results_width + 5
138 $("map").style.left = (search_results_width) + "px";
139 $("map").style.width = ($("content").offsetWidth - search_results_width) + "px";
140 $("map").style.height = ($("content").offsetHeight - 2) + "px";
142 map.setCenter(centre, zoom);
145 function handleResize() {
146 if (brokenContentSize) {
153 window.onresize = handleResize;
154 window.onload = init;