Changeset 730


Ignore:
Timestamp:
Dec 21, 2005, 6:16:36 PM (16 years ago)
Author:
Dominic Hargreaves
Message:

Add initial google maps support, see #46 but this isn't yet a complete
implementation so leaving the bug open for now.

Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r729 r730  
    7777   admin_pass stylesheet_url site_name navbar_on_home_page home_name
    7878   site_desc default_city default_country contact_email default_language
    79    formatting_rules_node backlinks_in_title
     79   formatting_rules_node backlinks_in_title gmaps_api_key centre_long
     80   centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84
    8081  ) ) {
    8182    my $q_method = $var . "__qu";
  • trunk/Changes

    r729 r730  
    88        Fix missing bracket in node.tt.
    99        Add custom_node template just below main content in node.tt.
     10        Google Maps support! There is a new index type,
     11        wiki.cgi?action=index;format=map, and maps appear in the node listings
     12        (the latter feature is user-configurable).
    1013        Fix <link> in RSS to point to RecentChanges page, not the feed itself.
    1114        #67 Default website for a page is now http://
  • trunk/lib/OpenGuides.pm

    r729 r730  
    172172    my %metadata   = %{$node_data{metadata}};
    173173
     174    my ($wgs84_long, $wgs84_lat) = OpenGuides::Utils->get_wgs84_coords(
     175                                        longitude => $metadata{longitude}[0],
     176                                        latitude => $metadata{latitude}[0],
     177                                        config => $config);
    174178    if ($args{format} && $args{format} eq 'raw') {
    175179      print "Content-Type: text/plain\n\n";
     
    193197                   language      => $config->default_language,
    194198                   oldid         => $oldid,
     199                   enable_gmaps  => 1,
     200                   display_google_maps => $self->get_cookie("display_google_maps"),
     201                   wgs84_long    => $wgs84_long,
     202                   wgs84_lat     => $wgs84_lat
    195203               );
    196204
     
    543551            $template = "plain_index.tt";
    544552            $conf{content_type} = "text/plain";
     553        } elsif ( $args{format} eq "map" ) {
     554            my $q = CGI->new;
     555            $tt_vars{zoom} = $q->param('zoom') || '';
     556            $tt_vars{lat} = $q->param('lat') || '';
     557            $tt_vars{long} = $q->param('long') || '';
     558            $tt_vars{centre_long} = $self->config->centre_long;
     559            $tt_vars{centre_lat} = $self->config->centre_lat;
     560            $tt_vars{default_gmaps_zoom} = $self->config->default_gmaps_zoom;
     561            $tt_vars{enable_gmaps} = 1;
     562            $tt_vars{display_google_maps} = 1; # override for this page
     563            $template = "map_index.tt";
     564           
    545565        }
    546566    } else {
     
    929949}
    930950
    931 
    932951=back
    933952
  • trunk/lib/OpenGuides/CGI.pm

    r729 r730  
    22use strict;
    33use vars qw( $VERSION );
    4 $VERSION = '0.06';
     4$VERSION = '0.07';
    55
    66use Carp qw( croak );
     
    3939      cookie_expires             => "never",
    4040      track_recent_changes_views => 1,
     41      display_google_maps        => 1
    4142  );
    4243
     
    8384      cookie_expires             => "never",
    8485      track_recent_changes_views => 1,
     86      display_google_maps        => 1
    8587  );
    8688
     
    125127                    exp        => $args{cookie_expires},
    126128                    trackrc    => $args{track_recent_changes_views} || 0,
     129                    gmaps      => $args{display_google_maps} || 0
    127130                  },
    128131        -expires => $expires,
     
    162165             cookie_expires             => $data{exp}        || "month",
    163166             track_recent_changes_views => $data{trackrc}    || 0,
     167             display_google_maps        => $data{gmaps}      || 0
    164168           );
    165169}
     
    256260=head1 COPYRIGHT
    257261
    258      Copyright (C) 2003-2004 The OpenGuides Project.  All Rights Reserved.
     262     Copyright (C) 2003-2005 The OpenGuides Project.  All Rights Reserved.
    259263
    260264This module is free software; you can redistribute it and/or modify it
  • trunk/lib/OpenGuides/Config.pm

    r729 r730  
    1010   admin_pass stylesheet_url site_name navbar_on_home_page home_name
    1111   site_desc default_city default_country contact_email default_language
    12    formatting_rules_node formatting_rules_link backlinks_in_title template_path custom_template_path
    13    geo_handler ellipsoid
     12   formatting_rules_node formatting_rules_link backlinks_in_title template_path
     13   custom_template_path geo_handler ellipsoid gmaps_api_key centre_long
     14   centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84
    1415);
    1516my @questions = map { $_ . "__qu" } @variables;
     
    7778                     backlinks_in_title => 0,
    7879                     geo_handler => 1,
    79                      ellipsoid => "International"
     80                     ellipsoid => "International",
     81                     centre_long => 0,
     82                     centre_lat => 0,
     83                     default_gmaps_zoom => 5,
     84                     default_gmaps_search_zoom => 3,
     85                     force_wgs84 => 0
    8086                   );
    8187
     
    135141        backlinks_in_title => "Make node titles link to node backlinks (C2 style)?",
    136142        ellipsoid => "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')",
     143        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.",
     144        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)",
     145        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)",
     146        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)",
     147        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)",
     148        force_wgs84 => "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?"
    137149    );
    138150
     
    223235=item * ellipsoid (default: C<International>)
    224236
     237=item * gmaps_api_key
     238
     239=item * centre_long
     240
     241=item * centre_lat
     242
     243=item * default_gmaps_zoom
     244
     245=item * default_gmaps_search_zoom
     246
     247=item * force_wgs84
     248
    225249=back
    226250
  • trunk/lib/OpenGuides/Template.pm

    r729 r730  
    8686
    8787=item * C<home_name>
     88
     89=item * C<gmaps_api_key>
    8890
    8991=back
     
    154156        language              => $config->default_language,
    155157        default_city          => $default_city,
     158        gmaps_api_key         => $config->gmaps_api_key
    156159    };
    157160
  • trunk/lib/OpenGuides/Utils.pm

    r729 r730  
    33use strict;
    44use vars qw( $VERSION );
    5 $VERSION = '0.08';
     5$VERSION = '0.09';
    66
    77use Carp qw( croak );
     
    217217}
    218218
     219=item B<get_wgs84_coords>
     220
     221Returns coordinate data suitable for use with Google Maps (and other GIS
     222systems that assume WGS-84 data).
     223
     224    my ($wgs84_long, $wgs84_lat) = OpenGuides::Utils->get_wgs84_coords(
     225                                        longitude => $longitude,
     226                                        latitude => $latitude,
     227                                        config => $config
     228                                   );
     229
     230=cut
     231
     232sub get_wgs84_coords {
     233    my ($self, %args) = @_;
     234    my ($longitude, $latitude, $config) = ($args{longitude}, $args{latitude},
     235                                           $args{config})
     236       or croak "No longitude supplied to get_wgs84_coords";
     237    croak "geo_handler not defined!" unless $config->geo_handler;
     238    if ($config->force_wgs84) {
     239        # Only as a rough approximation, good enough for large scale guides
     240        return ($longitude, $latitude);
     241    } elsif ($config->geo_handler == 1) {
     242        # Do conversion here
     243        return undef;
     244    } elsif ($config->geo_handler == 2) {
     245        # Do conversion here
     246        return undef;
     247    } elsif ($config->geo_handler == 3) {
     248        if ($config->ellipsoid eq "WGS-84") {
     249            return ($longitude, $latitude);
     250        } else {
     251            # Do conversion here
     252            return undef;
     253        }
     254    } else {
     255        croak "Invalid geo_handler config option $config->geo_handler";
     256    }
     257}
    219258
    220259=back
     
    226265=head1 COPYRIGHT
    227266
    228      Copyright (C) 2003-2004 The OpenGuides Project.  All Rights Reserved.
     267     Copyright (C) 2003-2005 The OpenGuides Project.  All Rights Reserved.
    229268
    230269This module is free software; you can redistribute it and/or modify it
  • trunk/preferences.cgi

    r729 r730  
    3434    my $expires      = $cgi->param("cookie_expires")             || "month";
    3535    my $track_rc     = $cgi->param("track_recent_changes_views") || 0;
     36    my $gmaps        = $cgi->param("display_google_maps")        || 0;
    3637    my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie(
    3738        config => $config,
     
    4546        cookie_expires         => $expires,
    4647        track_recent_changes_views => $track_rc,
     48        display_google_maps    => $gmaps
    4749    );
    4850    my @cookies = ( $prefs_cookie );
     
    7274                      cookie_expires             => $expires,
    7375                      track_recent_changes_views => $track_rc,
     76                      display_google_maps        => $gmaps
    7477                    }
    7578    );
  • trunk/templates/header.tt

    r729 r730  
    2929    <meta name="robots" content="noindex,nofollow" />
    3030  [% END %]
     31  [% IF enable_gmaps AND display_google_maps AND gmaps_api_key %]
     32    <script src="http://maps.google.com/maps?file=api&amp;v=1&amp;key=[% gmaps_api_key %]" type="text/javascript"></script>
     33  [% END %]
    3134</head>
    3235<body>
     36  [% IF enable_gmaps AND display_google_maps AND gmaps_api_key %]
     37    <script defer="defer" type="text/javascript">
     38      //<![CDATA[
     39        var baseIcon = new GIcon();
     40        baseIcon.image = "http://www.google.com/mapfiles/marker.png";
     41        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
     42        baseIcon.iconSize = new GSize(10, 17);
     43        baseIcon.shadowSize = new GSize(20, 17);
     44        baseIcon.iconAnchor = new GPoint(5, 17);
     45        baseIcon.infoWindowAnchor = new GPoint(9, 2);
     46        baseIcon.infoShadowAnchor = new GPoint(9, 12);
     47      //]]>
     48    </script>
     49  [% END %]
  • trunk/templates/node.tt

    r729 r730  
    77[% IF oldid %]
    88<div id="redirect_message">(redirected from <a href="[% full_cgi_url %]?id=[% oldid %];redirect=0">[% oldid.replace('_', ' ') %]</a>)</div>
     9[% END %]
     10
     11[% IF wgs84_lat AND wgs84_long AND display_google_maps and gmaps_api_key %]
     12  <div id="map" style="float:right; width: 300px; height: 200px"></div>
     13  <script defer="defer" type="text/javascript">
     14  //<![CDATA[
     15    var map = new GMap(document.getElementById("map"));
     16    map.addControl(new GSmallMapControl());
     17    map.centerAndZoom(new GPoint([% longitude %], [% latitude %]), 3);
     18    var point0 = new GPoint([% wgs84_long %], [% wgs84_lat %]);
     19    var marker0 = new GMarker(point0,baseIcon);
     20    GEvent.addListener(marker0, "click", function() {
     21      marker0.openInfoWindowHtml("[% node_name %]");
     22      });
     23    map.addOverlay(marker0);
     24  //]]>
     25  </script>
    926[% END %]
    1027
  • trunk/templates/preferences.tt

    r729 r730  
    7676    </p>
    7777
     78    [% IF gmaps_api_key %]
     79      <p>
     80        [% IF display_google_maps %]
     81          <input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" checked="1" />
     82        [% ELSE %]
     83          <input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" />
     84        [% END %]
     85        <label for="display_google_maps">Display Google Maps.</label>
     86      </p>
     87    [% END %]
     88
    7889    <p>
    7990      <label for="default_edit_type">Default edit type:</label>
     
    151162  be tracked.</p>
    152163
     164  [% IF gmaps_api_key %]
     165    <p>Google Maps will
     166      [% UNLESS display_google_maps %] not [% END %]
     167    be displayed.</p>
     168  [% END %]
     169
    153170  <p>Default edit type set to
    154171    [% IF default_edit_type == 'normal' %]
Note: See TracChangeset for help on using the changeset viewer.