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}, 15)", { :title => t('layouts.home_tooltip') } %> |
7 <%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
8 <%= render :partial => 'key' %>
9 <%= render :partial => 'search' %>
13 <p><%= t 'site.index.js_1' %></p>
14 <p><%= t 'site.index.js_2' %></p>
15 <p><%= t 'site.index.js_3' %></p>
21 <a href="/" id="permalinkanchor" class="geolink llz layers object"><%= t 'site.index.permalink' %></a><br/>
22 <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a>
23 <a href="#" id="createnoteanchor">Report a problem</a>
27 <iframe id="linkloader" style="display: none">
30 <div id="attribution">
33 <td class="attribution_license"><%= t'site.index.license.license_url' %></td>
34 <td class="attribution_project"><%= t'site.index.license.project_url' %></td>
37 <td colspan="2" class="attribution_notice"><%=
38 t'site.index.license.notice',
39 :license_name => t('site.index.license.license_name'),
40 :project_name => t('site.index.license.project_name')
47 if params['mlon'] and params['mlat']
49 mlon = h(params['mlon'])
50 mlat = h(params['mlat'])
53 if params['node'] or params['way'] or params['relation']
59 object_id = h(params['node'])
62 object_id = h(params['way'])
63 elsif params['relation']
64 object_type = 'relation'
65 object_id = h(params['relation'])
69 # Decide on a lat lon to initialise the map with. Various ways of doing this
72 minlon, minlat, maxlon, maxlat = h(params['bbox']).split(",")
73 layers = h(params['layers'])
74 box = true if params['box']=="yes"
76 elsif params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
78 minlon = h(params['minlon'])
79 minlat = h(params['minlat'])
80 maxlon = h(params['maxlon'])
81 maxlat = h(params['maxlat'])
82 layers = h(params['layers'])
83 box = true if params['box']=="yes"
85 elsif params['lon'] and params['lat']
86 lon = h(params['lon'])
87 lat = h(params['lat'])
88 zoom = h(params['zoom'] || '5')
89 layers = h(params['layers'])
91 elsif params['mlon'] and params['mlat']
92 lon = h(params['mlon'])
93 lat = h(params['mlat'])
94 zoom = h(params['zoom'] || '12')
95 layers = h(params['layers'])
97 elsif cookies.key?("_osm_location")
98 lon,lat,zoom,layers = cookies["_osm_location"].split("|")
99 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
104 unless STATUS == :database_readonly or STATUS == :database_offline
105 session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
108 if session[:location]
110 minlon = session[:location][:minlon]
111 minlat = session[:location][:minlat]
112 maxlon = session[:location][:maxlon]
113 maxlat = session[:location][:maxlat]
117 zoom = h(params['zoom'] || '5')
120 layers = h(params['layers'])
124 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
125 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
126 <%= javascript_include_tag 'map.js' %>
128 <%= render :partial => 'resize' %>
130 <script type="text/javascript">
134 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
137 var loginName = "<%= @user.display_name %>"
141 map = createMap("map");
143 <% unless STATUS == :api_offline or STATUS == :database_offline %>
144 map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
145 map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
146 map.addLayer(map.dataLayer);
148 map.noteLayer = new OpenLayers.Layer.Vector("Notes", {
150 projection: new OpenLayers.Projection("EPSG:4326"),
151 styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
159 new OpenLayers.Rule({
160 filter: new OpenLayers.Filter.Comparison({
161 type: OpenLayers.Filter.Comparison.EQUAL_TO,
166 externalGraphic: "<%= image_path 'open_note_marker.png' %>"
169 new OpenLayers.Rule({
170 filter: new OpenLayers.Filter.Comparison({
171 type: OpenLayers.Filter.Comparison.EQUAL_TO,
176 externalGraphic: "<%= image_path 'closed_note_marker.png' %>"
182 new OpenLayers.Strategy.BBOX()
184 protocol: new OpenLayers.Protocol.HTTP({
185 url: "<%= url_for :controller => :note, :action => :list, :format => :json %>",
186 format: new OpenLayers.Format.GeoJSON(),
187 callback: noteCallback
190 map.noteLayer.events.register("featureselected", map, noteSelected);
191 map.noteLayer.events.register("featureunselected", map, noteUnselected);
192 map.addLayer(map.noteLayer);
194 var noteControl = new OpenLayers.Control.SelectFeature(map.noteLayer, {
197 map.addControl(noteControl);
199 <% if params[:notes] == "yes" -%>
200 map.noteLayer.setVisibility(true);
203 $("createnoteanchor").observe("click", addNote);
205 map.events.register("zoomend", map, allowNoteReports);
208 <% unless object_zoom %>
210 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
215 Event.observe(window, "load", function() { addBoxToMap(bbox) });
218 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
219 var zoom = <%= zoom %>;
221 <% if params['scale'] and params['scale'].length > 0 then %>
222 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
225 setMapCenter(centre, zoom);
231 <% if !layers.nil? and !layers.empty? %>
232 setMapLayers("<%= layers %>");
236 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
240 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
242 <% if object_type != "node" %>
246 Event.observe(window, "load", function() { addObjectToMap(url, <%= object_zoom %>) });
249 map.events.register("moveend", map, updateLocation);
250 map.events.register("changelayer", map, updateLocation);
255 function toggleData() {
256 if (map.dataLayer.visibility) {
257 <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
258 } else if (map.dataLayer.active) {
263 function getPosition() {
264 return getMapCenter();
271 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
272 var centre = new OpenLayers.LonLat(lon, lat);
274 if (min_lon && min_lat && max_lon && max_lat) {
275 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
279 setMapCenter(centre, zoom);
283 removeMarkerFromMap(marker);
285 marker = addMarkerToMap(centre, getArrowIcon());
288 function updateLocation() {
289 var lonlat = getMapCenter();
290 var zoom = map.getZoom();
291 var layers = getMapLayers();
292 var extents = getMapExtent();
293 var expiry = new Date();
298 objtype = "<%= object_type %>";
299 objid = <%= object_id %>;
302 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
304 expiry.setYear(expiry.getFullYear() + 10);
305 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
308 function remoteEditHandler(event) {
309 var extent = getMapExtent();
312 $("linkloader").observe("load", function () { loaded = true; });
313 $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
315 setTimeout(function () {
316 if (!loaded) alert("<%= escape_javascript(t('site.index.remote_failed')) %>");
322 function installEditHandler() {
323 $("remoteanchor").observe("click", remoteEditHandler);
325 <% if preferred_editor == "remote" %>
326 $("editanchor").observe("click", remoteEditHandler);
328 <% if params[:action] == "edit" %>
334 function noteCallback(scope, response) {
335 for (var f = 0; f < response.features.length; f++) {
336 var feature = response.features[f];
340 function noteSelected(o) {
341 var feature = o.feature;
342 var location = feature.geometry.getBounds().getCenterLonLat();
344 feature.popup = new OpenLayers.Popup.FramedCloud(feature.attributes.id,
346 "<p>" + feature.attributes.id + "</p>",
349 map.addPopup(feature.popup);
350 // feature.popup.show();
353 function noteUnselected(o) {
354 var feature = o.feature;
356 map.removePopup(feature.popup);
357 delete feature.popup;
361 map.noteLayer.setVisibility(true);
362 map.noteLayer.addNote(map.getCenter());
365 function allowNoteReports() {
366 if (map.getZoom() > 11) {
367 $("createnoteanchor").style.visibility = "visible";
369 $("createnoteanchor").style.visibility = "hidden";
373 document.observe("dom:loaded", mapInit);
374 document.observe("dom:loaded", installEditHandler);
375 document.observe("dom:loaded", handleResize);
377 Event.observe(window, "resize", function() {
378 var centre = map.getCenter();
379 var zoom = map.getZoom();
383 map.setCenter(centre, zoom);
386 <% if params['action'] == 'export' %>
387 <%= remote_function :url => { :controller => 'export', :action => 'start' } %>