Changeset 1336


Ignore:
Timestamp:
Apr 14, 2012, 11:56:32 AM (10 years ago)
Author:
kake
Message:

Added support for using Leaflet instead of the Google Maps API.

Location:
trunk
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r1328 r1336  
    4747   qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title
    4848      moderation_requires_password enable_node_image enable_common_categories
    49       enable_common_locales recent_changes_on_home_page
     49      enable_common_locales recent_changes_on_home_page use_leaflet
    5050      random_page_omits_locales random_page_omits_categories
    5151      content_above_navbar_in_html show_gmap_in_node_display force_wgs84
     
    9898my $install_directory; # used to suggest template paths
    9999my $use_plucene = 1; # keep track of this so we know what to put in prereqs
     100my $use_leaflet; # if true, we skip the GMaps questions
     101my %gmaps_vars = map { $_ => 1 } qw( gmaps_api_key centre_long centre_lat
     102                                default_gmaps_zoom default_gmaps_search_zoom );
    100103my $centre_lat = ''; # contains centre lat derived from Google Maps URL
    101104foreach my $var ( qw(
     
    107110   random_page_omits_categories content_above_navbar_in_html home_name
    108111   site_desc default_city default_country contact_email default_language
    109    formatting_rules_node backlinks_in_title gmaps_api_key centre_long
    110    centre_lat show_gmap_in_node_display default_gmaps_zoom
     112   formatting_rules_node backlinks_in_title use_leaflet gmaps_api_key
     113   centre_long centre_lat show_gmap_in_node_display default_gmaps_zoom
    111114   default_gmaps_search_zoom force_wgs84 google_analytics_key
    112115   licence_name licence_url licence_info_url moderation_requires_password
     
    149152    }
    150153
     154    # If we're using Leaflet, we can skip the GMaps stuff.  Don't erase any
     155    # previous answers from their config file though.
     156    if ( $use_leaflet && $gmaps_vars{$var} ) {
     157        push @answers, { question => $qu,
     158                         variable => $var,
     159                         value => $val };
     160        next;
     161    }
     162
    151163    # Make sensible suggestions for template paths if we don't already
    152164    # have them stored.  Not really a default, but a useful hint/shortcut.
     
    197209    # From Module::Build docs: ->y_n returns a Perl boolean true or false.
    198210    $use_plucene = 1 if $var eq "use_plucene" and $val;
     211
     212    # If they've just chosen to use Leaflet, we won't need to ask any of the
     213    # GMaps questions.
     214    $use_leaflet = 1 if $var eq "use_leaflet" and $val;
    199215
    200216    # Make sure that script_url ends in a /
     
    367383                      "home_node.tt",
    368384                      "map_index.tt",
     385                      "map_index_leaflet.tt",
    369386                      "missing_metadata.tt",
    370387                      "moderate_confirm.tt",
     
    403420
    404421$build->config_data( __static_files => [
    405     # XXX to be supplied when we have some
     422        "map-leaflet.js",
    406423    ] );
    407424
  • trunk/INSTALL

    r1306 r1336  
    224224wiki at http://c2.com/cgi/wiki), but is not intuitive.
    225225
     226  "Do you want to use the Leaflet mapping library?"
     227
     228Answer "y" or "n", but "y" is recommended.  In version 0.67 of OpenGuides,
     229we switched from using the Google Maps API to the open source Leaflet mapping
     230library.  For now, Google Maps support is retained for legacy reasons, but is
     231deprecated and will be removed in the future.  We therefore recommend that
     232you answer "y" to this question.
     233
     234  "Would you like to display a map on every node that has geodata?"
     235
     236Answer "y" or "n".  Note that an answer of "y" will only take effect if you've
     237either chosen to use the Leaflet mapping library, or you've supplied a Google
     238Maps API key.  Note further that users can choose to turn this off in their
     239preferences.
     240 
    226241  "Do you have a Google Maps API key to use with this guide?"
    227242
    228 If you want Google Maps integration, you need to register with Google to get
    229 an API key. Visit http://www.google.com/apis/maps/signup.html and follow the
     243As of version 0.67 of OpenGuides, we recommend using the Leaflet mapping
     244library instead of Google Maps - our Google Maps support is out of date and
     245no longer maintained.  However, if you do want to use Google Maps, you need
     246to register with Google to get an API key. Visit
     247http://www.google.com/apis/maps/signup.html and follow the
    230248instructions. Paste the great long string into the console window where you
    231249are installing. See README.GMAPS for more information.
     
    234252  "What is the latitude of the centre point of a map to draw for your guide?"
    235253
    236 It's probably a good idea to pick some notionally central point for your
     254This is only necessary if you're using Google Maps - our Leaflet code will
     255figure this out for you.  If you do choose to use Google Maps, it's probably
     256a good idea to pick some notionally central point for your
    237257guide. For example, Carfax for Oxford, Charing Cross for London. As a
    238258convenience, you may paste in a Google Maps URL for the centre longitude
     
    244264The defaults are probably appropriate in most cases.
    245265
    246   "Would you like to display a Google Map on every node that has geodata?"
    247 
    248 Answer "y" or "n".  Note that an answer of "y" will only take effect if you've
    249 supplied a Google Maps API key above.  Note further that users can choose to
    250 turn this off in their preferences.
    251  
    252266  "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?"
    253267
     
    337351
    338352If you want to use a UTM ellipsoid, WGS-84 is the best choice, as it
    339 will allow you to use the Google Maps support with the minimum of fuss.
     353will allow you to use the mapping support with the minimum of fuss.
    340354
    341355* Dependency errors
  • trunk/MANIFEST

    r1328 r1336  
    2828preferences.cgi
    2929search.cgi
     30static/map-leaflet.js
    3031templates/admin_home.tt
    3132templates/admin_revert_user.tt
     
    4647templates/home_node.tt
    4748templates/map_index.tt
     49templates/map_index_leaflet.tt
    4850templates/missing_metadata.tt
    4951templates/metadata.tt
     
    160162t/92_node_name_from_cgi_obj.t
    161163t/93_redirect_without_spaces.t
     164t/94_leaflet.t
    162165t/templates/15_test.tt
    163166wiki.cgi
  • trunk/README.GMAPS

    r960 r1336  
     1NOTE: as of version 0.67, OpenGuides has switched from the Google Maps API
     2to the open source Leaflet mapping library.  Our Google Maps support is
     3out of date and no longer maintained.  To ensure you're using the latest
     4mapping code, set
     5
     6  use_leaflet = 1
     7
     8in your wiki.conf.
     9
     10The instructions below are retained for the benefit of legacy users.
     11
     12----------------------------------------------------------------------
     13
    114As of 0.52, OpenGuides supports Google Maps using the API. The support has a
    215few rough edges that still need ironing out, mostly relating to ellipsoids,
  • trunk/lib/OpenGuides.pm

    r1328 r1336  
    1515use vars qw( $VERSION );
    1616
    17 $VERSION = '0.66';
     17$VERSION = '0.67';
    1818
    1919=head1 NAME
     
    873873                    );
    874874
     875  # Or return the template variables (again, useful for writing tests).
     876  $guide->show_index(
     877                        type           => "category",
     878                        value          => "pubs",
     879                        format         => "map"
     880                        return_tt_vars => 1,
     881                    );
     882
    875883If either the C<type> or the C<value> parameter is omitted, then all pages
    876884will be returned.
     
    882890    my $wiki = $self->wiki;
    883891    my $formatter = $wiki->formatter;
     892    my $use_leaflet = $self->config->use_leaflet;
    884893    my %tt_vars;
    885894    my @selnodes;
     
    928937                        } sort @selnodes;
    929938
    930     # Convert the lat+long to WGS84 as required
     939    # Convert the lat+long to WGS84 as required.  If displaying a map
     940    # using Leaflet, also grab the min and max lat and long.
     941    my ( $min_lat, $max_lat, $min_long, $max_long );
    931942    for(my $i=0; $i<scalar @nodes;$i++) {
    932943        my $node = $nodes[$i];
     
    944955            push @{$nodes[$i]->{node_data}->{metadata}->{wgs84_long}}, $wgs84_long;
    945956            push @{$nodes[$i]->{node_data}->{metadata}->{wgs84_lat}},  $wgs84_lat;
     957            if ( $use_leaflet ) {
     958                if ( defined $wgs84_lat && $wgs84_lat =~ /^[-.\d]+$/
     959                     && defined $wgs84_long && $wgs84_long =~ /^[-.\d]+$/ ) {
     960                    $node->{has_geodata} = 1;
     961                    $node->{wgs84_lat} = $wgs84_lat;
     962                    $node->{wgs84_long} = $wgs84_long;
     963                    if ( !defined $min_lat ) {
     964                        $min_lat = $max_lat = $wgs84_lat;
     965                    } elsif ( $wgs84_lat < $min_lat ) {
     966                        $min_lat = $wgs84_lat;
     967                    } elsif ( $wgs84_lat > $max_lat ) {
     968                        $max_lat = $wgs84_lat;
     969                    }
     970                    if ( !defined $min_long ) {
     971                        $min_long = $max_long = $wgs84_long;
     972                    } elsif ( $wgs84_long < $min_long ) {
     973                        $min_long = $wgs84_long;
     974                    } elsif ( $wgs84_long > $max_long ) {
     975                        $max_long = $wgs84_long;
     976                    }
     977                }
     978            }
    946979        }
    947980    }
     
    962995            $conf{content_type} = "text/plain";
    963996        } elsif ( $args{format} eq "map" ) {
    964             my $q = CGI->new;
    965             $tt_vars{zoom} = $q->param('zoom') || '';
    966             $tt_vars{lat} = $q->param('lat') || '';
    967             $tt_vars{long} = $q->param('long') || '';
    968             $tt_vars{map_type} = $q->param('map_type') || '';
    969             $tt_vars{centre_long} = $self->config->centre_long;
    970             $tt_vars{centre_lat} = $self->config->centre_lat;
    971             $tt_vars{default_gmaps_zoom} = $self->config->default_gmaps_zoom;
    972             $tt_vars{enable_gmaps} = 1;
    973997            $tt_vars{display_google_maps} = 1; # override for this page
    974             $template = "map_index.tt";
    975            
     998            if ( $use_leaflet ) {
     999                if ( defined $min_lat ) {
     1000                    %tt_vars = ( %tt_vars,
     1001                        min_lat     => $min_lat,
     1002                        max_lat     => $max_lat,
     1003                        min_long    => $min_long,
     1004                        max_long    => $max_long,
     1005                        centre_lat  => ( ( $max_lat + $min_lat ) / 2 ),
     1006                        centre_long => ( ( $max_long + $min_long ) / 2 ),
     1007                    );
     1008                }
     1009                $template = "map_index_leaflet.tt";
     1010            } else {
     1011                my $q = CGI->new;
     1012                $tt_vars{zoom} = $q->param('zoom') || '';
     1013                $tt_vars{lat} = $q->param('lat') || '';
     1014                $tt_vars{long} = $q->param('long') || '';
     1015                $tt_vars{map_type} = $q->param('map_type') || '';
     1016                $tt_vars{centre_long} = $self->config->centre_long;
     1017                $tt_vars{centre_lat} = $self->config->centre_lat;
     1018                $tt_vars{default_gmaps_zoom}
     1019                                      = $self->config->default_gmaps_zoom;
     1020                $tt_vars{enable_gmaps} = 1;
     1021                $template = "map_index.tt";
     1022            }
    9761023        } elsif( $args{format} eq "rss" || $args{format} eq "atom") {
    9771024            # They really wanted a recent changes style rss/atom feed
     
    10001047        $template = "site_index.tt";
    10011048    }
     1049
     1050    return %tt_vars if $args{return_tt_vars};
    10021051
    10031052    %conf = (
  • trunk/lib/OpenGuides/Config.pm

    r1281 r1336  
    2121   formatting_rules_node formatting_rules_link backlinks_in_title template_path
    2222   custom_template_path geo_handler ellipsoid gmaps_api_key centre_long
    23    show_gmap_in_node_display google_analytics_key
     23   show_gmap_in_node_display google_analytics_key use_leaflet
    2424   centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84
    2525   licence_name licence_url licence_info_url
     
    105105                     geo_handler => 1,
    106106                     ellipsoid => "WGS-84",
     107                     use_leaflet => 0,
    107108                     show_gmap_in_node_display => 1,
    108109                     centre_long => 0,
     
    189190        backlinks_in_title => "Make node titles link to node backlinks (C2 style)?",
    190191        ellipsoid => "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')",
    191         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.",
    192         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). You may paste in a Google Maps URL here (hint: copy URL from 'Link to this page')",
    193         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)",
     192        use_leaflet => "Do you want to use the Leaflet mapping library? (this is recommended)",
     193        gmaps_api_key => "Do you have a Google Maps API key to use with this guide? If so, enter it here. (Note: our Google Maps support is deprecated, and we recommend you choose to use Leaflet instead.)",
     194        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 - we recommend you use Leaflet instead, as our Leaflet code will figure this out for you.) You may paste in a Google Maps URL here (hint: copy URL from 'Link to this page')",
     195        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 - we recommend you use Leaflet instead, as our Leaflet code will figure this out for you.)",
    194196        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)",
    195197        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)",
    196         show_gmap_in_node_display => "Would you like to display a Google Map on every node that has geodata? (This question can be ignored if you aren't using Google Maps)",
     198        show_gmap_in_node_display => "Would you like to display a map on every node that has geodata?",
    197199        force_wgs84 => "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?",
    198200        google_analytics_key => "Do you have a Google Analytics key to use with this guide? If you enter it here, then Google Analytics functionality will be automatically enabled.",
     
    310312=item * ellipsoid (default: C<WGS-84>)
    311313
     314=item * use_leaflet
     315
    312316=item * gmaps_api_key
    313317
     
    338342=item * static_path
    339343
    340 =item * static_url
     344=item * static_url (this is constrained to always end in C</>)
     345
     346=cut
     347
     348sub static_url {
     349    my $self = shift;
     350    # See perldoc Class::Accessor - can't just use SUPER.
     351    my $url = $self->_static_url_accessor( @_ );
     352    $url .= "/" unless (defined $url && $url =~ /\/$/);
     353    return $url;
     354}
    341355
    342356=item * send_moderation_notifications
     
    356370=head1 COPYRIGHT
    357371
    358      Copyright (C) 2004-2010 The OpenGuides Project.  All Rights Reserved.
     372     Copyright (C) 2004-2012 The OpenGuides Project.  All Rights Reserved.
    359373
    360374The OpenGuides distribution is free software; you can redistribute it
  • trunk/t/13_cookies.t

    r1236 r1336  
    6969                                     "...and recent changes tracking" );
    7070is( $prefs{display_google_maps}, "gm_pref",
    71                                      "...and Google Maps display preference" );
     71                                     "...and map display preference" );
    7272is( $prefs{is_admin}, "admin_pref",
    7373                                     "...and admin preference" );
  • trunk/t/46_map_in_node_display.t

    r1273 r1336  
    1717}
    1818
    19 plan tests => 4;
     19plan tests => 10;
    2020
    2121my ( $config, $guide, $wiki, $cookie, $output );
     
    3737                            );
    3838
    39 # Maps shouldn't show up if there's no API key.
     39# Maps shouldn't show up if there's no API key and we're not using Leaflet.
    4040$config->show_gmap_in_node_display( 1 );
     41$config->use_leaflet( 0 );
    4142$cookie = OpenGuides::CGI->make_prefs_cookie(
    4243                                              config => $config,
     
    5152$output =~ s/^Content-Type.*[\r\n]+//m;
    5253Test::HTML::Content::no_tag( $output, "div", { id => "map" },
    53                              "Google map omitted from node if no API key" );
     54               "Map omitted from node if no API key and not using Leaflet" );
    5455
    55 # And they should if there is.
     56# And they should if there is a Google API key.
    5657$config->gmaps_api_key( "This is not a real API key." );
    5758$output = $guide->display_node(
     
    6162$output =~ s/^Content-Type.*[\r\n]+//m;
    6263Test::HTML::Content::tag_ok( $output, "div", { id => "map" },
    63                              "Google map shown on node if we have an API key");
     64                             "Map shown on node if we have a Google API key");
    6465
    6566# But not if the user doesn't want them.
     
    9192Test::HTML::Content::no_tag( $output, "div", { id => "map" },
    9293                             "...and not if the admin turned it off" );
     94
     95# Now test with Leaflet.
     96$cookie = OpenGuides::CGI->make_prefs_cookie(
     97                               config => $config, display_google_maps => 1 );
     98$ENV{HTTP_COOKIE} = $cookie;
     99$config->gmaps_api_key( "I still have a key but don't expect to use it" );
     100$config->show_gmap_in_node_display( 1 );
     101$config->use_leaflet( 1 );
     102
     103# Shouldn't get any of the GMap stuff.
     104$output = $guide->display_node(
     105                                id => "Red Lion",
     106                                return_output => 1,
     107                              );
     108unlike( $output, qr|new GMap|,
     109        "No invocation of GMap constructor when using Leaflet" );
     110unlike ( $output, qr|new GPoint|, "...nor GPoint" );
     111unlike ( $output, qr|new GIcon|, "...nor GIcon" );
     112
     113# Map should show in node if we're using Leaflet and have no GMap API key.
     114$config->gmaps_api_key( "" );
     115$output = $guide->display_node(
     116                                id => "Red Lion",
     117                                return_output => 1,
     118                              );
     119$output =~ s/^Content-Type.*[\r\n]+//m;
     120Test::HTML::Content::tag_ok( $output, "div", { id => "node_map_canvas" },
     121                             "Map shown on node if using Leaflet");
     122
     123# But not if the user doesn't want them.
     124$cookie = OpenGuides::CGI->make_prefs_cookie(
     125                                              config => $config,
     126                                              display_google_maps => 0,
     127                                            );
     128$ENV{HTTP_COOKIE} = $cookie;
     129$output = $guide->display_node(
     130                                id => "Red Lion",
     131                                return_output => 1,
     132                              );
     133$output =~ s/^Content-Type.*[\r\n]+//m;
     134Test::HTML::Content::no_tag( $output, "div", { id => "map" },
     135                             "...but not if the user turned it off" );
     136
     137# And not if the admin doesn't want them.
     138$config->show_gmap_in_node_display( 0 );
     139$cookie = OpenGuides::CGI->make_prefs_cookie(
     140                                              config => $config,
     141                                              display_google_maps => 1,
     142                                            );
     143$ENV{HTTP_COOKIE} = $cookie;
     144$output = $guide->display_node(
     145                                id => "Red Lion",
     146                                return_output => 1,
     147                              );
     148$output =~ s/^Content-Type.*[\r\n]+//m;
     149Test::HTML::Content::no_tag( $output, "div", { id => "map" },
     150                             "...and not if the admin turned it off" );
  • trunk/t/53_show_index.t

    r1273 r1336  
    1212}
    1313
    14 plan tests => 23; # 25 when all enabled
     14plan tests => 27; # 29 when all enabled
    1515
    1616# Clear out the database from any previous runs.
    17     OpenGuides::Test::refresh_db();
     17OpenGuides::Test::refresh_db();
    1818
    1919my $config = OpenGuides::Test->make_basic_config;
     
    108108
    109109SKIP: {
    110     skip "No Helmert Transform provider installed, can't test geo stuff", 6
     110    skip "No Helmert Transform provider installed, can't test geo stuff", 10
    111111      unless $has_helmert;
     112
     113    # This is testing the legacy stuff.
     114    $config->use_leaflet( 0 );
    112115
    113116    $output = eval {
     
    117120                          );
    118121    };
    119     is( $@, "", "->show_index doesn't die when asked for map" );
     122    is( $@, "", "Using GMaps: ->show_index doesn't die when asked for map" );
    120123    like( $output, qr|Content-Type: text/html|,
    121           "Map output gets content-type of text/html" );
    122     like( $output, qr|new GMap|, "Really is google map" );
     124          "...map output gets content-type of text/html" );
     125    like( $output, qr|new GMap|, "...really is google map" );
    123126    my @points = ($output =~ /point\d+ = (new GPoint\(.*?, .*?\))/g);
    124     is( 1, scalar @points, "Right number of nodes included on map" );
     127    is( 1, scalar @points, "...right number of nodes included on map" );
    125128
    126129    # -1.259687,51.754813
    127     like( $points[0], qr|51.75481|, "Has latitude");
    128     like( $points[0], qr|-1.25968|, "Has longitude");
     130    like( $points[0], qr|51.75481|, "...has latitude");
     131    like( $points[0], qr|-1.25968|, "...has longitude");
     132
     133    # But we don't want the GMaps stuff if we're using Leaflet.
     134    $config->use_leaflet( 1 );
     135
     136    $output = eval {
     137        $guide->show_index(
     138                            return_output => 1,
     139                            format        => "map",
     140                          );
     141    };
     142
     143    is( $@, "", "Using Leaflet: ->show_index doesn't die when asked for map" );
     144    like( $output, qr|Content-Type: text/html|,
     145          "...map output gets content-type of text/html" );
     146    unlike( $output, qr|new GMap|, "...no invocation of GMap constructor" );
     147    unlike ( $output, qr|new GPoint|, "...nor GPoint" );
    129148}
  • trunk/t/59_preferences.t

    r1273 r1336  
    2424}
    2525
    26 plan tests => 2;
     26plan tests => 4;
    2727
    2828    OpenGuides::Test::refresh_db();
     
    3232my $wiki = $guide->wiki;
    3333
     34# If we have a google API key and node maps are enabled, we should see the
     35# checkbox for this pref.
    3436$config->gmaps_api_key( "This is not a real API key." );
    3537$config->show_gmap_in_node_display( 1 );
     
    4042                                               );
    4143$ENV{HTTP_COOKIE} = $cookie;
    42 
    43 # If the google API is present and node maps are enabled, we should have the pref
    44 Test::HTML::Content::tag_ok( get_output($wiki, $config), 'input',
    45                              { type => 'checkbox', name => 'display_google_maps' },
    46                              'Google maps pref shown'
    47                            );
     44Test::HTML::Content::tag_ok( get_output($wiki, $config),
     45  "input", { type => "checkbox", name => "display_google_maps" },
     46  "Node map preference checkbox shown when we have a GMaps API key." );
    4847
    4948# But not if the node map is globally disabled
    5049$config->show_gmap_in_node_display( 0 );
    51 Test::HTML::Content::no_tag( get_output($wiki, $config), 'input',
    52                              { type => 'checkbox', name => 'display_google_maps' },
    53                              'No google maps prefs if node maps disabled'
    54                            );
     50Test::HTML::Content::no_tag( get_output($wiki, $config),
     51  "input", { type => "checkbox", name => "display_google_maps" },
     52  "...but not when node maps are globally disabled." );
     53
     54# Now test with Leaflet enabled and no Google API key.
     55$config->gmaps_api_key( "" );
     56$config->show_gmap_in_node_display( 1 );
     57$config->use_leaflet( 1 );
     58
     59my $cookie = OpenGuides::CGI->make_prefs_cookie(
     60                                                 config => $config,
     61                                                 display_google_maps => 1,
     62                                               );
     63$ENV{HTTP_COOKIE} = $cookie;
     64Test::HTML::Content::tag_ok( get_output($wiki, $config),
     65  "input", { type => "checkbox", name => "display_google_maps" },
     66  "Node map preference checkbox shown when we're using Leaflet." );
     67
     68$config->show_gmap_in_node_display( 0 );
     69Test::HTML::Content::no_tag( get_output($wiki, $config),
     70  "input", { type => "checkbox", name => "display_google_maps" },
     71  "...but not when node maps are globally disabled." );
    5572
    5673sub get_output {
  • trunk/templates/header.tt

    r1178 r1336  
    2727", " UNLESS loop.last %][% END %][% END %]" />
    2828  [% END %]
     29
    2930  [% IF stylesheet %]
    3031    <link rel="stylesheet" href="[% stylesheet %]" type="text/css" title="Stylesheet for [% site_name %]" />
    3132  [% END %]
     33  [% IF config.use_leaflet %]
     34    <link rel="stylesheet" href="http://code.leafletjs.com/leaflet-0.3.1/leaflet.css" />
     35    <!--[if lte IE 8]>
     36      <link rel="stylesheet" href="http://code.leafletjs.com/leaflet-0.3.1/leaflet.ie.css" />
     37    <![endif]-->
     38  [% END %]
     39
    3240  [% IF feed_base %]
    3341    <link rel="alternate" type="application/rss+xml" title="Page as RSS" href="[% feed_base %];format=rss" />
     
    6068     href="[% source_site or full_cgi_url %]?id=[% node_param %];action=edit">
    6169  [% END %]
    62   [% IF enable_gmaps AND display_google_maps AND gmaps_api_key %]
    63     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=[% gmaps_api_key %]" type="text/javascript"></script>
     70
     71  [% IF display_google_maps %]
     72    [% IF config.use_leaflet %]
     73      <script
     74         src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
     75         type="text/javascript"></script>
     76      <script src="http://code.leafletjs.com/leaflet-0.3.1/leaflet.js"
     77              type="text/javascript"></script>
     78      <script src="[% config.static_url %]map-leaflet.js"
     79              type="text/javascript"></script>
     80    [% ELSIF enable_gmaps AND gmaps_api_key %]
     81      <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=[% gmaps_api_key %]" type="text/javascript"></script>
     82    [% END %]
    6483  [% END %]
    6584
     
    7291<body>
    7392  <div id="body_wrapper">
    74   [% IF enable_gmaps AND display_google_maps AND gmaps_api_key %]
     93  [% IF !config.use_leaflet AND enable_gmaps AND display_google_maps
     94     AND gmaps_api_key %]
    7595    <script defer="defer" type="text/javascript">
    7696      //<![CDATA[
  • trunk/templates/node.tt

    r1311 r1336  
    1717[% END %]
    1818
    19 [% IF wgs84_lat AND wgs84_long AND display_google_maps and gmaps_api_key %]
    20   <div id="map" style="float:right; width: 300px; height: 200px"></div>
    21   <script defer="defer" type="text/javascript">
    22   //<![CDATA[
    23     var map = new GMap(document.getElementById("map"));
    24     map.addControl(new GSmallMapControl());
    25     map.centerAndZoom(new GPoint([% wgs84_long %], [% wgs84_lat %]), 3);
    26     var point0 = new GPoint([% wgs84_long %], [% wgs84_lat %]);
    27     var marker0 = new GMarker(point0,baseIcon);
    28     GEvent.addListener(marker0, "click", function() {
    29       marker0.openInfoWindowHtml("[% node_name %]");
    30       });
    31     map.addOverlay(marker0);
    32   //]]>
    33   </script>
     19[% IF wgs84_lat AND wgs84_long AND display_google_maps %]
     20  [% IF config.use_leaflet %]
     21    <div id="node_map_canvas" style="float:right; width: 300px; height: 200px"></div>
     22    <script type="text/javascript">
     23      map_div_id = 'node_map_canvas';
     24      centre_lat = [% wgs84_lat %];
     25      centre_long = [% wgs84_long %];
     26      function add_markers() {
     27        var position = new L.LatLng( [% wgs84_lat %], [% wgs84_long %] );
     28        marker = new L.Marker( position, { icon: new gicon() } );
     29        map.addLayer( marker );
     30        marker.bindPopup( '[% node_name %]' );
     31      }
     32    </script>
     33  [% ELSIF gmaps_api_key %]
     34    <div id="map" style="float:right; width: 300px; height: 200px"></div>
     35    <script defer="defer" type="text/javascript">
     36    //<![CDATA[
     37      var map = new GMap(document.getElementById("map"));
     38      map.addControl(new GSmallMapControl());
     39      map.centerAndZoom(new GPoint([% wgs84_long %], [% wgs84_lat %]), 3);
     40      var point0 = new GPoint([% wgs84_long %], [% wgs84_lat %]);
     41      var marker0 = new GMarker(point0,baseIcon);
     42      GEvent.addListener(marker0, "click", function() {
     43        marker0.openInfoWindowHtml("[% node_name %]");
     44        });
     45      map.addOverlay(marker0);
     46    //]]>
     47    </script>
     48  [% END %]
    3449[% END %]
    3550
  • trunk/templates/preferences.tt

    r1236 r1336  
    7676    </p>
    7777
    78     [% IF gmaps_api_key AND config.show_gmap_in_node_display %]
     78    [% IF ( config.use_leaflet OR gmaps_api_key )
     79       AND config.show_gmap_in_node_display %]
    7980      <p>
    8081        [% IF prefs.display_google_maps %]
     
    8384          <input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" />
    8485        [% END %]
    85         <label for="display_google_maps">Display Google Maps.</label>
     86        <label for="display_google_maps">Display a map on every page with geodata.</label>
    8687      </p>
    8788    [% END %]
     
    166167  be tracked.</p>
    167168
    168   [% IF prefs.gmaps_api_key AND config.show_gmap_in_node_display %]
    169     <p>Google Maps will
    170       [% UNLESS display_google_maps %] not [% END %]
    171     be displayed.</p>
     169  [% IF ( config.use_leaflet OR gmaps_api_key )
     170     AND config.show_gmap_in_node_display %]
     171    <p>Maps will
     172      [% UNLESS prefs.display_google_maps %] not [% END %]
     173    be displayed on pages with geodata.</p>
    172174  [% END %]
    173175
Note: See TracChangeset for help on using the changeset viewer.