From: Richard Fairhurst Date: Fri, 18 May 2007 15:20:31 +0000 (+0000) Subject: Potlatch-on-Rails, ready to go (fingers crossed) X-Git-Tag: live~8562 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/0944c1cf02ca3f2b17c9261e57a9a0b0c210a40d?ds=sidebyside Potlatch-on-Rails, ready to go (fingers crossed) --- 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 77b38014d..bb0dd646a 100755 Binary files a/public/potlatch/potlatch.swf and b/public/potlatch/potlatch.swf differ