way stuff
This commit is contained in:
parent
97978ceeb9
commit
222d31e435
23 changed files with 233 additions and 13 deletions
2
app/controllers/current_way_segment_controller.rb
Normal file
2
app/controllers/current_way_segment_controller.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class CurrentWaySegmentController < ApplicationController
|
||||
end
|
2
app/controllers/old_way_controller.rb
Normal file
2
app/controllers/old_way_controller.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class OldWayController < ApplicationController
|
||||
end
|
29
app/controllers/way_controller.rb
Normal file
29
app/controllers/way_controller.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class WayController < ApplicationController
|
||||
require 'xml/libxml'
|
||||
|
||||
before_filter :authorize
|
||||
|
||||
def create
|
||||
if request.put?
|
||||
way = Way.from_xml(request.raw_post, true)
|
||||
|
||||
if way
|
||||
way.user_id = @user.id
|
||||
if way.save_with_history
|
||||
|
||||
|
||||
render :text => way.id
|
||||
else
|
||||
render :nothing => true, :status => 500
|
||||
end
|
||||
return
|
||||
else
|
||||
render :nothing => true, :status => 400 # if we got here the doc didnt parse
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
render :nothing => true, :status => 500 # something went very wrong
|
||||
end
|
||||
|
||||
end
|
2
app/controllers/way_tag_controller.rb
Normal file
2
app/controllers/way_tag_controller.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class WayTagController < ApplicationController
|
||||
end
|
2
app/helpers/current_way_segment_helper.rb
Normal file
2
app/helpers/current_way_segment_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module CurrentWaySegmentHelper
|
||||
end
|
2
app/helpers/old_way_helper.rb
Normal file
2
app/helpers/old_way_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module OldWayHelper
|
||||
end
|
2
app/helpers/way_helper.rb
Normal file
2
app/helpers/way_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module WayHelper
|
||||
end
|
2
app/helpers/way_tag_helper.rb
Normal file
2
app/helpers/way_tag_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module WayTagHelper
|
||||
end
|
2
app/models/current_way_segment.rb
Normal file
2
app/models/current_way_segment.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class CurrentWaySegment < ActiveRecord::Base
|
||||
end
|
14
app/models/old_way.rb
Normal file
14
app/models/old_way.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class OldWay < ActiveRecord::Base
|
||||
set_table_name 'ways'
|
||||
|
||||
belongs_to :user
|
||||
|
||||
def self.from_way(way)
|
||||
old_way = OldWay.new
|
||||
old_way.user_id = way.user_id
|
||||
old_way.timestamp = way.timestamp
|
||||
old_way.id = way.id
|
||||
return old_way
|
||||
end
|
||||
|
||||
end
|
81
app/models/way.rb
Normal file
81
app/models/way.rb
Normal file
|
@ -0,0 +1,81 @@
|
|||
class Way < ActiveRecord::Base
|
||||
require 'xml/libxml'
|
||||
|
||||
belongs_to :user
|
||||
set_table_name 'current_ways'
|
||||
|
||||
def self.from_xml(xml, create=false)
|
||||
p = XML::Parser.new
|
||||
p.string = xml
|
||||
doc = p.parse
|
||||
|
||||
way = Way.new
|
||||
|
||||
doc.find('//osm/way').each do |pt|
|
||||
if !create and pt['id'] != '0'
|
||||
way.id = pt['id'].to_i
|
||||
end
|
||||
|
||||
if create
|
||||
way.timestamp = Time.now
|
||||
way.visible = true
|
||||
else
|
||||
if pt['timestamp']
|
||||
way.timestamp = Time.parse(pt['timestamp'])
|
||||
end
|
||||
end
|
||||
|
||||
pt.find('tag').each do |tag|
|
||||
way.add_tag_keyval(tag['k'], tag['v'])
|
||||
end
|
||||
|
||||
pt.find('seg').each do |seg|
|
||||
way.add_seg_num(seg['id'])
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
return way
|
||||
end
|
||||
|
||||
def segs
|
||||
@segs = Array.new unless @segs
|
||||
@segs
|
||||
end
|
||||
|
||||
def tags
|
||||
@tags = Hash.new unless @tags
|
||||
@tags
|
||||
end
|
||||
|
||||
def add_seg_num(n)
|
||||
@segs = Array.new unless @segs
|
||||
@segs << n.to_i
|
||||
end
|
||||
|
||||
def add_tag_keyval(k, v)
|
||||
@tags = Hash.new unless @tags
|
||||
@tags[k] = v
|
||||
end
|
||||
|
||||
def save_with_history
|
||||
t = Time.now
|
||||
self.timestamp = t
|
||||
self.save
|
||||
|
||||
WayTag.delete_all(['id = ?', self.id])
|
||||
|
||||
self.tags.each do |k,v|
|
||||
tag = WayTag.new
|
||||
tag.k = k
|
||||
tag.v = v
|
||||
tag.id = self.id
|
||||
tag.save
|
||||
end
|
||||
|
||||
old_way = OldWay.from_way(self)
|
||||
old_way.save
|
||||
end
|
||||
|
||||
end
|
6
app/models/way_tag.rb
Normal file
6
app/models/way_tag.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
class WayTag < ActiveRecord::Base
|
||||
set_table_name 'current_way_tags'
|
||||
|
||||
belongs_to :way, :foreign_key => 'id'
|
||||
|
||||
end
|
|
@ -49,20 +49,19 @@
|
|||
<div id="logo">
|
||||
<center>
|
||||
<h1>OpenStreetMap</h1>
|
||||
|
||||
<img src="/images/osm_logo.png" width="120" height="120"/><br/>
|
||||
<nobr><h2>The Free Wiki World Map</h2></nobr>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
<% unless @user %>
|
||||
<div id="intro">
|
||||
OpenStreetMap is a free editable map of the whole world. It is made by people like you.
|
||||
<p/>
|
||||
OpenStreetMap allows you to view, edit and use geographical data in a collaborative way from anywhere on Earth.
|
||||
<p/>
|
||||
OpenStreetMap's hosting is kindly supported by the <a href="http://www.vr.ucl.ac.uk">UCL VR Centre</a> and <a href="http://www.bytemark.co.uk">bytemark</a>.
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div id="left_menu">
|
||||
<a href="http://wiki.openstreetmap.org">Help & Wiki</a><br />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue