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 <% 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 setMapLayers("<%= layers %>");
96 marker = addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
99 map.events.register("moveend", map, updateLocation);
105 function getPosition() {
106 return mercatorToLonLat(map.getCenter());
109 function setPosition(lat, lon, zoom) {
110 var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
112 map.setCenter(centre, zoom);
115 removeMarkerFromMap(marker);
117 marker = addMarkerToMap(centre, getArrowIcon());
120 function updateLocation() {
121 var lonlat = mercatorToLonLat(map.getCenter());
122 var zoom = map.getZoom();
123 var layers = getMapLayers();
125 updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
127 document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
130 function resizeContent() {
131 var content = $("content");
132 var rightMargin = parseInt(getStyle(content, "right"));
133 var bottomMargin = parseInt(getStyle(content, "bottom"));
135 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
136 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
139 function resizeMap() {
140 var centre = map.getCenter();
141 var zoom = map.getZoom();
142 var search_results_width = $("search_results").offsetWidth;
144 if (search_results_width > 0) {
145 search_results_width = search_results_width + 5
148 $("map").style.left = (search_results_width) + "px";
149 $("map").style.width = ($("content").offsetWidth - search_results_width) + "px";
150 $("map").style.height = ($("content").offsetHeight - 2) + "px";
152 map.setCenter(centre, zoom);
155 function handleResize() {
156 if (brokenContentSize) {
163 window.onresize = handleResize;
164 window.onload = init;