aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Map.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/Map.pm')
-rw-r--r--perllib/FixMyStreet/Map.pm95
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;