]> git.openstreetmap.org Git - rails.git/commitdiff
move potlatch presets to only be generated once, and allow pulling in way_tags in...
authorSteve Coast <steve@asklater.com>
Thu, 24 Jan 2008 10:52:10 +0000 (10:52 +0000)
committerSteve Coast <steve@asklater.com>
Thu, 24 Jan 2008 10:52:10 +0000 (10:52 +0000)
app/controllers/amf_controller.rb
app/models/way.rb
app/models/way_node.rb
app/models/way_tag.rb
config/environment.rb
lib/osm.rb

index 60b7ab4438641dbe015b65c7b41ecd9302261af3..4b92db11c3bdf92afa16829ceed70a26f506c153 100644 (file)
@@ -85,75 +85,15 @@ class AmfController < ApplicationController
 
   private
 
+  # Return presets (default tags and crap) to potlatch
+  # Global is set up in config/environment.rb on startup, code is in lib/osm.rb
+  def getpresets
+    return POTLATCH_PRESETS
+  end
 
   # ====================================================================
   # Remote calls
 
-  # ----- getpresets
-  #              in:   none
-  #              does: reads tag preset menus, colours, and autocomplete config files
-  #          out:  [0] presets, [1] presetmenus, [2] presetnames,
-  #                            [3] colours, [4] casing, [5] areas, [6] autotags
-  #                            (all hashes)
-
-  def getpresets
-    RAILS_DEFAULT_LOGGER.info("  Message: getpresets")
-
-    # Read preset menus
-    presets={}
-    presetmenus={}; presetmenus['point']=[]; presetmenus['way']=[]; presetmenus['POI']=[]
-    presetnames={}; presetnames['point']={}; presetnames['way']={}; presetnames['POI']={}
-    presettype=''
-    presetcategory=''
-    #  StringIO.open(txt) do |file|
-    File.open("#{RAILS_ROOT}/config/potlatch/presets.txt") do |file|
-      file.each_line {|line|
-        t=line.chomp
-        if (t=~/(\w+)\/(\w+)/) then
-          presettype=$1
-          presetcategory=$2
-          presetmenus[presettype].push(presetcategory)
-          presetnames[presettype][presetcategory]=["(no preset)"]
-        elsif (t=~/^(.+):\s?(.+)$/) then
-          pre=$1; kv=$2
-          presetnames[presettype][presetcategory].push(pre)
-          presets[pre]={}
-          kv.split(',').each {|a|
-            if (a=~/^(.+)=(.*)$/) then presets[pre][$1]=$2 end
-          }
-        end
-      }
-    end
-
-    # Read colours/styling
-    colours={}; casing={}; areas={}
-    File.open("#{RAILS_ROOT}/config/potlatch/colours.txt") do |file|
-      file.each_line {|line|
-        t=line.chomp
-        if (t=~/(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/) then
-          tag=$1
-          if ($2!='-') then colours[tag]=$2.hex end
-          if ($3!='-') then casing[tag]=$3.hex end
-          if ($4!='-') then areas[tag]=$4.hex end
-        end
-      }
-    end
-
-    # Read auto-complete
-    autotags={}; autotags['point']={}; autotags['way']={}; autotags['POI']={};
-    File.open("#{RAILS_ROOT}/config/potlatch/autocomplete.txt") do |file|
-      file.each_line {|line|
-        t=line.chomp
-        if (t=~/^(\w+)\/(\w+)\s+(.+)$/) then
-          tag=$1; type=$2; values=$3
-          if values=='-' then autotags[type][tag]=[]
-          else autotags[type][tag]=values.split(',').sort.reverse end
-        end
-      }
-    end
-
-    [presets,presetmenus,presetnames,colours,casing,areas,autotags]
-  end
 
 
   # ----- whichways
@@ -208,6 +148,8 @@ class AmfController < ApplicationController
     basey       = args[5]
     masterscale = args[6]
 
+
+
     sql=<<-EOF
      SELECT DISTINCT current_ways.id 
        FROM current_nodes,way_nodes,current_ways 
index 1fe628171c9f91eefc47c050e70efb773e6715b7..2c9ce9f72d06e0560632953a1fafd9b069ff26b6 100644 (file)
@@ -49,9 +49,10 @@ class Way < ActiveRecord::Base
 
   # Find a way given it's ID, and in a single SQL call also grab its nodes
   #
+  
   # You can't pull in all the tags too unless we put a sequence_id on the way_tags table and have a multipart key
   def self.find_eager(id)
-    way = Way.find(id, :include => {:way_nodes => :node})
+    way = Way.find(id, :include => [:way_tags, {:way_nodes => :node}])
   end
 
   # Find a way given it's ID, and in a single SQL call also grab its nodes and tags
index 7f7789303f736da688195cad874df0c324d93aa1..957016b9dd6fd91d1b50b7b54faffc060888a66b 100644 (file)
@@ -3,4 +3,6 @@ class WayNode < ActiveRecord::Base
 
   set_primary_keys :id, :sequence_id
   belongs_to :node
+
+  belongs_to :way, :foreign_key => :id
 end
index 101085f129a4e0989f7623b55d68c7456bfba86b..3f6ac8ce3b5427b5128228e3f49cd218aa6fb84c 100644 (file)
@@ -1,5 +1,8 @@
 class WayTag < ActiveRecord::Base
   set_table_name 'current_way_tags'
 
+  # false multipart key
+  set_primary_keys :id, :k, :v
+
   belongs_to :way, :foreign_key => 'id'
 end
index be3cf2a8f3c4fff81dcb348fad9c138b6bc8e6aa..bf80499f7502e8a07d0355f2dbfe0b1b5b43962f 100644 (file)
@@ -68,3 +68,8 @@ Rails::Initializer.run do |config|
   # Make Active Record use UTC-base instead of local time
   # config.active_record.default_timezone = :utc
 end
+
+# This has to be after the above block for some reason (doesnt pull in /lib/osm.rb?)
+POTLATCH_PRESETS = OSM::Potlatch.get_presets()
+
+
index de5e73d294d546bbdc59a4aef5ae44d2dba17c8a..6e9346bb4f0076df8361c9a52b52348a8a426747 100644 (file)
@@ -424,4 +424,73 @@ module OSM
 
     return "#{tilesql} AND #{prefix}latitude BETWEEN #{minlat} AND #{maxlat} AND #{prefix}longitude BETWEEN #{minlon} AND #{maxlon}"
   end
+
+  class Potlatch # crazy shit
+
+    # ----- getpresets
+    #            in:   none
+    #            does: reads tag preset menus, colours, and autocomplete config files
+    #        out:  [0] presets, [1] presetmenus, [2] presetnames,
+    #                          [3] colours, [4] casing, [5] areas, [6] autotags
+    #                          (all hashes)
+    def self.get_presets
+      RAILS_DEFAULT_LOGGER.info("  Message: getpresets")
+
+      # Read preset menus
+      presets={}
+      presetmenus={}; presetmenus['point']=[]; presetmenus['way']=[]; presetmenus['POI']=[]
+      presetnames={}; presetnames['point']={}; presetnames['way']={}; presetnames['POI']={}
+      presettype=''
+      presetcategory=''
+      #        StringIO.open(txt) do |file|
+      File.open("#{RAILS_ROOT}/config/potlatch/presets.txt") do |file|
+        file.each_line {|line|
+          t=line.chomp
+          if (t=~/(\w+)\/(\w+)/) then
+            presettype=$1
+            presetcategory=$2
+            presetmenus[presettype].push(presetcategory)
+            presetnames[presettype][presetcategory]=["(no preset)"]
+          elsif (t=~/^(.+):\s?(.+)$/) then
+            pre=$1; kv=$2
+            presetnames[presettype][presetcategory].push(pre)
+            presets[pre]={}
+            kv.split(',').each {|a|
+              if (a=~/^(.+)=(.*)$/) then presets[pre][$1]=$2 end
+            }
+          end
+        }
+      end
+
+      # Read colours/styling
+      colours={}; casing={}; areas={}
+      File.open("#{RAILS_ROOT}/config/potlatch/colours.txt") do |file|
+        file.each_line {|line|
+          t=line.chomp
+          if (t=~/(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/) then
+            tag=$1
+            if ($2!='-') then colours[tag]=$2.hex end
+            if ($3!='-') then casing[tag]=$3.hex end
+            if ($4!='-') then areas[tag]=$4.hex end
+          end
+        }
+      end
+
+      # Read auto-complete
+      autotags={}; autotags['point']={}; autotags['way']={}; autotags['POI']={};
+      File.open("#{RAILS_ROOT}/config/potlatch/autocomplete.txt") do |file|
+        file.each_line {|line|
+          t=line.chomp
+          if (t=~/^(\w+)\/(\w+)\s+(.+)$/) then
+            tag=$1; type=$2; values=$3
+            if values=='-' then autotags[type][tag]=[]
+            else autotags[type][tag]=values.split(',').sort.reverse end
+          end
+        }
+      end
+
+      [presets,presetmenus,presetnames,colours,casing,areas,autotags]
+    end
+  end
+
 end