myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2553] branches/neiss: added thresholds to MapTub


From: noreply
Subject: [myexperiment-hackers] [2553] branches/neiss: added thresholds to MapTube maps
Date: Tue, 1 Feb 2011 11:28:53 -0500 (EST)

Revision
2553
Author
dgc
Date
2011-02-01 11:28:53 -0500 (Tue, 01 Feb 2011)

Log Message

added thresholds to MapTube maps

Modified Paths

Added Paths

Diff

Added: branches/neiss/app/helpers/maps_helper.rb (0 => 2553)


--- branches/neiss/app/helpers/maps_helper.rb	                        (rev 0)
+++ branches/neiss/app/helpers/maps_helper.rb	2011-02-01 16:28:53 UTC (rev 2553)
@@ -0,0 +1,22 @@
+# myExperiment: app/helpers/maps_helper.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+module MapsHelper
+
+  def threshold_colour(threshold)
+
+    colour = threshold.colour[2..-1]
+
+    if colour.length == 6
+      if colour.match(/^[0-9a-f]*$/)
+        return "##{colour}"
+      end
+    end
+
+    nil
+  end
+
+end
+

Modified: branches/neiss/app/models/map.rb (2552 => 2553)


--- branches/neiss/app/models/map.rb	2011-02-01 16:27:26 UTC (rev 2552)
+++ branches/neiss/app/models/map.rb	2011-02-01 16:28:53 UTC (rev 2553)
@@ -9,6 +9,8 @@
 require 'acts_as_attributor'
 require 'acts_as_attributable'
 
+require 'xml/libxml'
+
 class Map < ActiveRecord::Base
 
   acts_as_site_entity :owner_text => 'Creator'
@@ -25,6 +27,8 @@
   acts_as_attributor
   acts_as_attributable
   
+  acts_as_structured_data
+
   acts_as_solr(:fields => [:title, :description, :uploader, :tag_list],
                :boost => "rank",
                :include => [ :comments ]) if Conf.solr_enable
@@ -46,5 +50,34 @@
     
     boost
   end
+
+
+  def retrieve_maptube_colour_thresholds
+
+    def fetch_xml(url)
+      LibXML::XML::Parser.string(URI.parse(url).read).parse.root
+    end
+
+    descriptor = fetch_xml(map_descriptor)
+
+    settings_url = descriptor.find_first('/MapDataDescriptor/RenderStyleURL/text()').content
+
+    settings = fetch_xml(settings_url)
+
+    # erase existing colour thresholds
+
+    map_tube_colour_thresholds.each do |t|
+      t.destroy
+    end
+
+    # create colour thresholds
+
+    settings.find('/gmapcreator/colourscale/colourThresholds/colourThreshold').map do |threshold_el|
+      map_tube_colour_thresholds << MapTubeColourThreshold.create(
+        :colour      => threshold_el.find_first('colour/text()').content,
+        :description => threshold_el.find_first('description/text()').content,
+        :threshold   => threshold_el.find_first('threshold/text()').content)
+    end
+  end
 end
 

Added: branches/neiss/app/views/maps/_thresholds.rhtml (0 => 2553)


--- branches/neiss/app/views/maps/_thresholds.rhtml	                        (rev 0)
+++ branches/neiss/app/views/maps/_thresholds.rhtml	2011-02-01 16:28:53 UTC (rev 2553)
@@ -0,0 +1,9 @@
+
+<h2>Thresholds</h2>
+
+<table>
+  <% @map.map_tube_colour_thresholds.each do |t| %>
+    <tr><td style="text-align: left; background: <%= threshold_colour(t) -%>"><%=h t.description %></td></tr>
+  <% end %>
+</table>
+

Modified: branches/neiss/app/views/maps/explore.rhtml (2552 => 2553)


--- branches/neiss/app/views/maps/explore.rhtml	2011-02-01 16:27:26 UTC (rev 2552)
+++ branches/neiss/app/views/maps/explore.rhtml	2011-02-01 16:28:53 UTC (rev 2553)
@@ -54,3 +54,5 @@
 surveyMap.addOverlay(getOverlay(tileService, descriptor));
 </script>
 
+<%= render :partial => "thresholds" -%>
+

Modified: branches/neiss/config/schema.d/neiss.xml (2552 => 2553)


--- branches/neiss/config/schema.d/neiss.xml	2011-02-01 16:27:26 UTC (rev 2552)
+++ branches/neiss/config/schema.d/neiss.xml	2011-02-01 16:28:53 UTC (rev 2553)
@@ -18,7 +18,18 @@
     <column type="datetime" name="created_at"/>
     <column type="datetime" name="updated_at"/>
 
+    <has-many target="map_tube_colour_thresholds"/>
+
   </table>
   
+  <table name="map_tube_colour_thresholds">
+
+    <column type="integer" name="map_id"/>
+    <column type="string"  name="threshold"/>
+    <column type="string"  name="description"/>
+    <column type="string"  name="colour"/>
+
+  </table>
+
 </schema>
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]