Author: kake Date: 2012-04-16 19:29:47 +0100 (Mon, 16 Apr 2012) New Revision: 1344
Modified: trunk/lib/OpenGuides.pm trunk/t/94_leaflet.t trunk/templates/map_index_leaflet.tt Log: Deal with case where there are no nodes to display on map.
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2012-04-16 16:43:28 UTC (rev 1343) +++ trunk/lib/OpenGuides.pm 2012-04-16 18:29:47 UTC (rev 1344) @@ -1052,6 +1052,8 @@ centre_lat => ( ( $max_lat + $min_lat ) / 2 ), centre_long => ( ( $max_long + $min_long ) / 2 ), ); + } else { + $tt_vars{no_nodes_on_map} = 1; } $template = "map_index_leaflet.tt"; } else {
Modified: trunk/t/94_leaflet.t =================================================================== --- trunk/t/94_leaflet.t 2012-04-16 16:43:28 UTC (rev 1343) +++ trunk/t/94_leaflet.t 2012-04-16 18:29:47 UTC (rev 1344) @@ -11,7 +11,7 @@ "DBD::SQLite could not be used - no database to test with. ($error)"; }
-plan tests => 18; +plan tests => 21;
my $config = OpenGuides::Test->make_basic_config; $config->static_url( "http://example.com/static" ); @@ -149,3 +149,15 @@ "Nodes with zero latitude have has_geodata set." ); ok( $node_hash{"Zero Long"}{has_geodata}, "Nodes with zero longitude have has_geodata set." ); + +# Map shouldn't be displayed if none of the nodes have geodata. +%tt_vars = $guide->show_index( type => "locale", value => "Addiscombe", + format => "map", return_tt_vars => 1 ); +ok( $tt_vars{no_nodes_on_map}, + "no_nodes_on_map template variable is set when no nodes have geodata" ); +$output = $guide->show_index( type => "locale", value => "Addiscombe", + format => "map", return_output => 1 ); +unlike( $output, qr/not on map/, + "...and no warning about individual things not being on the map" ); +unlike( $output, qr/centre_lat/, + "...and no attempt to set centre_lat JavaScript variable" );
Modified: trunk/templates/map_index_leaflet.tt =================================================================== --- trunk/templates/map_index_leaflet.tt 2012-04-16 16:43:28 UTC (rev 1343) +++ trunk/templates/map_index_leaflet.tt 2012-04-16 18:29:47 UTC (rev 1344) @@ -19,50 +19,61 @@
<div id="map_index_node_list" style="height:400px; overflow:auto;float:right; width:30%"> <ul> - [% i = 0 %] - [% FOREACH node = nodes %] - [% i = i + 1 %] - <li> - [% IF node.has_geodata %] - <a href="#" onclick="return show_marker( [% i %] )">[% node.name | html %]</a> - [% ELSE %] - [% node.name | html %] (not on map — - <a href="?[% node.param %]">view info</a>) - [% END %] - </li> + [% IF no_nodes_on_map %] + [% FOREACH node = nodes %] + <li><a href="?[% node.param %]">[% node.name %]</a></li> + [% END %] + [% ELSE %] + [% i = 0 %] + [% FOREACH node = nodes %] + [% i = i + 1 %] + <li> + [% IF node.has_geodata %] + <a href="#" onclick="return show_marker( [% i %] )">[% node.name | html %]</a> + [% ELSE %] + [% node.name | html %] (not on map — + <a href="?[% node.param %]">view info</a>) + [% END %] + </li> + [% END %] [% END %] </ul> </div>
- <div id="map_index_canvas" style="width:60%; height:450px"></div> + <div id="map_index_canvas" style="width:60%; height:450px"> + [% IF no_nodes_on_map %] + <p class="no_nodes_on_map">No pages with geodata - nothing to display + on map!</p> + [% ELSE %] + <script type="text/javascript">
- <script type="text/javascript"> + map_div_id = 'map_index_canvas'; + centre_lat = [% centre_lat %]; + centre_long = [% centre_long %];
- map_div_id = 'map_index_canvas'; - centre_lat = [% centre_lat %]; - centre_long = [% centre_long %]; - - function add_markers() { - var node; - [% i = 0 %] - [% FOREACH node = nodes %] - [% i = i + 1 %] - [% IF node.has_geodata %] - node = { - name: '[% node.name | html %]', - param: '[% node.param %]', - [% address = node.node_data.metadata.address.list.first %] - [% IF address %] - address: '[% address | html %]', + function add_markers() { + var node; + [% i = 0 %] + [% FOREACH node = nodes %] + [% i = i + 1 %] + [% IF node.has_geodata %] + node = { + name: '[% node.name | html %]', + param: '[% node.param %]', + [% address = node.node_data.metadata.address.list.first %] + [% IF address %] + address: '[% address | html %]', + [% END %] + lat: [% node.wgs84_lat %], + long: [% node.wgs84_long %], + }; + add_marker( [% i %], node ); [% END %] - lat: [% node.wgs84_lat %], - long: [% node.wgs84_long %], - }; - add_marker( [% i %], node ); - [% END %] - [% END %] - } - </script> + [% END %] + } + </script> + [% END %] + </div>
</div> </div>
openguides-commits@lists.openguides.org