]> git.openstreetmap.org Git - rails.git/blob - app/views/changeset/_map.html.erb
ddfac9f54ba9c200b71ac1d080a3e238555bbeea
[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 <div id="browse_map_changeset">
5   <div id="small_map">
6   </div>
7   <span id="loading"><%= t 'browse.map.loading' %></span>
8 </div>
9 <script type="text/javascript">
10   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
11
12   /*
13     This function borrowed from the latest version of OpenLayers.Layer.Vector. OSM is using an older version.
14     http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Layer/Vector.js
15   */
16   function getFeaturesByAttribute(obj, attrName, attrValue) {
17         var i,
18             feature,    
19             len = obj.features.length,
20             foundFeatures = [];
21         for(i = 0; i < len; i++) {            
22             feature = obj.features[i];
23             if(feature && feature.attributes) {
24                 if (feature.attributes[attrName] === attrValue) {
25                     foundFeatures.push(feature);
26                 }
27             }
28         }
29         return foundFeatures;
30   }
31   function highlightChangesetMap(name) {
32     getFeaturesByAttribute(vectors,'name',name)[0].style.strokeColor='#ffff55';
33     vectors.redraw(); 
34   } 
35   function unHighlightChangesetMap(name) {
36     getFeaturesByAttribute(vectors,'name',name)[0].style.strokeColor='#ee9900';
37     vectors.redraw(); 
38   }      
39   function init() {
40     var map = createMap("small_map", {
41       controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoom(), new OpenLayers.Control.PanZoomBar() ]
42     });
43     
44     var bounds = new OpenLayers.Bounds();
45     <%= render :partial => 'changeset_map_add', :collection => @edits unless @edits.nil? %>
46      
47     vectors.events.on({
48       'featureselected': function(feature) {
49          document.getElementById('tr-' + feature.feature.attributes['name']).style.backgroundColor = '#ffff55';
50          feature.feature.style.strokeColor='#ffff00';
51          vectors.redraw();
52        },
53        'featureunselected': function(feature) {
54          document.getElementById('tr-' + feature.feature.attributes['name']).style.backgroundColor = '';
55          feature.feature.style.strokeColor='#ee9900';
56          vectors.redraw();
57        }
58     });
59     var selectControl = new OpenLayers.Control.SelectFeature(vectors,
60       {multiple: false, hover:true});
61     map.addControl(selectControl);
62     selectControl.activate();
63
64     <!-- if bounds were passed, just use those -->
65     <% if ! @bbox.nil? %>
66       bounds = new OpenLayers.Bounds(<%= @bbox %>);
67     <% end %>
68     setMapExtent(bounds);
69
70     $("loading").innerHTML = "";
71   }
72
73   window.onload = init;
74 </script>