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' %>
12 <div id="permalink"><a href="/" id="permalinkanchor">Permalink</a></div>
15 <div id="attribution">
18 <td align="left">http://creativecommons.org/licenses/by-sa/2.0/</td>
19 <td align="right">http://openstreetmap.org/</td>
22 <td colspan="2" align="center">
23 Licensed under the Creative Commons Attribution-Share Alike 2.0 license
24 by the OpenStreetMap project and it's contributors.
29 <% if params['mlon'] and params['mlat'] %>
31 <% mlon = h(params['mlon']) %>
32 <% mlat = h(params['mlat']) %>
35 <% if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] %>
37 <% minlon = h(params['minlon']) %>
38 <% minlat = h(params['minlat']) %>
39 <% maxlon = h(params['maxlon']) %>
40 <% maxlat = h(params['maxlat']) %>
43 <% if params['lon'] and params['lat'] %>
44 <% lon = h(params['lon']) %>
45 <% lat = h(params['lat']) %>
46 <% zoom = h(params['zoom'] || '5') %>
47 <% layers = h(params['layers']) %>
48 <% elsif params['mlon'] and params['mlat'] %>
49 <% lon = h(params['mlon']) %>
50 <% lat = h(params['mlat']) %>
51 <% zoom = h(params['zoom'] || '12') %>
52 <% layers = h(params['layers']) %>
53 <% elsif cookies.key?("location") %>
54 <% lon,lat,zoom,layers = cookies["location"].split(",") %>
55 <% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
56 <% lon = @user.home_lon %>
57 <% lat = @user.home_lat %>
60 <% session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location] %>
61 <% if session[:location] %>
63 <% minlon = session[:location][:minlon] %>
64 <% minlat = session[:location][:minlat] %>
65 <% maxlon = session[:location][:maxlon] %>
66 <% maxlat = session[:location][:maxlat] %>
70 <% zoom = h(params['zoom'] || '5') %>
71 <% layers = h(params['layers']) %>
75 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
76 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
77 <%= javascript_include_tag 'map.js' %>
80 <script type="text/javascript" defer="defer">
82 var brokenContentSize = $("content").offsetWidth == 0;
87 map = createMap("map");
90 var min = lonLatToMercator(new OpenLayers.LonLat(<%= minlon %>, <%= minlat %>));
91 var max = lonLatToMercator(new OpenLayers.LonLat(<%= maxlon %>, <%= maxlat %>));
92 var bbox = new OpenLayers.Bounds(min.lon, min.lat, max.lon, max.lat);
94 map.zoomToExtent(bbox);
96 var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
97 var zoom = <%= zoom %>;
99 <% if params['scale'] and params['scale'].length > 0 then %>
100 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
103 map.setCenter(centre, zoom);
107 setMapLayers("<%= layers %>");
111 marker = addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
114 map.events.register("zoomend", map, updateKey);
116 map.events.register("moveend", map, updateLocation);
117 map.events.register("changelayer", map, updateLocation);
123 function getPosition() {
124 return mercatorToLonLat(map.getCenter());
127 function setPosition(lat, lon, zoom) {
128 var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
130 map.setCenter(centre, zoom);
133 removeMarkerFromMap(marker);
135 marker = addMarkerToMap(centre, getArrowIcon());
138 function updateLocation() {
139 var lonlat = mercatorToLonLat(map.getCenter());
140 var zoom = map.getZoom();
141 var layers = getMapLayers();
143 updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
145 document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
148 function resizeContent() {
149 var content = $("content");
150 var rightMargin = parseInt(getStyle(content, "right"));
151 var bottomMargin = parseInt(getStyle(content, "bottom"));
153 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
154 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
157 function resizeMap() {
158 var centre = map.getCenter();
159 var zoom = map.getZoom();
160 var sidebar_width = $("sidebar").offsetWidth;
162 if (sidebar_width > 0) {
163 sidebar_width = sidebar_width + 5
166 $("map").style.left = (sidebar_width) + "px";
167 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
168 $("map").style.height = ($("content").offsetHeight - 2) + "px";
170 map.setCenter(centre, zoom);
173 function handleResize() {
174 if (brokenContentSize) {
183 window.onload = handleResize;
184 window.onresize = handleResize;