]> git.openstreetmap.org Git - rails.git/blob - app/views/changeset/_map.html.erb
d0d65d9d77153bd85a31a6a0e3ac72e77efa1246
[rails.git] / app / views / changeset / _map.html.erb
1 <%= javascript_include_tag 'openlayers.js' %>
2 <%= javascript_include_tag 'map.js' %>
3
4 <div id="changeset_list_map">
5 </div>
6
7 <script type="text/javascript">
8   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
9
10   var highlight;
11
12   function highlightChangeset(id) {
13     var feature = vectors.getFeatureByFid(id);
14     var bounds = feature.geometry.getBounds();
15
16     if (bounds.containsBounds(map.getExtent())) {
17       bounds = map.getExtent().scale(1.1);
18     }
19
20     if (highlight) vectors.removeFeatures(highlight);
21
22     highlight = new OpenLayers.Feature.Vector(bounds.toGeometry(), {}, {
23       strokeWidth: 2,
24       strokeColor: "#ee9900",
25       fillColor: "#ffff55",
26       fillOpacity: 0.5
27     });
28
29     vectors.addFeatures(highlight);
30
31     $("#tr-changeset-" + id).addClass("selected");
32   }
33
34   function unHighlightChangeset(id) {
35     vectors.removeFeatures(highlight);
36
37     $("#tr-changeset-" + id).removeClass("selected");
38   }
39
40   function init() {
41     var map = createMap("changeset_list_map", {
42       controls: [
43         new OpenLayers.Control.Navigation(),
44         new OpenLayers.Control.PanZoom(),
45         new OpenLayers.Control.PanZoomBar()
46       ]
47     });
48
49     var bounds = new OpenLayers.Bounds();
50
51     <% @edits.each do |edit| %>
52     <% if edit.has_valid_bbox? %>
53     <% bbox = edit.bbox.to_unscaled %>
54     var minlon = <%= bbox.min_lon %>;
55     var minlat = <%= bbox.min_lat %>;
56     var maxlon = <%= bbox.max_lon %>;
57     var maxlat = <%= bbox.max_lat %>;
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>