]> git.openstreetmap.org Git - rails.git/blob - app/views/changeset/_map.html.erb
6d7aa96c04fafbafcf95f971e7373b16eb524391
[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   var highlight;
12
13   function highlightChangeset(id) {
14     var feature = vectors.getFeatureByFid(id);
15     var bounds = feature.geometry.getBounds();
16
17     if ( highlight ) vectors.removeFeatures(highlight);
18
19     highlight = new OpenLayers.Feature.Vector(bounds.toGeometry(), {}, {
20       strokeWidth: 2,
21       strokeColor: "#ee9900",
22       fillColor: "#ffff55",
23       fillOpacity: 0.5
24     });
25
26     vectors.addFeatures(highlight);
27
28     $("tr-changeset-" + id).addClassName("selected");
29   }
30
31   function unHighlightChangeset(id) {
32     vectors.removeFeatures(highlight);
33
34     $("tr-changeset-" + id).removeClassName("selected");
35   }
36
37   function init() {
38     var map = createMap("changeset_list_map", {
39       controls: [
40         new OpenLayers.Control.Navigation(),
41         new OpenLayers.Control.PanZoom(),
42         new OpenLayers.Control.PanZoomBar()
43       ]
44     });
45
46     var bounds = new OpenLayers.Bounds();
47
48     <% @edits.each do |edit| %>
49     var minlon = <%= edit.min_lon / GeoRecord::SCALE.to_f %>;
50     var minlat = <%= edit.min_lat / GeoRecord::SCALE.to_f %>;
51     var maxlon = <%= edit.max_lon / GeoRecord::SCALE.to_f %>;
52     var maxlat = <%= edit.max_lat / GeoRecord::SCALE.to_f %>;
53     var bbox = new OpenLayers.Bounds(minlon, minlat, maxlon, maxlat);
54
55     bounds.extend(bbox);
56     box = addBoxToMap(bbox, "<%= edit.id %>", true);
57     <% end %>
58
59     vectors.events.on({
60       "featureselected": function(feature) {
61         highlightChangeset(feature.feature.fid);
62       },
63       "featureunselected": function(feature) {
64         unHighlightChangeset(feature.feature.fid);
65       }
66     });
67
68     var selectControl = new OpenLayers.Control.SelectFeature(vectors, {
69       multiple: false,
70       hover: true
71     });
72     map.addControl(selectControl);
73     selectControl.activate();
74
75     <% if ! @bbox.nil? %>
76       setMapExtent(new OpenLayers.Bounds(<%= @bbox %>));
77     <% else %>
78       setMapExtent(bounds);
79     <% end %>
80   }
81
82   Event.observe(window, "load", init);
83 </script>