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