]> git.openstreetmap.org Git - rails.git/blob - app/views/browse/_map.html.erb
User errors.add(:base) instead of the removed errors.add_to_base()
[rails.git] / app / views / browse / _map.html.erb
1 <%= javascript_include_tag 'openlayers.js' %>
2 <%= javascript_include_tag 'map.js' %>
3
4 <iframe id="linkloader" style="display: none">
5 </iframe>
6
7 <div id="browse_map">
8   <% if map.instance_of? Changeset or (map.instance_of? Node and map.version > 1) or map.visible? %>
9   <div id="small_map">
10   </div>
11   <span id="loading"><%= t 'browse.map.loading' %></span>
12   <% if map.instance_of? Note -%>
13   <%= link_to(t("browse.map.larger.area"), { :controller => :site, :action => :index, :notes => "yes" }, { :id => "area_larger_map", :class => "geolink bbox" }) %>
14   <% else -%>
15   <%= link_to(t("browse.map.larger.area"), { :controller => :site, :action => :index, :box => "yes" }, { :id => "area_larger_map", :class => "geolink bbox" }) %>
16   <% end -%>
17   <br />
18   <%= link_to(t("browse.map.edit.area"), { :controller => :site, :action => :edit }, { :id => "area_edit", :class => "geolink bbox" }) %>
19   <% unless map.instance_of? Changeset or map.instance_of? Note %>
20     <br />
21     <%= link_to("", { :controller => :site, :action => :index }, { :id => "object_larger_map", :class => "geolink object" }) %>
22     <br />
23     <%= link_to("", { :controller => :site, :action => :edit }, { :id => "object_edit", :class => "geolink object" }) %>
24   <% end %>
25   <% else %>
26     <%= t 'browse.map.deleted' %>
27   <% end %>
28 </div>
29
30 <div id="area_edit_menu" class="menu">
31   <ul>
32     <% Editors::ALL_EDITORS.each do |editor| %>
33       <li><%= link_to t('layouts.edit_with', :editor => t("editor.#{editor}.description")), { :controller => :site, :action => :edit, :editor => editor }, { :id => "#{editor}_area_edit", :class => "geolink bbox" } %></li>
34     <% end %>
35   </ul>
36 </div>
37
38 <div id="object_edit_menu" class="menu">
39   <ul>
40     <% Editors::ALL_EDITORS.each do |editor| %>
41       <li><%= link_to t('layouts.edit_with', :editor => t("editor.#{editor}.description")), { :controller => :site, :action => :edit, :editor => editor }, { :id => "#{editor}_object_edit", :class => "geolink object" } %></li>
42     <% end %>
43   </ul>
44 </div>
45
46 <% if map.instance_of? Changeset or (map.instance_of? Node and map.version > 1) or map.visible? %>
47   <script type="text/javascript">
48     OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
49
50     function remoteEditHandler(event, bbox, select) {
51       var left = bbox.left - 0.0001;
52       var top = bbox.top + 0.0001;
53       var right = bbox.right + 0.0001;
54       var bottom = bbox.bottom - 0.0001;
55       var loaded = false;
56
57       $("#linkloader").load(function () { loaded = true; });
58
59       if (select) {
60         $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + left + "&top=" + top + "&right=" + right + "&bottom=" + bottom + "&select=" + select);
61       } else {
62         $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + left + "&top=" + top + "&right=" + right + "&bottom=" + bottom);
63       }
64
65       setTimeout(function () {
66         if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
67       }, 1000);
68
69       return false;
70     }
71
72     function init() {
73       var map = createMap("small_map", {
74         controls: [ new OpenLayers.Control.Navigation() ]
75       });
76
77       <% if map.instance_of? Changeset -%>
78         <% bbox = map.bbox.to_unscaled %>
79         var minlon = <%= bbox.min_lon %>;
80         var minlat = <%= bbox.min_lat %>;
81         var maxlon = <%= bbox.max_lon %>;
82         var maxlat = <%= bbox.max_lat %>;
83         var bbox = new OpenLayers.Bounds(minlon, minlat, maxlon, maxlat);
84         var centre = bbox.getCenterLonLat();
85
86         setMapExtent(bbox);
87         addBoxToMap(bbox);
88
89         $("#loading").hide();
90         $("#browse_map .geolink").show();
91
92         $("#remote_area_edit").click(function (event) {
93           return remoteEditHandler(event, bbox);
94         });
95
96         <% if preferred_editor == "remote" -%>
97         $("#area_edit").click(function (event) {
98           return remoteEditHandler(event, bbox);
99         });
100         <% end -%>
101
102         updatelinks(centre.lon, centre.lat, 16, null, minlon, minlat, maxlon, maxlat)
103       <% elsif map.instance_of? Note %>
104         var centre = new OpenLayers.LonLat(<%= map.lon %>, <%= map.lat %>);
105
106         setMapCenter(centre, 16);
107         addMarkerToMap(centre);
108
109         var bbox = getMapExtent();
110
111         $("#loading").hide();
112         $("#browse_map .geolink").show();
113
114         $("#remote_area_edit").click(function (event) {
115           return remoteEditHandler(event, bbox);
116         });
117
118         <% if preferred_editor == "remote" -%>
119         $("#area_edit").click(function (event) {
120           return remoteEditHandler(event, bbox);
121         });
122         <% end -%>
123
124         updatelinks(centre.lon, centre.lat, 16, null, bbox.left, bbox.bottom, bbox.right, bbox.top)
125       <% else %>
126         var obj_type = "<%= map.class.name.downcase %>";
127         var obj_id = <%= map.id %>;
128         var obj_version = <%= map.version %>;
129         var obj_visible = <%= map.visible %>;
130         var url = "/api/<%= API_VERSION %>/<%= map.class.name.downcase %>/<%= map.id %>";
131
132         if (obj_type != "node") {
133           url += "/full";
134         } else if (!obj_visible) {
135           var previous_version = obj_version - 1;
136           url += "/" + previous_version;
137         }
138
139         addObjectToMap(url, true, function(extent) {
140           $("#loading").hide();
141           $("#browse_map .geolink").show();
142
143           if (extent) {
144             extent.transform(map.getProjectionObject(), map.displayProjection);
145
146             var centre = extent.getCenterLonLat();
147
148             $("#remote_area_edit").click(function (event) {
149               return remoteEditHandler(event, extent);
150             });
151
152             <% if preferred_editor == "remote" -%>
153             $("#area_edit").click(function (event) {
154               return remoteEditHandler(event, extent);
155             });
156             <% end -%>
157
158             <% unless map.instance_of? Changeset -%>
159             $("#remote_object_edit").click(function (event) {
160               return remoteEditHandler(event, extent, "<%= map.class.to_s.downcase + map.id.to_s %>");
161             });
162
163             <% if preferred_editor == "remote" -%>
164             $("#object_edit").click(function (event) {
165               return remoteEditHandler(event, extent, "<%= map.class.to_s.downcase + map.id.to_s %>");
166             });
167             <% end -%>
168
169             $("#object_larger_map").html("<%=j t('browse.map.larger.' + map.class.to_s.downcase) %>");
170             $("#object_edit").html("<%=j t('browse.map.edit.' + map.class.to_s.downcase) %>");
171             <% end -%>
172
173             updatelinks(centre.lon, centre.lat, 16, null, extent.left, extent.bottom, extent.right, extent.top, "<%= map.class.to_s.downcase %>", <%= map.id %>);
174           } else {
175             $("#small_map").hide();
176           }
177         });
178       <% end -%>
179
180       createMenu("area_edit", "area_edit_menu", 1000, "right");
181       createMenu("object_edit", "object_edit_menu", 1000, "right");
182     }
183
184     window.onload = init;
185   </script>
186 <% end %>