1 <% content_for :greeting do %>
2 <% if !@user.home_lon.nil? and !@user.home_lat.nil? %>
3 <%= link_to_function 'home', "setPosition(#{@user.home_lat}, #{@user.home_lon}, 10)" %> |
7 <% content_for :left_menu do %>
8 <%= link_to "Map key", "http://wiki.openstreetmap.org/index.php/Map_Key" %>
11 <%= render :partial => 'search', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
15 <% if params['mlon'] and params['mlat'] %>
17 <% mlon = params['mlon'] %>
18 <% mlat = params['mlat'] %>
21 <% if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] %>
23 <% minlon = params['minlon'] %>
24 <% minlat = params['minlat'] %>
25 <% maxlon = params['maxlon'] %>
26 <% maxlat = params['maxlat'] %>
29 <% if params['lon'] and params['lat'] %>
30 <% lon = params['lon'] %>
31 <% lat = params['lat'] %>
32 <% zoom = params['zoom'] || '5' %>
33 <% layers = params['layers'] %>
34 <% elsif params['mlon'] and params['mlat'] %>
35 <% lon = params['mlon'] %>
36 <% lat = params['mlat'] %>
37 <% zoom = params['zoom'] || '12' %>
38 <% layers = params['layers'] %>
39 <% elsif cookies.key?("location") %>
40 <% lon,lat,zoom,layers = cookies["location"].value.first.split(",") %>
41 <% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
42 <% lon = @user.home_lon %>
43 <% lat = @user.home_lat %>
46 <% session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location] %>
47 <% if session[:location] %>
49 <% minlon = session[:location][:minlon] %>
50 <% minlat = session[:location][:minlat] %>
51 <% maxlon = session[:location][:maxlon] %>
52 <% maxlat = session[:location][:maxlat] %>
56 <% zoom = params['zoom'] || '5' %>
57 <% layers = params['layers'] %>
61 <script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
62 <%= javascript_include_tag 'map.js' %>
65 <script type="text/javascript">
67 var brokenContentSize = $("content").offsetWidth == 0;
72 map = createMap("map");
75 var min = lonLatToMercator(new OpenLayers.LonLat(<%= minlon %>, <%= minlat %>));
76 var max = lonLatToMercator(new OpenLayers.LonLat(<%= maxlon %>, <%= maxlat %>));
77 var bbox = new OpenLayers.Bounds(min.lon, min.lat, max.lon, max.lat);
79 map.zoomToExtent(bbox);
81 var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
82 var zoom = <%= zoom %>;
84 <% if params['scale'] and params['scale'].length > 0 then %>
85 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
88 map.setCenter(centre, zoom);
92 marker = addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
96 setMapLayers("<%= layers %>");
99 map.events.register("moveend", map, updateLocation);
105 function setPosition(lat, lon, zoom) {
106 var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
108 map.setCenter(centre, zoom);
111 removeMarkerFromMap(marker);
113 marker = addMarkerToMap(centre, getArrowIcon());
116 function updateLocation() {
117 var lonlat = mercatorToLonLat(map.getCenter());
118 var zoom = map.getZoom();
119 var layers = getMapLayers();
121 updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
123 document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
126 function resizeContent() {
127 var content = $("content");
128 var rightMargin = parseInt(getStyle(content, "right"));
129 var bottomMargin = parseInt(getStyle(content, "bottom"));
131 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
132 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
135 function resizeMap() {
136 var centre = map.getCenter();
137 var zoom = map.getZoom();
138 var search_results_width = $("search_results").offsetWidth;
140 if (search_results_width > 0) {
141 search_results_width = search_results_width + 5
144 $("map").style.left = (search_results_width) + "px";
145 $("map").style.width = ($("content").offsetWidth - search_results_width) + "px";
146 $("map").style.height = ($("content").offsetHeight - 2) + "px";
148 map.setCenter(centre, zoom);
151 function handleResize() {
152 if (brokenContentSize) {
159 window.onresize = handleResize;
160 window.onload = init;