1 <% content_for :greeting do %>
2 <% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
3 <%= link_to_function 'home', "setPosition(#{@user.home_lat}, #{@user.home_lon}, 10)" %> |
7 <%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
8 <%= render :partial => 'key' %>
9 <%= render :partial => 'search' %>
13 <% if params['mlon'] and params['mlat'] %>
15 <% mlon = params['mlon'] %>
16 <% mlat = params['mlat'] %>
19 <% if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] %>
21 <% minlon = params['minlon'] %>
22 <% minlat = params['minlat'] %>
23 <% maxlon = params['maxlon'] %>
24 <% maxlat = params['maxlat'] %>
27 <% if params['lon'] and params['lat'] %>
28 <% lon = params['lon'] %>
29 <% lat = params['lat'] %>
30 <% zoom = params['zoom'] || '5' %>
31 <% layers = params['layers'] %>
32 <% elsif params['mlon'] and params['mlat'] %>
33 <% lon = params['mlon'] %>
34 <% lat = params['mlat'] %>
35 <% zoom = params['zoom'] || '12' %>
36 <% layers = params['layers'] %>
37 <% elsif cookies.key?("location") %>
38 <% lon,lat,zoom,layers = cookies["location"].value.first.split(",") %>
39 <% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
40 <% lon = @user.home_lon %>
41 <% lat = @user.home_lat %>
44 <% session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location] %>
45 <% if session[:location] %>
47 <% minlon = session[:location][:minlon] %>
48 <% minlat = session[:location][:minlat] %>
49 <% maxlon = session[:location][:maxlon] %>
50 <% maxlat = session[:location][:maxlat] %>
54 <% zoom = params['zoom'] || '5' %>
55 <% layers = params['layers'] %>
59 <script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
60 <%= javascript_include_tag 'map.js' %>
63 <script type="text/javascript">
65 var brokenContentSize = $("content").offsetWidth == 0;
70 map = createMap("map");
73 var min = lonLatToMercator(new OpenLayers.LonLat(<%= minlon %>, <%= minlat %>));
74 var max = lonLatToMercator(new OpenLayers.LonLat(<%= maxlon %>, <%= maxlat %>));
75 var bbox = new OpenLayers.Bounds(min.lon, min.lat, max.lon, max.lat);
77 map.zoomToExtent(bbox);
79 var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
80 var zoom = <%= zoom %>;
82 <% if params['scale'] and params['scale'].length > 0 then %>
83 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
86 map.setCenter(centre, zoom);
90 setMapLayers("<%= layers %>");
94 marker = addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
97 map.events.register("moveend", map, updateLocation);
103 function getPosition() {
104 return mercatorToLonLat(map.getCenter());
107 function setPosition(lat, lon, zoom) {
108 var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
110 map.setCenter(centre, zoom);
113 removeMarkerFromMap(marker);
115 marker = addMarkerToMap(centre, getArrowIcon());
118 function updateLocation() {
119 var lonlat = mercatorToLonLat(map.getCenter());
120 var zoom = map.getZoom();
121 var layers = getMapLayers();
123 updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
125 document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
128 function resizeContent() {
129 var content = $("content");
130 var rightMargin = parseInt(getStyle(content, "right"));
131 var bottomMargin = parseInt(getStyle(content, "bottom"));
133 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
134 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
137 function resizeMap() {
138 var centre = map.getCenter();
139 var zoom = map.getZoom();
140 var sidebar_width = $("sidebar").offsetWidth;
142 if (sidebar_width > 0) {
143 sidebar_width = sidebar_width + 5
146 $("map").style.left = (sidebar_width) + "px";
147 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
148 $("map").style.height = ($("content").offsetHeight - 2) + "px";
150 map.setCenter(centre, zoom);
153 function handleResize() {
154 if (brokenContentSize) {
161 window.onresize = handleResize;
162 window.onload = init;