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