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