From 0944c1cf02ca3f2b17c9261e57a9a0b0c210a40d Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Fri, 18 May 2007 15:20:31 +0000 Subject: [PATCH] Potlatch-on-Rails, ready to go (fingers crossed) --- app/controllers/amf_controller.rb | 39 ++++-- app/controllers/swf_controller.rb | 202 ++++++++++++++++++++++++++++++ app/helpers/swf_helper.rb | 2 + app/views/site/edit.rhtml | 8 +- config/routes.rb | 1 + public/potlatch/potlatch.swf | Bin 71052 -> 71156 bytes 6 files changed, 237 insertions(+), 15 deletions(-) create mode 100644 app/controllers/swf_controller.rb create mode 100644 app/helpers/swf_helper.rb diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 9947a4eaa..a9a56203a 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -1,9 +1,9 @@ class AmfController < ApplicationController -=begin +#=begin require 'stringio' -# to log: -# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") + # to log: + # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") # ==================================================================== # Main AMF handler @@ -55,6 +55,7 @@ class AmfController < ApplicationController end + private # ==================================================================== # Remote calls @@ -107,7 +108,20 @@ class AmfController < ApplicationController waylist.each {|a| ways<80 do + r+=[b.slice!(0...80)].pack("B*") + end + end + + # - Write shape + + b+=endShape() + r+=[b].pack("B*") + m+=swfRecord(2,packUI16(1) + packRect(xl,xr,yb,yt) + r) + m+=swfRecord(4,packUI16(1) + packUI16(1)) + + # - Create Flash header and write to browser + + m+=swfRecord(1,'') # Show frame + m+=swfRecord(0,'') # End + + m=packRect(bounds_left,bounds_right,bounds_bottom,bounds_top) + 0.chr + 12.chr + packUI16(1) + m + m='FWS' + 6.chr + packUI32(m.length+8) + m + + response.headers["Content-Type"]="application/x-shockwave-flash" + render :text=>m + end + + private + + # ======================================================================= + # SWF functions + + # ----------------------------------------------------------------------- + # Line-drawing + + def startShape + s =0.chr # No fill styles + s+=1.chr # One line style + s+=packUI16(5) + 0.chr + 255.chr + 255.chr # Width 5, RGB #00FFFF + s+=17.chr # 1 fill, 1 line index bit + s + end + + def endShape + '000000' + end + + def startAndMove(x,y) + d='001001' # Line style change, moveTo + l =[lengthSB(x),lengthSB(y)].max + d+=sprintf("%05b%0#{l}b%0#{l}b",l,x,y) + d+='1' # Select line style 1 + end + + def drawTo(absx,absy,x,y) + d='11' # TypeFlag, EdgeFlag + dx=x-absx + dy=y-absy + + l =[lengthSB(dx),lengthSB(dy)].max + d+=sprintf("%04b",l-2) + d+='1' # GeneralLine + d+=sprintf("%0#{l}b%0#{l}b",dx,dy) + end + + # ----------------------------------------------------------------------- + # Specific data types + + def swfRecord(id,r) + if r.length>62 + return packUI16((id<<6)+0x3F) + packUI32(r.length) + r + else + return packUI16((id<<6)+r.length) + r + end + end + + def packRect(a,b,c,d) + l=[lengthSB(a), + lengthSB(b), + lengthSB(c), + lengthSB(d)].max + n=sprintf("%05b%0#{l}b%0#{l}b%0#{l}b%0#{l}b",l,a,b,c,d) + [n].pack("B*") + end + + # ----------------------------------------------------------------------- + # Generic pack functions + + def packUI16(n) + [n.floor].pack("v") + end + + def packUI32(n) + [n.floor].pack("V") + end + + # Find number of bits required to store arbitrary-length binary + + def lengthSB(n) + Math.frexp(n+ (n==0?1:0) )[1]+1 + end + + # ==================================================================== + # Co-ordinate conversion + # (this is duplicated from amf_controller, should probably share) + + def lat2coord(a,basey,masterscale) + -(lat2y(a)-basey)*masterscale+250 + end + + def long2coord(a,baselong,masterscale) + (a-baselong)*masterscale+350 + end + + def lat2y(a) + 180/Math::PI * Math.log(Math.tan(Math::PI/4+a*(Math::PI/180)/2)) + end + + def sqlescape(a) + a.gsub("'","''").gsub(92.chr,92.chr+92.chr) + end + +end diff --git a/app/helpers/swf_helper.rb b/app/helpers/swf_helper.rb new file mode 100644 index 000000000..cf2a311dc --- /dev/null +++ b/app/helpers/swf_helper.rb @@ -0,0 +1,2 @@ +module SwfHelper +end diff --git a/app/views/site/edit.rhtml b/app/views/site/edit.rhtml index 20b049198..e1ef556e0 100644 --- a/app/views/site/edit.rhtml +++ b/app/views/site/edit.rhtml @@ -1,7 +1,7 @@ -

This editor isn't working yet - currently you can only browse the aerial photos. +

You need a Flash player to use Potlatch, the OpenStreetMap Flash editor. You can download Flash Player from Adobe.com. @@ -18,8 +18,8 @@ fully functional desktop client editor for Open Street Map.

fo.addVariable('token','<%= @user.token %>'); fo.write("mapcontent"); } -<% lon = params['lon'] || '-0.1' %> -<% lat = params['lat'] || '51.5' %> +<% lon = params['lon'] || @user.home_lon || '-0.1' %> +<% lat = params['lat'] || @user.home_lat || '51.5' %> doSWF(<%= lat %>,<%= lon %>,12); diff --git a/config/routes.rb b/config/routes.rb index 941991cdc..4f887d140 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,6 +36,7 @@ ActionController::Routing::Routes.draw do |map| # Potlatch API map.connect "api/#{API_VERSION}/amf", :controller =>'amf', :action =>'talk' + map.connect "api/#{API_VERSION}/swf/trackpoints", :controller =>'swf', :action =>'trackpoints' # web site diff --git a/public/potlatch/potlatch.swf b/public/potlatch/potlatch.swf index 77b38014dca491803cb442ca0d8222df1bbcce08..bb0dd646a0699634e28706013ef93b6cf31c0cdc 100755 GIT binary patch delta 672 zcmeBK&GKb63#(grFvpjTtXxSPN7gbhbOZ=J-z=UqUr;H%pt!Ushe1zIKd~TF-$2hq zzqmY2zoaNJIlCY~Gq0qWVe+ZsP=UnCoXp}92Cxu_wOO_#!H-dGa@`?CPBsS4D~z01 z8D%FwxThfejA0rxNI(WeU1M~g#>6mr;b9rZ>y!5#R%E;}`2mo;Ia&R%qUJ5IBnN{G zPzeW@pF2pyZDcVch}fOUg@-kSzY=S%Ez#y8+hq)~>+a-)BPL9587EI)rB)Ag&ppQ3 ztPEfv3v%8)ptpdIT|S$Kfq{{sD7CmWr-Z?P5hTVS;{&3s{HC!ourmU+fPBtjc3le$&69TCP3IR>O&*;_;xt-oY7Ae#1oU5#sP6Z=MzXA1~CSSgTz2ihlxD{ip^wVh+>$= u&A|TuKTzTkBj@AEeJAy`LArqEh+=Ab3Ni>N1&nZ@cbqsMZ+>xdi8lbj+qO9X delta 525 zcma)2yDvjw6hG(c)$g_p-h24A%u2c1! UlodjJ#m_GT>ryht@Wo#L7uQyn9RL6T -- 2.45.1