]> git.openstreetmap.org Git - rails.git/blob - app/views/changeset/_map.html.erb
Float user image to right correctly on per-user diary listing page
[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   var highlight;
9
10   function highlightChangeset(id) {
11     var feature = vectors.getFeatureByFid(id);
12     var bounds = feature.geometry.getBounds();
13
14     if (bounds.containsBounds(map.getExtent())) {
15       bounds = map.getExtent().scale(1.1);
16     }
17
18     if (highlight) vectors.removeFeatures(highlight);
19
20     highlight = new OpenLayers.Feature.Vector(bounds.toGeometry(), {}, {
21       strokeWidth: 2,
22       strokeColor: "#ee9900",
23       fillColor: "#ffff55",
24       fillOpacity: 0.5
25     });
26
27     vectors.addFeatures(highlight);
28
29     $("#tr-changeset-" + id).addClass("selected");
30   }
31
32   function unHighlightChangeset(id) {
33     vectors.removeFeatures(highlight);
34
35     $("#tr-changeset-" + id).removeClass("selected");
36   }
37
38   $(document).ready(function () {
39     var map = createMap("changeset_list_map", {
40       controls: [
41         new OpenLayers.Control.Navigation(),
42         new OpenLayers.Control.Zoom(),
43         new OpenLayers.Control.SimplePanZoom()
44       ]
45     });
46
47     var bounds = new OpenLayers.Bounds();
48
49     <% @edits.each do |edit| %>
50     <% if edit.has_valid_bbox? %>
51     <% bbox = edit.bbox.to_unscaled %>
52     var minlon = <%= bbox.min_lon %>;
53     var minlat = <%= bbox.min_lat %>;
54     var maxlon = <%= bbox.max_lon %>;
55     var maxlat = <%= bbox.max_lat %>;
56     var bbox = new OpenLayers.Bounds(minlon, minlat, maxlon, maxlat);
57
58     bounds.extend(bbox);
59
60     addBoxToMap(bbox, "<%= edit.id %>", true);
61     <% end %>
62     <% end %>
63
64     vectors.events.on({
65       "featureselected": function(feature) {
66         highlightChangeset(feature.feature.fid);
67       },
68       "featureunselected": function(feature) {
69         unHighlightChangeset(feature.feature.fid);
70       }
71     });
72
73     var selectControl = new OpenLayers.Control.SelectFeature(vectors, {
74       multiple: false,
75       hover: true
76     });
77     map.addControl(selectControl);
78     selectControl.activate();
79
80     <% if ! @bbox.nil? %>
81       map.zoomToExtent(proj(new OpenLayers.Bounds(<%= @bbox %>)));
82     <% else %>
83       map.zoomToExtent(proj(bounds));
84     <% end %>
85   });
86 </script>