]> git.openstreetmap.org Git - rails.git/blob - app/views/changeset/_map.html.erb
fe934bbc754969bdb228524c919fb7cdd5c2de28
[rails.git] / app / views / changeset / _map.html.erb
1 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
2 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
3 <%= javascript_include_tag 'map.js' %>
4
5 <div id="changeset_list_map">
6 </div>
7
8 <script type="text/javascript">
9   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
10
11   function highlightChangeset(id) {
12     var feature = vectors.getFeatureByFid(id);
13     feature.style.strokeColor = "#ffff55";
14     feature.style.strokeWidth = 4;
15     vectors.redraw(); 
16
17     $("tr-changeset-" + id).addClassName("selected");
18   } 
19
20   function unHighlightChangeset(id) {
21     var feature = vectors.getFeatureByFid(id);
22     feature.style.strokeColor = "#ee9900";
23     feature.style.strokeWidth = 2;
24     vectors.redraw(); 
25
26     $("tr-changeset-" + id).removeClassName("selected");
27   }      
28
29   function init() {
30     var map = createMap("changeset_list_map", {
31       controls: [
32         new OpenLayers.Control.Navigation(),
33         new OpenLayers.Control.PanZoom(),
34         new OpenLayers.Control.PanZoomBar()
35       ]
36     });
37     
38     var bounds = new OpenLayers.Bounds();
39
40     <% @edits.each do |edit| %>
41     var minlon = <%= edit.min_lon / GeoRecord::SCALE.to_f %>;
42     var minlat = <%= edit.min_lat / GeoRecord::SCALE.to_f %>;
43     var maxlon = <%= edit.max_lon / GeoRecord::SCALE.to_f %>;
44     var maxlat = <%= edit.max_lat / GeoRecord::SCALE.to_f %>;
45     var bbox = new OpenLayers.Bounds(minlon, minlat, maxlon, maxlat);
46
47     bounds.extend(bbox);
48     box = addBoxToMap(bbox, "<%= edit.id %>", true);
49     <% end %>
50      
51     vectors.events.on({
52       "featureselected": function(feature) {
53         highlightChangeset(feature.feature.fid);
54       },
55       "featureunselected": function(feature) {
56         unHighlightChangeset(feature.feature.fid);
57       }
58     });
59
60     var selectControl = new OpenLayers.Control.SelectFeature(vectors, {
61       multiple: false, 
62       hover: true
63     });
64     map.addControl(selectControl);
65     selectControl.activate();
66
67     <% if ! @bbox.nil? %>
68       setMapExtent(new OpenLayers.Bounds(<%= @bbox %>));
69     <% else %>
70       setMapExtent(bounds);
71     <% end %>
72   }
73
74   Event.observe(window, "load", init);
75 </script>