Author: nick
Date: 2006-09-17 18:48:41 +0100 (Sun, 17 Sep 2006)
New Revision: 872
Modified:
trunk/lib/OpenGuides.pm
trunk/lib/OpenGuides/Utils.pm
trunk/t/28_wgs84_coords.t
trunk/t/53_show_index.t
trunk/templates/map_index.tt
Log:
Do the wgs84 convertion for the google maps page. Add tests for this too. References #89
Modified: trunk/lib/OpenGuides/Utils.pm
===================================================================
--- trunk/lib/OpenGuides/Utils.pm 2006-09-17 16:50:39 UTC (rev 871)
+++ trunk/lib/OpenGuides/Utils.pm 2006-09-17 17:48:41 UTC (rev 872)
@@ -254,8 +254,8 @@
require Geo::HelmertTransform;
$helmert = sub($$$) {
my ($datum,$oldlat,$oldlong) = @_;
- my $datum_helper = Geo::HelmertTransform::datum($datum);
- my $wgs84_helper = Geo::HelmertTransform::datum('WGS84');
+ my $datum_helper = new Geo::HelmertTransform::Datum(Name=>$datum);
+ my $wgs84_helper = new Geo::HelmertTransform::Datum(Name=>'WGS84');
unless($datum_helper) {
croak("No convertion helper for datum '$datum'");
return undef;
Modified: trunk/lib/OpenGuides.pm
===================================================================
--- trunk/lib/OpenGuides.pm 2006-09-17 16:50:39 UTC (rev 871)
+++ trunk/lib/OpenGuides.pm 2006-09-17 17:48:41 UTC (rev 872)
@@ -561,6 +561,25 @@
param => $formatter->node_name_to_node_param($_) }
} sort @selnodes;
+ # Convert the lat+long to WGS84 as required
+ for(my $i=0; $i<scalar @nodes;$i++) {
+ my $node = $nodes[$i];
+ if($node) {
+ my %metadata = %{$node->{node_data}->{metadata}};
+ my ($wgs84_long, $wgs84_lat);
+ eval {
+ ($wgs84_long, $wgs84_lat) = OpenGuides::Utils->get_wgs84_coords(
+ longitude => $metadata{longitude}[0],
+ latitude => $metadata{latitude}[0],
+ config => $self->config);
+ };
+ warn $@." on ".$metadata{latitude}[0]." ".$metadata{longitude}[0] if $@;
+
+ push @{$nodes[$i]->{node_data}->{metadata}->{wgs84_long}}, $wgs84_long;
+ push @{$nodes[$i]->{node_data}->{metadata}->{wgs84_lat}}, $wgs84_lat;
+ }
+ }
+
$tt_vars{nodes} = \@nodes;
my ($template, %conf);
Modified: trunk/t/28_wgs84_coords.t
===================================================================
--- trunk/t/28_wgs84_coords.t 2006-09-17 16:50:39 UTC (rev 871)
+++ trunk/t/28_wgs84_coords.t 2006-09-17 17:48:41 UTC (rev 872)
@@ -4,7 +4,7 @@
use OpenGuides::Test;
use Test::More;
-plan tests => 4;
+plan tests => 6;
# Clear out the database from any previous runs.
unlink "t/node.db";
@@ -34,7 +34,7 @@
eval{ require Geo::HelmertTransform; };
my $have_helmert = $@ ? 0 : 1;
SKIP : {
- skip "Geo::HelmertTransform not installed - can't do transforms", 2
+ skip "Geo::HelmertTransform not installed - can't do transforms", 4
unless $have_helmert;
$config->force_wgs84(0);
@@ -60,4 +60,16 @@
"get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
is( $wgs_lat, $wgs84_lat,
"get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
+
+ # Call it again, check we get the same result
+ ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
+ longitude => $longitude,
+ latitude => $latitude,
+ config => $config);
+ $wgs_long = int($wgs_long * $fivedp)/$fivedp;
+ $wgs_lat = int($wgs_lat * $fivedp)/$fivedp;
+ is( $wgs_long, $wgs84_lon,
+ "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
+ is( $wgs_lat, $wgs84_lat,
+ "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
}
Modified: trunk/t/53_show_index.t
===================================================================
--- trunk/t/53_show_index.t 2006-09-17 16:50:39 UTC (rev 871)
+++ trunk/t/53_show_index.t 2006-09-17 17:48:41 UTC (rev 872)
@@ -2,13 +2,13 @@
use Wiki::Toolkit::Setup::SQLite;
use OpenGuides;
use OpenGuides::Test;
-use Test::More tests => 17; # 19 when all enabled
+use Test::More tests => 23; # 25 when all enabled
eval { require DBD::SQLite; };
my $have_sqlite = $@ ? 0 : 1;
SKIP: {
- skip "DBD::SQLite not installed - no database to test with", 17
+ skip "DBD::SQLite not installed - no database to test with", 23
unless $have_sqlite;
Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
@@ -27,7 +27,7 @@
}
$wiki->write_node( "Test Page", "foo", undef,
- { category => "Alpha" } )
+ { category => "Alpha", latitude=>51.754349, longitude=>-1.258200 } )
or die "Couldn't write node";
$wiki->write_node( "Test Page 2", "foo", undef,
{ category => "Alpha" } )
@@ -93,4 +93,26 @@
#like( $output, qr|<title>Category Alpha</title>|, "Right atom title" );
@entries = ($output =~ /(\<entry\>)/g);
is( 2, scalar @entries, "Right number of nodes included in atom" );
+
+
+ # Test the map version
+ $config->gmaps_api_key("yes I have one");
+ $config->geo_handler(1);
+ $config->force_wgs84(0);
+ $output = eval {
+ $guide->show_index(
+ return_output => 1,
+ format => "map",
+ );
+ };
+ is( $@, "", "->show_index doesn't die when asked for map" );
+ like( $output, qr|Content-Type: text/html|,
+ "Map output gets content-type of text/html" );
+ like( $output, qr|new GMap|, "Really is google map" );
+ my @points = ($output =~ /point\d+ = (new GPoint\(.*?, .*?\))/g);
+ is( 1, scalar @points, "Right number of nodes included on map" );
+
+ # -1.259687,51.754813
+ like( $points[0], qr|51.75481|, "Has latitude");
+ like( $points[0], qr|-1.25968|, "Has longitude");
}
Modified: trunk/templates/map_index.tt
===================================================================
--- trunk/templates/map_index.tt 2006-09-17 16:50:39 UTC (rev 871)
+++ trunk/templates/map_index.tt 2006-09-17 17:48:41 UTC (rev 872)
@@ -37,7 +37,7 @@
[% IF metadata.latitude.list.first AND metadata.longitude.list.first %]
[% NEXT IF metadata.latitude.list.first.match('m') %]
[% NEXT IF metadata.longitude.list.first.match('m') %]
- var point[% i %] = new GPoint([% metadata.longitude.list.first %], [% metadata.latitude.list.first %]);
+ var point[% i %] = new GPoint([% metadata.wgs84_long.list.first %], [% metadata.wgs84_lat.list.first %]);
var marker[% i %] = new GMarker(point[% i %],baseIcon);
[% IF metadata.source %]
[% source_url = metadata.source.list.first.match('^(.*?)\?(?:\?|$)').first %]