diff options
author | Matthew Somerville <matthew@fury.ukcod.org.uk> | 2011-03-23 16:58:54 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@fury.ukcod.org.uk> | 2011-03-23 16:58:54 +0000 |
commit | 21c9779d0aa2a1045d91d0e70968e81f03587678 (patch) | |
tree | 39831e93718b6f4ee5fe15a8686c4fa9c6bb60d8 /perllib/FixMyStreet/Map.pm | |
parent | b2db40fe0ce173d96716bff07d30af0fe5bb28b5 (diff) |
Allow map change in URL.
Diffstat (limited to 'perllib/FixMyStreet/Map.pm')
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 95 |
1 files changed, 67 insertions, 28 deletions
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index e507726c2..5305b360a 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -10,25 +10,64 @@ package FixMyStreet::Map; use strict; +use Module::Pluggable + sub_name => 'maps', + search_path => __PACKAGE__, + except => 'FixMyStreet::Map::Tilma::Original', + require => 1; + +# Get the list of maps we want and load map classes at compile time +my @ALL_MAP_CLASSES = allowed_maps(); + use Problems; use Cobrand; use mySociety::Config; use mySociety::Gaze; use mySociety::Locale; -use mySociety::Web qw(ent NewURL); -use Utils; +use mySociety::Web qw(ent); + +=head2 allowed_maps + +Returns an array of all the map classes that were found and that +are permitted by the config. + +=cut + +sub allowed_maps { + my @allowed = split /,/, mySociety::Config::get('MAP_TYPE'); + @allowed = map { __PACKAGE__.'::'.$_ } @allowed; + my %avail = map { $_ => 1 } __PACKAGE__->maps; + return grep { $avail{$_} } @allowed; +} + +=head2 map_class + +Set and return the appropriate class given a query parameter string. + +=cut + +our $map_class; +sub set_map_class { + my $str = shift; + $str = __PACKAGE__.'::'.$str if $str; + my %avail = map { $_ => 1 } @ALL_MAP_CLASSES; + $str = $ALL_MAP_CLASSES[0] unless $str && $avail{$str}; + $map_class = $str; +} -# Run on module boot up -load(); +sub header_js { + return $map_class->header_js(@_); +} -# This is yucky, but no-one's taught me a better way -sub load { - my $type = mySociety::Config::get('MAP_TYPE'); - my $class = "FixMyStreet::Map::$type"; - eval "use $class"; +sub display_map { + return $map_class->display_map(@_); +} - # If we have an error die as it is a compile error rather than runtime error - die $@ if $@; +sub display_map_end { + my ($type) = @_; + my $out = '</div>'; + $out .= '</form>' if ($type); + return $out; } sub header { @@ -38,32 +77,20 @@ sub header { my $cobrand = Page::get_cobrand($q); my $cobrand_form_elements = Cobrand::form_elements( $cobrand, 'mapForm', $q ); - my $form_action = Cobrand::url( $cobrand, '', $q ); + my $form_action = Cobrand::url( $cobrand, '/', $q ); my $encoding = ''; $encoding = ' enctype="multipart/form-data"' if $type == 2; - my $pc = $q->param('pc') || ''; - my $pc_enc = ent($pc); + my $pc = ent($q->param('pc') || ''); + my $map = ent($q->param('map') || ''); return <<EOF; <form action="$form_action" method="post" name="mapForm" id="mapForm"$encoding> <input type="hidden" name="submit_map" value="1"> -<input type="hidden" name="pc" value="$pc_enc"> +<input type="hidden" name="map" value="$map"> +<input type="hidden" name="pc" value="$pc"> $cobrand_form_elements EOF } -=head2 map_features_easting_northing - -Wrapper around map_features which does the easting, northing to lat, lon -conversion. - -=cut - -sub map_features_easting_northing { - my ( $q, $easting, $northing, $interval ) = @_; - my ( $lat, $lon ) = Utils::convert_en_to_latlon( $easting, $northing ); - return map_features( $q, $lat, $lon, $interval ); -} - sub map_features { my ( $q, $lat, $lon, $interval ) = @_; @@ -102,4 +129,16 @@ sub map_features { return ( $around_map, $around_map_list, $nearby, $dist ); } +sub map_pins { + return $map_class->map_pins(@_); +} + +sub click_to_wgs84 { + return $map_class->click_to_wgs84(@_); +} + +sub tile_xy_to_wgs84 { + return $map_class->tile_xy_to_wgs84(@_); +} + 1; |