]> git.openstreetmap.org Git - rails.git/blob - app/views/changeset/_map.html.erb
Extract browse.js static asset
[rails.git] / app / views / changeset / _map.html.erb
1 <%= javascript_include_tag 'map.js' %>
2
3 <div id="changeset_list_map">
4 </div>
5
6 <script type="text/javascript">
7   var highlight;
8
9   function highlightChangeset(id) {
10     var feature = vectors.getFeatureByFid(id);
11     var bounds = feature.geometry.getBounds();
12
13     if (bounds.containsBounds(map.getExtent())) {
14       bounds = map.getExtent().scale(1.1);
15     }
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).addClass("selected");
29   }
30
31   function unHighlightChangeset(id) {
32     vectors.removeFeatures(highlight);
33
34     $("#tr-changeset-" + id).removeClass("selected");
35   }
36
37   $(document).ready(function () {
38     var map = createMap("changeset_list_map", {
39       controls: [
40         new OpenLayers.Control.Navigation(),
41         new OpenLayers.Control.Zoom(),
42         new OpenLayers.Control.SimplePanZoom()
43       ]
44     });
45
46     var bounds = new OpenLayers.Bounds();
47
48     <% @edits.each do |edit| %>
49     <% if edit.has_valid_bbox? %>
50     <% bbox = edit.bbox.to_unscaled %>
51     var minlon = <%= bbox.min_lon %>;
52     var minlat = <%= bbox.min_lat %>;
53     var maxlon = <%= bbox.max_lon %>;
54     var maxlat = <%= bbox.max_lat %>;
55     var bbox = new OpenLayers.Bounds(minlon, minlat, maxlon, maxlat);
56
57     bounds.extend(bbox);
58
59     addBoxToMap(bbox, "<%= edit.id %>", true);
60     <% end %>
61     <% end %>
62
63     vectors.events.on({
64       "featureselected": function(feature) {
65         highlightChangeset(feature.feature.fid);
66       },
67       "featureunselected": function(feature) {
68         unHighlightChangeset(feature.feature.fid);
69       }
70     });
71
72     var selectControl = new OpenLayers.Control.SelectFeature(vectors, {
73       multiple: false,
74       hover: true
75     });
76     map.addControl(selectControl);
77     selectControl.activate();
78
79     <% if ! @bbox.nil? %>
80       map.zoomToExtent(proj(new OpenLayers.Bounds(<%= @bbox %>)));
81     <% else %>
82       map.zoomToExtent(proj(bounds));
83     <% end %>
84   });
85 </script>