source: subversion/sites/rails_port/app/views/site/index.html.erb @ 16101

Revision 16101, 6.3 KB checked in by tomhughes, 5 years ago (diff)

Rework the translatable map key to be driven by a YAML file listing the
entries to show for each layer and zoom level.

Line 
1<% content_for :greeting do %>
2<% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
3  <%= link_to_function t('layouts.home'), "setPosition(#{@user.home_lat}, #{@user.home_lon}, 10)", { :title => t('layouts.home_tooltip') } %> |
4<% end %>
5<% end %>
6
7<%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
8<%= render :partial => 'key' %>
9<%= render :partial => 'search' %>
10
11<noscript>
12  <div id="noscript">
13    <p><%= t 'site.index.js_1' %></p>
14    <p><%= t 'site.index.js_2' %></p>
15    <p><%= t 'site.index.js_3' %></p>
16  </div>
17</noscript>
18
19<div id="map">
20<div id="permalink"><a href="/" id="permalinkanchor"><%= t 'site.index.permalink' %></a></div>
21</div>
22
23<div id="attribution">
24  <table width="100%">
25    <tr>
26      <td align="left"><%= t'site.index.license.license_url' %></td>
27      <td align="right"><%= t'site.index.license.project_url' %></td>
28    </tr>
29    <tr>
30      <td colspan="2" align="center"><%=
31        t'site.index.license.notice',
32          :license_name => t('site.index.license.license_name'),
33          :project_name => t('site.index.license.project_name')
34        %></td>
35    </tr>
36  </table>
37</div>
38
39<%
40if params['mlon'] and params['mlat']
41        marker = true
42        mlon = h(params['mlon'])
43        mlat = h(params['mlat'])
44end
45
46if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
47        bbox = true
48        minlon = h(params['minlon'])
49        minlat = h(params['minlat'])
50        maxlon = h(params['maxlon'])
51        maxlat = h(params['maxlat'])
52        box = true if params['box']=="yes"
53end
54
55# Decide on a lat lon to initialise the map with. Various ways of doing this
56if params['lon'] and params['lat']
57        lon =  h(params['lon'])
58        lat =  h(params['lat'])
59        zoom =  h(params['zoom'] || '5')
60        layers = h(params['layers'])
61       
62elsif params['mlon'] and params['mlat']
63        lon = h(params['mlon'])
64        lat = h(params['mlat'])
65        zoom =  h(params['zoom'] || '12')
66        layers = h(params['layers'])
67       
68elsif cookies.key?("_osm_location")
69        lon,lat,zoom,layers = cookies["_osm_location"].split("|")
70       
71elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
72        lon =  @user.home_lon
73        lat =  @user.home_lat
74        zoom = '10'
75else
76        session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
77
78        if session[:location]
79                bbox = true
80                minlon = session[:location][:minlon]
81                minlat = session[:location][:minlat]
82                maxlon = session[:location][:maxlon]
83                maxlat = session[:location][:maxlat]
84        else
85                lon =  '-0.1'
86                lat =  '51.5'
87                zoom =  h(params['zoom'] || '5')
88        end
89        layers = h(params['layers'])
90end
91%>
92
93<%= javascript_include_tag '/openlayers/OpenLayers.js' %>
94<%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
95<%= javascript_include_tag 'map.js' %>
96
97
98<script type="text/javascript" defer="defer">
99  <!--
100  var brokenContentSize = $("content").offsetWidth == 0;
101  var marker;
102  var map;
103
104  OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
105
106  function mapInit(){
107    map = createMap("map");
108
109    <% unless OSM_STATUS == :api_offline or OSM_STATUS == :database_offline %>
110    map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
111    map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
112    map.addLayer(map.dataLayer);
113    <% end %>
114
115    <% if bbox %>
116    var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
117
118    setMapExtent(bbox);
119    <%    if box %>
120    // IE requires Vector layers be initialised on page load, and not under deferred script conditions
121    Event.observe(window, 'load', function() {addBoxToMap(bbox)});
122    <%    end %>
123    <% else %>
124    var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
125    var zoom = <%= zoom %>;
126
127    <%    if params['scale'] and params['scale'].length > 0 then %>
128    zoom = scaleToZoom(<%= params['scale'].to_f() %>);
129    <%    end %>
130
131    setMapCenter(centre, zoom);
132    <% end %>
133
134    <% if !layers.nil? and !layers.empty? %>
135    setMapLayers("<%= layers %>");
136    <% end %>
137
138    <% if marker %>
139    marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
140    <% end %>
141
142    map.events.register("moveend", map, updateLocation);
143    map.events.register("changelayer", map, updateLocation);
144    updateLocation();
145
146    handleResize();
147  }
148
149  function toggleData() {
150    if (map.dataLayer.visibility) {
151      <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
152    } else {
153      closeSidebar();
154    }
155  }
156
157  function getPosition() {
158    return getMapCenter();
159  }
160
161  function setPosition(lat, lon, zoom) {
162    var centre = new OpenLayers.LonLat(lon, lat);
163
164    setMapCenter(centre, zoom);
165
166    if (marker)
167      removeMarkerFromMap(marker);
168
169    marker = addMarkerToMap(centre, getArrowIcon());
170  }
171
172  function updateLocation() {
173    var lonlat = getMapCenter();
174    var zoom = map.getZoom();
175    var layers = getMapLayers();
176    var extents = getMapExtent();
177    var expiry = new Date();
178
179    updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top);
180
181    expiry.setYear(expiry.getFullYear() + 10);
182    document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
183  }
184
185  function resizeContent() {
186    var content = $("content");
187    var rightMargin = parseInt(getStyle(content, "right"));
188    var bottomMargin = parseInt(getStyle(content, "bottom"));
189
190    content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
191    content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
192  }
193 
194  function resizeMap() {
195    var centre = map.getCenter();
196    var zoom = map.getZoom();
197    var sidebar_width = $("sidebar").offsetWidth;
198
199    if (sidebar_width > 0) {
200      sidebar_width = sidebar_width + 5
201    }
202
203    $("map").style.left = (sidebar_width) + "px";
204    $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
205    $("map").style.height = ($("content").offsetHeight - 2) + "px";
206
207    map.setCenter(centre, zoom);
208  }
209
210  function handleResize() {
211    if (brokenContentSize) {
212      resizeContent();
213    }
214
215    resizeMap();
216  }
217 
218  mapInit();
219
220  window.onload = handleResize;
221  window.onresize = handleResize;
222
223  <% if params['action'] == 'export' %>
224  <%= remote_function :url => { :controller => 'export', :action => 'start' } %>
225  <% end %>
226// -->
227</script>
Note: See TracBrowser for help on using the repository browser.