-<div id="geocoder">
- <form action="/search.html">
- <input type="text" name="query" value="" size="60">
- <input type="submit" value="Search">
- </form>
-</div>
+<% content_for :left_menu do %>
+<%= link_to "Map key", "http://wiki.openstreetmap.org/index.php/Map_Key" %>
+<% end %>
+
+<%= render :partial => 'search', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
+
+<div id="map"></div>
+
+<% if params['mlon'] and params['mlat'] %>
+<% marker = true %>
+<% mlon = params['mlon'] %>
+<% mlat = params['mlat'] %>
+<% end %>
+
+<% if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] %>
+<% bbox = true %>
+<% minlon = params['minlon'] %>
+<% minlat = params['minlat'] %>
+<% maxlon = params['maxlon'] %>
+<% maxlat = params['maxlat'] %>
+<% end %>
+
+<% if params['lon'] and params['lat'] %>
+<% lon = params['lon'] %>
+<% lat = params['lat'] %>
+<% zoom = params['zoom'] || '5' %>
+<% layers = params['layers'] %>
+<% elsif params['mlon'] and params['mlat'] %>
+<% lon = params['mlon'] %>
+<% lat = params['mlat'] %>
+<% zoom = params['zoom'] || '12' %>
+<% layers = params['layers'] %>
+<% elsif cookies.key?("location") %>
+<% lon,lat,zoom,layers = cookies["location"].value.first.split(",") %>
+<% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
+<% lon = @user.home_lon %>
+<% lat = @user.home_lat %>
+<% zoom = '10' %>
+<% else %>
+<% session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location] %>
+<% if session[:location] %>
+<% bbox = true %>
+<% minlon = session[:location][:minlon] %>
+<% minlat = session[:location][:minlat] %>
+<% maxlon = session[:location][:maxlon] %>
+<% maxlat = session[:location][:maxlat] %>
+<% else %>
+<% lon = '-0.1' %>
+<% lat = '51.5' %>
+<% zoom = params['zoom'] || '5' %>
+<% layers = params['layers'] %>
+<% end %>
+<% end %>
+
+<script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
+<%= javascript_include_tag 'map.js' %>
-<div id="map" style="WIDTH: 700px; HEIGHT: 500px;"></div>
-<script src="lib/OpenLayers.js"></script>
<script type="text/javascript">
<!--
+ var brokenContentSize = $("content").offsetWidth == 0;
+ var marker;
+ var map;
+
function init(){
- var map = new OpenLayers.Map('map');
+ map = createMap("map");
+
+ <% if bbox %>
+ var min = lonLatToMercator(new OpenLayers.LonLat(<%= minlon %>, <%= minlat %>));
+ var max = lonLatToMercator(new OpenLayers.LonLat(<%= maxlon %>, <%= maxlat %>));
+ var bbox = new OpenLayers.Bounds(min.lon, min.lat, max.lon, max.lat);
- var osm_wms = new OpenLayers.Layer.WMS( "OpenStreetMap Streets",
- "http://tile.openstreetmap.org/cgi-bin/mapserv?map=/usr/lib/cgi-bin/steve/osm.map",
- {layers: "default_segment,segments,class_segment",
-transparent: "true", format: "image/png" });
+ map.zoomToExtent(bbox);
+ <% else %>
+ var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
+ var zoom = <%= zoom %>;
- // FIXME this should be landsat.openstreetmap.org
+ <% if params['scale'] and params['scale'].length > 0 then %>
+ zoom = scaleToZoom(<%= params['scale'].to_f() %>);
+ <% end %>
- var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
- "http://wms.jpl.nasa.gov/wms.cgi",
- {layers: "modis,global_mosaic"});
+ map.setCenter(centre, zoom);
+ <% end %>
+ <% if marker %>
+ marker = addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
+ <% end %>
- map.addLayers([jpl_wms, osm_wms]);
- map.zoomToFullExtent();
+ <% if layers %>
+ setMapLayers("<%= layers %>");
+ <% end %>
+
+ map.events.register("moveend", map, updateLocation);
+ updateLocation();
+
+ handleResize();
}
-init();
-// -->
-</script>
+ function setPosition(lat, lon, zoom) {
+ var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
+ map.setCenter(centre, zoom);
-<!--
-<div id="drag" style="WIDTH: 700px; HEIGHT: 500px;">
- <div id='controls'>
- <a id="zoomout" class="mapcontrol"><img src="/images/map_zoomout.png" alt="zoom out"></a>
- <a id="zoomin" class="mapcontrol"> <img src="/images/map_zoomin.png" alt="zoom in"> </a>
- </div>
-</div>
-
-<div id="debuginfo"></div>
--->
-<% unless @user %>
-<div id="gads">
- <script type="text/javascript"><!--
- google_ad_client = "pub-7727744269903103";
- google_ad_width = 728;
- google_ad_height = 90;
- google_ad_format = "728x90_as";
- google_ad_type = "text";
- google_ad_channel ="";
- google_color_border = "CCCCCC";
- google_color_bg = "FFFFFF";
- google_color_link = "000000";
- google_color_url = "000080";
- google_color_text = "000000";
- //--></script><script type="text/javascript"
- src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
- </script>We're trialing adverts to support the project. Login and they go away.
- </div>
- <% end %>
+ if (marker)
+ removeMarkerFromMap(marker);
- <!--
- <script type="text/javascript">
- lat = 0;
- lon = 0;
- zoom = 0;
+ marker = addMarkerToMap(centre, getArrowIcon());
+ }
+
+ function updateLocation() {
+ var lonlat = mercatorToLonLat(map.getCenter());
+ var zoom = map.getZoom();
+ var layers = getMapLayers();
- init();
- </script>
+ updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
- -->
+ document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
+ }
+
+ function resizeContent() {
+ var content = $("content");
+ var rightMargin = parseInt(getStyle(content, "right"));
+ var bottomMargin = parseInt(getStyle(content, "bottom"));
+
+ content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
+ content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
+ }
+
+ function resizeMap() {
+ var centre = map.getCenter();
+ var zoom = map.getZoom();
+ var search_results_width = $("search_results").offsetWidth;
+
+ if (search_results_width > 0) {
+ search_results_width = search_results_width + 5
+ }
+
+ $("map").style.left = (search_results_width) + "px";
+ $("map").style.width = ($("content").offsetWidth - search_results_width) + "px";
+ $("map").style.height = ($("content").offsetHeight - 2) + "px";
+
+ map.setCenter(centre, zoom);
+ }
+
+ function handleResize() {
+ if (brokenContentSize) {
+ resizeContent();
+ }
+
+ resizeMap();
+ }
+
+ window.onresize = handleResize;
+ window.onload = init;
+// -->
+</script>