]> git.openstreetmap.org Git - rails.git/blobdiff - app/views/changeset/_map.html.erb
Make spam scoring work with new rich text system
[rails.git] / app / views / changeset / _map.html.erb
index ddfac9f54ba9c200b71ac1d080a3e238555bbeea..88dd53c99a8e7847ee51119148bca318ea72405a 100644 (file)
@@ -1,74 +1,90 @@
-<%= javascript_include_tag '/openlayers/OpenLayers.js' %>
-<%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
+<%= javascript_include_tag 'openlayers.js' %>
 <%= javascript_include_tag 'map.js' %>
 <%= javascript_include_tag 'map.js' %>
-<div id="browse_map_changeset">
-  <div id="small_map">
-  </div>
-  <span id="loading"><%= t 'browse.map.loading' %></span>
+
+<div id="changeset_list_map">
 </div>
 </div>
+
 <script type="text/javascript">
   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
 
 <script type="text/javascript">
   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
 
-  /*
-    This function borrowed from the latest version of OpenLayers.Layer.Vector. OSM is using an older version.
-    http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Layer/Vector.js
-  */
-  function getFeaturesByAttribute(obj, attrName, attrValue) {
-        var i,
-            feature,    
-            len = obj.features.length,
-            foundFeatures = [];
-        for(i = 0; i < len; i++) {            
-            feature = obj.features[i];
-            if(feature && feature.attributes) {
-                if (feature.attributes[attrName] === attrValue) {
-                    foundFeatures.push(feature);
-                }
-            }
-        }
-        return foundFeatures;
+  var highlight;
+
+  function highlightChangeset(id) {
+    var feature = vectors.getFeatureByFid(id);
+    var bounds = feature.geometry.getBounds();
+
+    if (bounds.containsBounds(map.getExtent())) {
+      bounds = map.getExtent().scale(1.1);
+    }
+
+    if (highlight) vectors.removeFeatures(highlight);
+
+    highlight = new OpenLayers.Feature.Vector(bounds.toGeometry(), {}, {
+      strokeWidth: 2,
+      strokeColor: "#ee9900",
+      fillColor: "#ffff55",
+      fillOpacity: 0.5
+    });
+
+    vectors.addFeatures(highlight);
+
+    $("#tr-changeset-" + id).addClass("selected");
+  }
+
+  function unHighlightChangeset(id) {
+    vectors.removeFeatures(highlight);
+
+    $("#tr-changeset-" + id).removeClass("selected");
   }
   }
-  function highlightChangesetMap(name) {
-    getFeaturesByAttribute(vectors,'name',name)[0].style.strokeColor='#ffff55';
-    vectors.redraw(); 
-  } 
-  function unHighlightChangesetMap(name) {
-    getFeaturesByAttribute(vectors,'name',name)[0].style.strokeColor='#ee9900';
-    vectors.redraw(); 
-  }      
+
   function init() {
   function init() {
-    var map = createMap("small_map", {
-      controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoom(), new OpenLayers.Control.PanZoomBar() ]
+    var map = createMap("changeset_list_map", {
+      controls: [
+        new OpenLayers.Control.Navigation(),
+        new OpenLayers.Control.PanZoom(),
+        new OpenLayers.Control.PanZoomBar()
+      ]
     });
     });
-    
+
     var bounds = new OpenLayers.Bounds();
     var bounds = new OpenLayers.Bounds();
-    <%= render :partial => 'changeset_map_add', :collection => @edits unless @edits.nil? %>
-     
+
+    <% @edits.each do |edit| %>
+    <% if edit.has_valid_bbox? %>
+    <% bbox = edit.bbox.to_unscaled %>
+    var minlon = <%= bbox.min_lon %>;
+    var minlat = <%= bbox.min_lat %>;
+    var maxlon = <%= bbox.max_lon %>;
+    var maxlat = <%= bbox.max_lat %>;
+    var bbox = new OpenLayers.Bounds(minlon, minlat, maxlon, maxlat);
+
+    bounds.extend(bbox);
+
+    addBoxToMap(bbox, "<%= edit.id %>", true);
+    <% end %>
+    <% end %>
+
     vectors.events.on({
     vectors.events.on({
-      'featureselected': function(feature) {
-         document.getElementById('tr-' + feature.feature.attributes['name']).style.backgroundColor = '#ffff55';
-         feature.feature.style.strokeColor='#ffff00';
-         vectors.redraw();
-       },
-       'featureunselected': function(feature) {
-         document.getElementById('tr-' + feature.feature.attributes['name']).style.backgroundColor = '';
-         feature.feature.style.strokeColor='#ee9900';
-         vectors.redraw();
-       }
+      "featureselected": function(feature) {
+        highlightChangeset(feature.feature.fid);
+      },
+      "featureunselected": function(feature) {
+        unHighlightChangeset(feature.feature.fid);
+      }
+    });
+
+    var selectControl = new OpenLayers.Control.SelectFeature(vectors, {
+      multiple: false,
+      hover: true
     });
     });
-    var selectControl = new OpenLayers.Control.SelectFeature(vectors,
-      {multiple: false, hover:true});
     map.addControl(selectControl);
     selectControl.activate();
 
     map.addControl(selectControl);
     selectControl.activate();
 
-    <!-- if bounds were passed, just use those -->
     <% if ! @bbox.nil? %>
     <% if ! @bbox.nil? %>
-      bounds = new OpenLayers.Bounds(<%= @bbox %>);
+      map.zoomToExtent(proj(new OpenLayers.Bounds(<%= @bbox %>)));
+    <% else %>
+      map.zoomToExtent(proj(bounds));
     <% end %>
     <% end %>
-    setMapExtent(bounds);
-
-    $("loading").innerHTML = "";
   }
 
   }
 
-  window.onload = init;
+  Event.observe(window, "load", init);
 </script>
 </script>