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">
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);
118 map.events.register("click", map, mapClick);
124 // Map click results in feature lookup
125 function mapClick(e) {
126 var pos = lonLatToNonSphericalMercator
128 (map.getLonLatFromViewPortPx
129 ( map.events.getMousePosition(e))));
131 // put in the freemap url for the moment. this will be replaced
132 // by a ruby equivalent.
134 url= 'http://www.free-map.org.uk/freemap/common/osmlookup.php?'+
135 'action=get&x='+pos.lon+'&y='+pos.lat;
137 OpenLayers.loadURL(url,/null, null,osmLookupCallback);
141 // the feature lookup finds the nearest POI node, or, if no node could
142 // be found, the nearest way
144 function osmLookupCallback (xmlHTTP) {
145 var nodes = xmlHTTP.responseXML.getElementsByTagName('node');
146 var ways = xmlHTTP.responseXML.getElementsByTagName('way');
147 var features = (ways.length==1) ? ways:nodes;
149 if(features.length==1) {
150 var osm_id = features[0].getElementsByTagName('osm_id')[0].
151 firstChild.nodeValue;
153 (xmlHTTP.responseXML.getElementsByTagName('name').length>0) ?
154 xmlHTTP.responseXML.getElementsByTagName('name')[0].
155 firstChild.nodeValue: "";
158 if(this.osm_type=='way' && ways.length==1) {
159 // use openlayers vector layer to highlight way for editing?
166 if(xmlHTTP.responseXML.getElementsByTagName('description').length){
168 xmlHTTP.responseXML.getElementsByTagName('description')[0].
169 firstChild.nodeValue;
171 description += "<p>"+osmdesc+"</p>";
177 function getPosition() {
178 return mercatorToLonLat(map.getCenter());
181 function setPosition(lat, lon, zoom) {
182 var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
184 map.setCenter(centre, zoom);
187 removeMarkerFromMap(marker);
189 marker = addMarkerToMap(centre, getArrowIcon());
192 function updateLocation() {
193 var lonlat = mercatorToLonLat(map.getCenter());
194 var zoom = map.getZoom();
195 var layers = getMapLayers();
197 updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
199 document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
202 function resizeContent() {
203 var content = $("content");
204 var rightMargin = parseInt(getStyle(content, "right"));
205 var bottomMargin = parseInt(getStyle(content, "bottom"));
207 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
208 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
211 function resizeMap() {
212 var centre = map.getCenter();
213 var zoom = map.getZoom();
214 var sidebar_width = $("sidebar").offsetWidth;
216 if (sidebar_width > 0) {
217 sidebar_width = sidebar_width + 5
220 $("map").style.left = (sidebar_width) + "px";
221 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
222 $("map").style.height = ($("content").offsetHeight - 2) + "px";
224 map.setCenter(centre, zoom);
227 function handleResize() {
228 if (brokenContentSize) {
235 window.onresize = handleResize;
236 window.onload = init;