Changeset 872


Ignore:
Timestamp:
Sep 17, 2006, 6:48:41 PM (15 years ago)
Author:
nick
Message:

Do the wgs84 convertion for the google maps page. Add tests for this too. References #89

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides.pm

    r867 r872  
    561561                            param     => $formatter->node_name_to_node_param($_) }
    562562                        } sort @selnodes;
     563
     564    # Convert the lat+long to WGS84 as required
     565    for(my $i=0; $i<scalar @nodes;$i++) {
     566        my $node = $nodes[$i];
     567        if($node) {
     568            my %metadata = %{$node->{node_data}->{metadata}};
     569            my ($wgs84_long, $wgs84_lat);
     570            eval {
     571                ($wgs84_long, $wgs84_lat) = OpenGuides::Utils->get_wgs84_coords(
     572                                      longitude => $metadata{longitude}[0],
     573                                      latitude => $metadata{latitude}[0],
     574                                      config => $self->config);
     575            };
     576            warn $@." on ".$metadata{latitude}[0]." ".$metadata{longitude}[0] if $@;
     577
     578            push @{$nodes[$i]->{node_data}->{metadata}->{wgs84_long}}, $wgs84_long;
     579            push @{$nodes[$i]->{node_data}->{metadata}->{wgs84_lat}},  $wgs84_lat;
     580        }
     581    }
    563582
    564583    $tt_vars{nodes} = \@nodes;
  • trunk/lib/OpenGuides/Utils.pm

    r870 r872  
    255255            $helmert = sub($$$) {
    256256                my ($datum,$oldlat,$oldlong) = @_;
    257                 my $datum_helper = Geo::HelmertTransform::datum($datum);
    258                 my $wgs84_helper = Geo::HelmertTransform::datum('WGS84');
     257                my $datum_helper = new Geo::HelmertTransform::Datum(Name=>$datum);
     258                my $wgs84_helper = new Geo::HelmertTransform::Datum(Name=>'WGS84');
    259259                unless($datum_helper) {
    260260                    croak("No convertion helper for datum '$datum'");
  • trunk/t/28_wgs84_coords.t

    r870 r872  
    55use Test::More;
    66
    7 plan tests => 4;
     7plan tests => 6;
    88
    99# Clear out the database from any previous runs.
     
    3535my $have_helmert = $@ ? 0 : 1;
    3636SKIP : {
    37     skip "Geo::HelmertTransform not installed - can't do transforms", 2
     37    skip "Geo::HelmertTransform not installed - can't do transforms", 4
    3838        unless $have_helmert;
    3939
     
    6161    is( $wgs_lat, $wgs84_lat,
    6262        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
     63
     64    # Call it again, check we get the same result
     65    ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
     66                                                     longitude => $longitude,
     67                                                     latitude => $latitude,
     68                                                     config => $config);
     69    $wgs_long = int($wgs_long * $fivedp)/$fivedp;
     70    $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
     71    is( $wgs_long, $wgs84_lon,
     72        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
     73    is( $wgs_lat, $wgs84_lat,
     74        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
    6375}
  • trunk/t/53_show_index.t

    r847 r872  
    33use OpenGuides;
    44use OpenGuides::Test;
    5 use Test::More tests => 17; # 19 when all enabled
     5use Test::More tests => 23; # 25 when all enabled
    66
    77eval { require DBD::SQLite; };
     
    99
    1010SKIP: {
    11     skip "DBD::SQLite not installed - no database to test with", 17
     11    skip "DBD::SQLite not installed - no database to test with", 23
    1212      unless $have_sqlite;
    1313
     
    2828
    2929    $wiki->write_node( "Test Page", "foo", undef,
    30                        { category => "Alpha" } )
     30                       { category => "Alpha", latitude=>51.754349, longitude=>-1.258200 } )
    3131      or die "Couldn't write node";
    3232    $wiki->write_node( "Test Page 2", "foo", undef,
     
    9494    @entries = ($output =~ /(\<entry\>)/g);
    9595    is( 2, scalar @entries, "Right number of nodes included in atom" );
     96
     97
     98    # Test the map version
     99    $config->gmaps_api_key("yes I have one");
     100    $config->geo_handler(1);
     101    $config->force_wgs84(0);
     102    $output = eval {
     103        $guide->show_index(
     104                            return_output => 1,
     105                            format        => "map",
     106                          );
     107    };
     108    is( $@, "", "->show_index doesn't die when asked for map" );
     109    like( $output, qr|Content-Type: text/html|,
     110          "Map output gets content-type of text/html" );
     111    like( $output, qr|new GMap|, "Really is google map" );
     112    my @points = ($output =~ /point\d+ = (new GPoint\(.*?, .*?\))/g);
     113    is( 1, scalar @points, "Right number of nodes included on map" );
     114
     115    # -1.259687,51.754813
     116    like( $points[0], qr|51.75481|, "Has latitude");
     117    like( $points[0], qr|-1.25968|, "Has longitude");
    96118}
  • trunk/templates/map_index.tt

    r867 r872  
    3838        [% NEXT IF metadata.latitude.list.first.match('m') %]
    3939        [% NEXT IF metadata.longitude.list.first.match('m') %]
    40           var point[% i %] = new GPoint([% metadata.longitude.list.first %], [% metadata.latitude.list.first %]);
     40          var point[% i %] = new GPoint([% metadata.wgs84_long.list.first %], [% metadata.wgs84_lat.list.first %]);
    4141          var marker[% i %] = new GMarker(point[% i %],baseIcon);
    4242          [% IF metadata.source %]
Note: See TracChangeset for help on using the changeset viewer.