From 6559db51dfcdc10187d3e8f845474729dbb9faa6 Mon Sep 17 00:00:00 2001 From: Steve Coast Date: Wed, 6 Dec 2006 17:55:22 +0000 Subject: [PATCH] various gpx rails things --- app/controllers/trace_controller.rb | 1 - app/models/trace.rb | 2 +- app/views/trace/view.rhtml | 28 +++++++++++++--------------- lib/daemons/gpx_import.rb | 13 ++++++++++++- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index f7f323e9c..41802a89b 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -47,5 +47,4 @@ class TraceController < ApplicationController trace = Trace.find(params[:id]) send_data(trace.icon_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public end - end diff --git a/app/models/trace.rb b/app/models/trace.rb index 06e3dc1a1..7c4b5de18 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -2,7 +2,7 @@ class Trace < ActiveRecord::Base set_table_name 'gpx_files' belongs_to :user - has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id' + has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy def tagstring=(s) self.tags = s.split().collect {|tag| diff --git a/app/views/trace/view.rhtml b/app/views/trace/view.rhtml index 28ef095ab..661f5866f 100644 --- a/app/views/trace/view.rhtml +++ b/app/views/trace/view.rhtml @@ -1,15 +1,13 @@ -trace <%= @trace.name %> -
-icon -
- -picture - -
-time <%= @trace.timestamp %> -
-dec <%= @trace.description %> - - - - +

Viewing trace <%= @trace.name %>

+ + + + + + + + + + + +
filename:<%= @trace.name %>
uploaded at:<%= @trace.timestamp %>
points:<%= @trace.size %>
start coordinate:<%= @trace.latitude %>, <%= @trace.longitude %>
owner:<%= link_to @trace.user.display_name, {:controller => 'trace', :action => 'by_user'} %>
description:<%= @trace.description %>
tags:<%= @trace.tags.collect {|tag| tag.tag} %>
diff --git a/lib/daemons/gpx_import.rb b/lib/daemons/gpx_import.rb index 70764dd38..427edd121 100755 --- a/lib/daemons/gpx_import.rb +++ b/lib/daemons/gpx_import.rb @@ -33,7 +33,16 @@ while($running) do end gpx = OSM::GPXImporter.new("/tmp/#{trace.id}.gpx") + f_lat = 0 + l_lon = 0 + first = true + gpx.points do |point| + if first + f_lat = point['latitude'] + f_lon = point['longitude'] + end + tp = Tracepoint.new tp.latitude = point['latitude'] tp.longitude = point['longitude'] @@ -49,7 +58,9 @@ while($running) do min_lat = Tracepoint.minimum('latitude', :conditions => ['gpx_id = ?', trace.id]) max_lon = Tracepoint.maximum('longitude', :conditions => ['gpx_id = ?', trace.id]) min_lon = Tracepoint.minimum('longitude', :conditions => ['gpx_id = ?', trace.id]) - #logger.info("bbox: #{min_lat} #{max_lat} #{min_lon} #{max_lon}") + + trace.latitude = f_lat + trace.longitude = f_lat trace.large_picture = gpx.get_picture(min_lat, min_lon, max_lat, max_lon, gpx.actual_points) trace.icon_picture = gpx.get_icon(min_lat, min_lon, max_lat, max_lon) trace.size = gpx.actual_points -- 2.43.2