Author: dom Date: 2005-12-21 18:16:36 +0000 (Wed, 21 Dec 2005) New Revision: 730
Added: trunk/t/28_wgs84_coords.t Modified: trunk/Build.PL trunk/Changes trunk/lib/OpenGuides.pm trunk/lib/OpenGuides/CGI.pm trunk/lib/OpenGuides/Config.pm trunk/lib/OpenGuides/Template.pm trunk/lib/OpenGuides/Utils.pm trunk/preferences.cgi trunk/templates/header.tt trunk/templates/node.tt trunk/templates/preferences.tt Log: Add initial google maps support, see #46 but this isn't yet a complete implementation so leaving the bug open for now.
Modified: trunk/Build.PL =================================================================== --- trunk/Build.PL 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/Build.PL 2005-12-21 18:16:36 UTC (rev 730) @@ -76,7 +76,8 @@ custom_lib_path use_plucene indexing_directory enable_page_deletion admin_pass stylesheet_url site_name navbar_on_home_page home_name site_desc default_city default_country contact_email default_language - formatting_rules_node backlinks_in_title + formatting_rules_node backlinks_in_title gmaps_api_key centre_long + centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84 ) ) { my $q_method = $var . "__qu"; my $qu = $existing_config->$q_method;
Modified: trunk/Changes =================================================================== --- trunk/Changes 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/Changes 2005-12-21 18:16:36 UTC (rev 730) @@ -7,6 +7,9 @@ Things with opening hours are marked as geospatial in RDF. Fix missing bracket in node.tt. Add custom_node template just below main content in node.tt. + Google Maps support! There is a new index type, + wiki.cgi?action=index;format=map, and maps appear in the node listings + (the latter feature is user-configurable). Fix <link> in RSS to point to RecentChanges page, not the feed itself. #67 Default website for a page is now http://
Modified: trunk/lib/OpenGuides/CGI.pm =================================================================== --- trunk/lib/OpenGuides/CGI.pm 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/lib/OpenGuides/CGI.pm 2005-12-21 18:16:36 UTC (rev 730) @@ -1,7 +1,7 @@ package OpenGuides::CGI; use strict; use vars qw( $VERSION ); -$VERSION = '0.06'; +$VERSION = '0.07';
use Carp qw( croak ); use CGI::Cookie; @@ -38,6 +38,7 @@ default_edit_type => "tidying", cookie_expires => "never", track_recent_changes_views => 1, + display_google_maps => 1 );
my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); @@ -82,6 +83,7 @@ default_edit_type => "tidying", cookie_expires => "never", track_recent_changes_views => 1, + display_google_maps => 1 );
Croaks unless an LOpenGuides::Config object is supplied as C<config>. @@ -124,6 +126,7 @@ defedit => $args{default_edit_type} || "normal", exp => $args{cookie_expires}, trackrc => $args{track_recent_changes_views} || 0, + gmaps => $args{display_google_maps} || 0 }, -expires => $expires, ); @@ -161,6 +164,7 @@ default_edit_type => $data{defedit} || "normal", cookie_expires => $data{exp} || "month", track_recent_changes_views => $data{trackrc} || 0, + display_google_maps => $data{gmaps} || 0 ); }
@@ -255,7 +259,7 @@
=head1 COPYRIGHT
- Copyright (C) 2003-2004 The OpenGuides Project. All Rights Reserved. + Copyright (C) 2003-2005 The OpenGuides Project. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Modified: trunk/lib/OpenGuides/Config.pm =================================================================== --- trunk/lib/OpenGuides/Config.pm 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/lib/OpenGuides/Config.pm 2005-12-21 18:16:36 UTC (rev 730) @@ -9,8 +9,9 @@ custom_lib_path use_plucene indexing_directory enable_page_deletion admin_pass stylesheet_url site_name navbar_on_home_page home_name site_desc default_city default_country contact_email default_language - formatting_rules_node formatting_rules_link backlinks_in_title template_path custom_template_path - geo_handler ellipsoid + formatting_rules_node formatting_rules_link backlinks_in_title template_path + custom_template_path geo_handler ellipsoid gmaps_api_key centre_long + centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84 ); my @questions = map { $_ . "__qu" } @variables; OpenGuides::Config->mk_accessors( @variables ); @@ -76,7 +77,12 @@ formatting_rules_link => "http://openguides.org/page/text_formatting", backlinks_in_title => 0, geo_handler => 1, - ellipsoid => "International" + ellipsoid => "International", + centre_long => 0, + centre_lat => 0, + default_gmaps_zoom => 5, + default_gmaps_search_zoom => 3, + force_wgs84 => 0 );
# See if we already have some config variables set. @@ -134,6 +140,12 @@ formatting_rules_link => "What URL do you want to use for the text formatting rules (leave blank to use a wiki node instead)?", backlinks_in_title => "Make node titles link to node backlinks (C2 style)?", ellipsoid => "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')", + gmaps_api_key => "Do you have a Google Maps API key to use with this guide? If you enter it here the Google Maps functionality will be automatically enabled.", + centre_long => "What is the longitude of the centre point of a map to draw for your guide? (This question can be ignored if you aren't using Google Maps)", + centre_lat => "What is the latitude of the centre point of a map to draw for your guide? (This question can be ignored if you aren't using Google Maps)", + default_gmaps_zoom => "What default zoom level shall we use for Google Maps? (This question can be ignored if you aren't using Google Maps)", + default_gmaps_search_zoom => "What default zoom level shall we use for Google Maps in the search results? (This question can be ignored if you aren't using Google Maps)", + force_wgs84 => "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?" );
foreach my $var ( keys %questions ) { @@ -222,6 +234,18 @@
=item * ellipsoid (default: C<International>)
+=item * gmaps_api_key + +=item * centre_long + +=item * centre_lat + +=item * default_gmaps_zoom + +=item * default_gmaps_search_zoom + +=item * force_wgs84 + =back
=head1 AUTHOR
Modified: trunk/lib/OpenGuides/Template.pm =================================================================== --- trunk/lib/OpenGuides/Template.pm 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/lib/OpenGuides/Template.pm 2005-12-21 18:16:36 UTC (rev 730) @@ -86,6 +86,8 @@
=item * C<home_name>
+=item * C<gmaps_api_key> + =back
=over @@ -153,6 +155,7 @@ enable_page_deletion => $enable_page_deletion, language => $config->default_language, default_city => $default_city, + gmaps_api_key => $config->gmaps_api_key };
if ($args{node}) {
Modified: trunk/lib/OpenGuides/Utils.pm =================================================================== --- trunk/lib/OpenGuides/Utils.pm 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/lib/OpenGuides/Utils.pm 2005-12-21 18:16:36 UTC (rev 730) @@ -2,7 +2,7 @@
use strict; use vars qw( $VERSION ); -$VERSION = '0.08'; +$VERSION = '0.09';
use Carp qw( croak ); use CGI::Wiki; @@ -216,7 +216,46 @@ return $wiki; }
+=item B<get_wgs84_coords>
+Returns coordinate data suitable for use with Google Maps (and other GIS +systems that assume WGS-84 data). + + my ($wgs84_long, $wgs84_lat) = OpenGuides::Utils->get_wgs84_coords( + longitude => $longitude, + latitude => $latitude, + config => $config + ); + +=cut + +sub get_wgs84_coords { + my ($self, %args) = @_; + my ($longitude, $latitude, $config) = ($args{longitude}, $args{latitude}, + $args{config}) + or croak "No longitude supplied to get_wgs84_coords"; + croak "geo_handler not defined!" unless $config->geo_handler; + if ($config->force_wgs84) { + # Only as a rough approximation, good enough for large scale guides + return ($longitude, $latitude); + } elsif ($config->geo_handler == 1) { + # Do conversion here + return undef; + } elsif ($config->geo_handler == 2) { + # Do conversion here + return undef; + } elsif ($config->geo_handler == 3) { + if ($config->ellipsoid eq "WGS-84") { + return ($longitude, $latitude); + } else { + # Do conversion here + return undef; + } + } else { + croak "Invalid geo_handler config option $config->geo_handler"; + } +} + =back
=head1 AUTHOR @@ -225,7 +264,7 @@
=head1 COPYRIGHT
- Copyright (C) 2003-2004 The OpenGuides Project. All Rights Reserved. + Copyright (C) 2003-2005 The OpenGuides Project. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/lib/OpenGuides.pm 2005-12-21 18:16:36 UTC (rev 730) @@ -171,6 +171,10 @@ my $modified = $node_data{last_modified}; my %metadata = %{$node_data{metadata}};
+ my ($wgs84_long, $wgs84_lat) = OpenGuides::Utils->get_wgs84_coords( + longitude => $metadata{longitude}[0], + latitude => $metadata{latitude}[0], + config => $config); if ($args{format} && $args{format} eq 'raw') { print "Content-Type: text/plain\n\n"; print $raw; @@ -192,6 +196,10 @@ node => $id, language => $config->default_language, oldid => $oldid, + enable_gmaps => 1, + display_google_maps => $self->get_cookie("display_google_maps"), + wgs84_long => $wgs84_long, + wgs84_lat => $wgs84_lat );
if ( $raw =~ /^#REDIRECT\s+(.+?)\s*$/ ) { @@ -542,6 +550,18 @@ elsif ( $args{format} eq "plain" ) { $template = "plain_index.tt"; $conf{content_type} = "text/plain"; + } elsif ( $args{format} eq "map" ) { + my $q = CGI->new; + $tt_vars{zoom} = $q->param('zoom') || ''; + $tt_vars{lat} = $q->param('lat') || ''; + $tt_vars{long} = $q->param('long') || ''; + $tt_vars{centre_long} = $self->config->centre_long; + $tt_vars{centre_lat} = $self->config->centre_lat; + $tt_vars{default_gmaps_zoom} = $self->config->default_gmaps_zoom; + $tt_vars{enable_gmaps} = 1; + $tt_vars{display_google_maps} = 1; # override for this page + $template = "map_index.tt"; + } } else { $template = "site_index.tt"; @@ -928,7 +948,6 @@ return $cookie_data{$pref_name}; }
- =back
=head1 BUGS AND CAVEATS
Modified: trunk/preferences.cgi =================================================================== --- trunk/preferences.cgi 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/preferences.cgi 2005-12-21 18:16:36 UTC (rev 730) @@ -33,6 +33,7 @@ my $edit_type = $cgi->param("default_edit_type") || "normal"; my $expires = $cgi->param("cookie_expires") || "month"; my $track_rc = $cgi->param("track_recent_changes_views") || 0; + my $gmaps = $cgi->param("display_google_maps") || 0; my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( config => $config, username => $username, @@ -44,6 +45,7 @@ default_edit_type => $edit_type, cookie_expires => $expires, track_recent_changes_views => $track_rc, + display_google_maps => $gmaps ); my @cookies = ( $prefs_cookie ); # If they've asked not to have their recent changes visits tracked, @@ -71,6 +73,7 @@ default_edit_type => $edit_type, cookie_expires => $expires, track_recent_changes_views => $track_rc, + display_google_maps => $gmaps } ); }
Added: trunk/t/28_wgs84_coords.t =================================================================== --- trunk/t/28_wgs84_coords.t 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/t/28_wgs84_coords.t 2005-12-21 18:16:36 UTC (rev 730) @@ -0,0 +1,27 @@ +use strict; +use CGI::Wiki::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +plan tests => 2; + +# Clear out the database from any previous runs. +unlink "t/node.db"; + +my $config = OpenGuides::Test->make_basic_config; +$config->force_wgs84 (1); + +my $guide = OpenGuides->new( config => $config ); + +my ($longitude, $latitude) = (0, 0); + +my ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( + longitude => $longitude, + latitude => $latitude, + config => $config); + +is( $wgs_long, $longitude, + "get_wgs84_coords returns the original longitude when force_wgs84 is on"); +is( $wgs_lat, $latitude, + "get_wgs84_coords returns the original latitude when force_wgs84 is on");
Property changes on: trunk/t/28_wgs84_coords.t ___________________________________________________________________ Name: svn:executable + *
Modified: trunk/templates/header.tt =================================================================== --- trunk/templates/header.tt 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/templates/header.tt 2005-12-21 18:16:36 UTC (rev 730) @@ -28,5 +28,22 @@ [% IF deter_robots %] <meta name="robots" content="noindex,nofollow" /> [% END %] + [% IF enable_gmaps AND display_google_maps AND gmaps_api_key %] + <script src="http://maps.google.com/maps?file=api&v=1&key=[% gmaps_api_key %]" type="text/javascript"></script> + [% END %] </head> <body> + [% IF enable_gmaps AND display_google_maps AND gmaps_api_key %] + <script defer="defer" type="text/javascript"> + //<![CDATA[ + var baseIcon = new GIcon(); + baseIcon.image = "http://www.google.com/mapfiles/marker.png"; + baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png"; + baseIcon.iconSize = new GSize(10, 17); + baseIcon.shadowSize = new GSize(20, 17); + baseIcon.iconAnchor = new GPoint(5, 17); + baseIcon.infoWindowAnchor = new GPoint(9, 2); + baseIcon.infoShadowAnchor = new GPoint(9, 12); + //]]> + </script> + [% END %]
Modified: trunk/templates/node.tt =================================================================== --- trunk/templates/node.tt 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/templates/node.tt 2005-12-21 18:16:36 UTC (rev 730) @@ -8,6 +8,23 @@ <div id="redirect_message">(redirected from <a href="[% full_cgi_url %]?id=[% oldid %];redirect=0">[% oldid.replace('_', ' ') %]</a>)</div> [% END %]
+[% IF wgs84_lat AND wgs84_long AND display_google_maps and gmaps_api_key %] + <div id="map" style="float:right; width: 300px; height: 200px"></div> + <script defer="defer" type="text/javascript"> + //<![CDATA[ + var map = new GMap(document.getElementById("map")); + map.addControl(new GSmallMapControl()); + map.centerAndZoom(new GPoint([% longitude %], [% latitude %]), 3); + var point0 = new GPoint([% wgs84_long %], [% wgs84_lat %]); + var marker0 = new GMarker(point0,baseIcon); + GEvent.addListener(marker0, "click", function() { + marker0.openInfoWindowHtml("[% node_name %]"); + }); + map.addOverlay(marker0); + //]]> + </script> +[% END %] + [% IF current %] [% IF backlinks_in_title AND is_indexable_node %] <h2 class="node_name"><a href="[% cgi_url %]?action=index;index_type=[% CGI.escape(index_type) %];index_value=[% CGI.escape(index_value) %]">[% node_name %]</a></h2>
Modified: trunk/templates/preferences.tt =================================================================== --- trunk/templates/preferences.tt 2005-12-03 17:06:12 UTC (rev 729) +++ trunk/templates/preferences.tt 2005-12-21 18:16:36 UTC (rev 730) @@ -75,6 +75,17 @@ <label for="track_recent_changes_views">Track my visits to Recent Changes and offer me a link for “changes since I last viewed Recent Changes”.</label> </p>
+ [% IF gmaps_api_key %] + <p> + [% IF display_google_maps %] + <input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" checked="1" /> + [% ELSE %] + <input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" /> + [% END %] + <label for="display_google_maps">Display Google Maps.</label> + </p> + [% END %] + <p> <label for="default_edit_type">Default edit type:</label> <select name="default_edit_type"> @@ -150,6 +161,12 @@ [% UNLESS track_recent_changes_views %] not [% END %] be tracked.</p>
+ [% IF gmaps_api_key %] + <p>Google Maps will + [% UNLESS display_google_maps %] not [% END %] + be displayed.</p> + [% END %] + <p>Default edit type set to [% IF default_edit_type == 'normal' %] “Normal edit”.
openguides-commits@lists.openguides.org