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 | |
parent | b2db40fe0ce173d96716bff07d30af0fe5bb28b5 (diff) |
Allow map change in URL.
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 95 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Bing.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/BingOL.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Google.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM.pm | 25 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/CycleMap.pm | 68 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/StreetView.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Tilma/Original.pm | 75 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm | 23 | ||||
-rw-r--r-- | perllib/Page.pm | 2 |
13 files changed, 160 insertions, 262 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; diff --git a/perllib/FixMyStreet/Map/Bing.pm b/perllib/FixMyStreet/Map/Bing.pm index ef5397d01..c29311324 100644 --- a/perllib/FixMyStreet/Map/Bing.pm +++ b/perllib/FixMyStreet/Map/Bing.pm @@ -6,7 +6,7 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::Bing; use strict; use mySociety::Web qw(ent); @@ -26,7 +26,7 @@ sub header_js { # PINS is array of pins to show, location and colour # PRE/POST are HTML to show above/below map sub display_map { - my ($q, %params) = @_; + my ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; @@ -60,17 +60,4 @@ EOF return $out; } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - -sub display_pin { -} - -sub map_pins { -} - 1; diff --git a/perllib/FixMyStreet/Map/BingOL.pm b/perllib/FixMyStreet/Map/BingOL.pm index a14d4e112..4e93243a9 100644 --- a/perllib/FixMyStreet/Map/BingOL.pm +++ b/perllib/FixMyStreet/Map/BingOL.pm @@ -6,7 +6,7 @@ # Copyright (c) 2011 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::BingOL; use strict; use mySociety::Web qw(ent); @@ -14,7 +14,7 @@ use mySociety::Web qw(ent); sub header_js { return ' <!-- <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=en-GB"></script> --> -<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script> +<script type="text/javascript" src="/jslib/OpenLayers-2.10/OpenLayers.js"></script> <script type="text/javascript" src="/js/map-OpenLayers.js"></script> <script type="text/javascript" src="/js/map-bing-ol.js"></script> '; @@ -28,7 +28,7 @@ sub header_js { # PINS is array of pins to show, location and colour # PRE/POST are HTML to show above/below map sub display_map { - my ($q, %params) = @_; + my ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; @@ -62,17 +62,4 @@ EOF return $out; } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - -sub display_pin { -} - -sub map_pins { -} - 1; diff --git a/perllib/FixMyStreet/Map/Google.pm b/perllib/FixMyStreet/Map/Google.pm index 9fb0cb964..35896108b 100644 --- a/perllib/FixMyStreet/Map/Google.pm +++ b/perllib/FixMyStreet/Map/Google.pm @@ -6,7 +6,7 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::Google; use strict; use mySociety::Web qw(ent); @@ -26,7 +26,7 @@ sub header_js { # PINS is array of pins to show, location and colour # PRE/POST are HTML to show above/below map sub display_map { - my ($q, %params) = @_; + my ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; @@ -60,17 +60,4 @@ EOF return $out; } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - -sub display_pin { -} - -sub map_pins { -} - 1; diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm index 2fe43b63d..b930a4e4d 100644 --- a/perllib/FixMyStreet/Map/OSM.pm +++ b/perllib/FixMyStreet/Map/OSM.pm @@ -6,11 +6,11 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::OSM; use strict; use Math::Trig; -use mySociety::Web qw(ent); +use mySociety::Web qw(ent NewURL); use Utils; sub header_js { @@ -21,6 +21,10 @@ sub header_js { '; } +sub map_type { + return 'OpenLayers.Layer.OSM.Mapnik'; +} + # display_map Q PARAMS # PARAMS include: # latitude, longitude for the centre point of the map @@ -29,7 +33,7 @@ sub header_js { # PINS is array of pins to show, location and colour # PRE/POST are HTML to show above/below map sub display_map { - my ($q, %params) = @_; + my ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; @@ -71,6 +75,7 @@ sub display_map { my $out = FixMyStreet::Map::header($q, $params{type}); my $copyright = _('Map © <a id="osm_link" href="http://www.openstreetmap.org/">OpenStreetMap</a> and contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'); my $compass = compass($q, $x_tile, $y_tile, $zoom); + my $map_type = $self->map_type(); $out .= <<EOF; <input type="hidden" name="latitude" id="fixmystreet.latitude" value="$params{latitude}"> <input type="hidden" name="longitude" id="fixmystreet.longitude" value="$params{longitude}"> @@ -80,7 +85,7 @@ var fixmystreet = { 'latitude': $params{latitude}, 'longitude': $params{longitude}, 'pins': [ $pins_js ], - 'map_type': OpenLayers.Layer.OSM.Mapnik + 'map_type': $map_type } </script> <div id="map_box"> @@ -98,13 +103,6 @@ EOF return $out; } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - sub display_pin { my ($q, $pin, $x_tile, $y_tile, $zoom) = @_; @@ -124,9 +122,6 @@ sub display_pin { return $out; } -sub map_pins { -} - # Given a lat/lon, convert it to OSM tile co-ordinates (precise). sub latlon_to_tile($$$) { my ($lat, $lon, $zoom) = @_; @@ -188,7 +183,7 @@ sub click_to_tile { # Given some click co-ords (the tile they were on, and where in the # tile they were), convert to WGS84 and return. sub click_to_wgs84 { - my ($q, $pin_tile_x, $pin_x, $pin_tile_y, $pin_y) = @_; + my ($self, $q, $pin_tile_x, $pin_x, $pin_tile_y, $pin_y) = @_; my $tile_x = click_to_tile($pin_tile_x, $pin_x); my $tile_y = click_to_tile($pin_tile_y, $pin_y); my $zoom = 14 + (defined $q->param('zoom') ? $q->param('zoom') : 2); diff --git a/perllib/FixMyStreet/Map/OSM/CycleMap.pm b/perllib/FixMyStreet/Map/OSM/CycleMap.pm index 0a6e216c8..06b07ae20 100644 --- a/perllib/FixMyStreet/Map/OSM/CycleMap.pm +++ b/perllib/FixMyStreet/Map/OSM/CycleMap.pm @@ -6,73 +6,13 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::OSM::CycleMap; +use base 'FixMyStreet::Map::OSM'; use strict; -use mySociety::Web qw(ent); -sub header_js { - return ' -<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script> -<script type="text/javascript" src="/js/map-OpenLayers.js"></script> -<script type="text/javascript" src="/js/map-OpenStreetMap.js"></script> -'; -} - -# display_map Q PARAMS -# PARAMS include: -# EASTING, NORTHING for the centre point of the map -# TYPE is 1 if the map is clickable, 2 if clickable and has a form upload, -# 0 if not clickable -# PINS is array of pins to show, location and colour -# PRE/POST are HTML to show above/below map -sub display_map { - my ($q, %params) = @_; - $params{pre} ||= ''; - $params{post} ||= ''; - - my @pins; - foreach my $pin (@{$params{pins}}) { - $pin->[3] ||= ''; - push @pins, "[ $pin->[0], $pin->[1], '$pin->[2]', '$pin->[3]' ]"; - } - my $pins_js = join(",\n", @pins); - - my $out = FixMyStreet::Map::header($q, $params{type}); - my $copyright = _('Map © <a id="osm_link" href="http://www.openstreetmap.org/">OpenStreetMap</a> and contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'); - $out .= <<EOF; -<input type="hidden" name="latitude" id="fixmystreet.latitude" value="$params{latitude}"> -<input type="hidden" name="longitude" id="fixmystreet.longitude" value="$params{longitude}"> -<script type="text/javascript"> -var fixmystreet = { - 'latitude': $params{latitude}, - 'longitude': $params{longitude}, - 'pins': [ $pins_js ], - 'map_type': OpenLayers.Layer.OSM.CycleMap -} -</script> -<div id="map_box"> - $params{pre} - <div id="map"></div> - <p id="copyright">$copyright</p> - $params{post} -</div> -<div id="side"> -EOF - return $out; -} - -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - -sub display_pin { -} - -sub map_pins { +sub map_type { + return 'OpenLayers.Layer.OSM.CycleMap'; } 1; diff --git a/perllib/FixMyStreet/Map/OSM/StreetView.pm b/perllib/FixMyStreet/Map/OSM/StreetView.pm index c0c2a8504..9c9a1ac8e 100644 --- a/perllib/FixMyStreet/Map/OSM/StreetView.pm +++ b/perllib/FixMyStreet/Map/OSM/StreetView.pm @@ -6,14 +6,14 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::OSM::StreetView; use strict; use mySociety::Web qw(ent); sub header_js { return ' -<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script> +<script type="text/javascript" src="/jslib/OpenLayers-2.10/OpenLayers.js"></script> <script type="text/javascript" src="/js/map-OpenLayers.js"></script> <script type="text/javascript" src="/js/map-streetview.js"></script> '; @@ -27,7 +27,7 @@ sub header_js { # PINS is array of pins to show, location and colour # PRE/POST are HTML to show above/below map sub display_map { - my ($q, %params) = @_; + my ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; @@ -61,17 +61,4 @@ EOF return $out; } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - -sub display_pin { -} - -sub map_pins { -} - 1; diff --git a/perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm b/perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm index 8fbf9aa8d..9ae5829c4 100644 --- a/perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm +++ b/perllib/FixMyStreet/Map/Tilma/OL/1_10k.pm @@ -6,7 +6,7 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::Tilma::OL::1_10k; use strict; @@ -18,7 +18,7 @@ use constant TILE_TYPE => '10k-full'; sub header_js { return ' -<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script> +<script type="text/javascript" src="/jslib/OpenLayers-2.10/OpenLayers.js"></script> <script type="text/javascript" src="/js/map-OpenLayers.js"></script> <script type="text/javascript" src="/js/map-tilma-ol.js"></script> <script type="text/javascript" src="/js/OpenLayers.Projection.OrdnanceSurvey.js"></script> @@ -33,7 +33,7 @@ sub header_js { # PINS is array of pins to show, location and colour # PRE/POST are HTML to show above/below map sub display_map { - my ($q, %params) = @_; + my ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; @@ -76,17 +76,4 @@ EOF return $out; } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - -sub display_pin { -} - -sub map_pins { -} - 1; diff --git a/perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm b/perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm index 518e575ac..7a898b55b 100644 --- a/perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm +++ b/perllib/FixMyStreet/Map/Tilma/OL/StreetView.pm @@ -6,7 +6,7 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::Tilma::OL::StreetView; use strict; @@ -18,7 +18,7 @@ use constant TILE_TYPE => 'streetview'; sub header_js { return ' -<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script> +<script type="text/javascript" src="/jslib/OpenLayers-2.10/OpenLayers.js"></script> <script type="text/javascript" src="/js/map-OpenLayers.js"></script> <script type="text/javascript" src="/js/map-tilma-ol.js"></script> <script type="text/javascript" src="/js/OpenLayers.Projection.OrdnanceSurvey.js"></script> @@ -33,7 +33,7 @@ sub header_js { # PINS is array of pins to show, location and colour # PRE/POST are HTML to show above/below map sub display_map { - my ($q, %params) = @_; + my ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; @@ -74,17 +74,4 @@ EOF return $out; } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - -sub display_pin { -} - -sub map_pins { -} - 1; diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm index ee9948dc3..2a64b5bbb 100644 --- a/perllib/FixMyStreet/Map/Tilma/Original.pm +++ b/perllib/FixMyStreet/Map/Tilma/Original.pm @@ -6,7 +6,7 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::Tilma::Original; use strict; use LWP::Simple; @@ -18,6 +18,10 @@ use mySociety::Web qw(ent NewURL); use Utils; use RABX; +sub TILE_WIDTH() { return $FixMyStreet::Map::map_class->tile_width; } +sub SCALE_FACTOR() { return $FixMyStreet::Map::map_class->scale_factor; } +sub TILE_TYPE() { return $FixMyStreet::Map::map_class->tile_type; } + sub _ll_to_en { my ($lat, $lon) = @_; return Utils::convert_latlon_to_en( $lat, $lon ); @@ -36,8 +40,8 @@ sub header_js { # 0 if not clickable # PINS is array of pins to show, location and colour # PRE/POST are HTML to show above/below map -sub _display_map { - my ($q, %params) = @_; +sub display_map { + my ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; my $mid_point = TILE_WIDTH; # Map is 2 TILE_WIDTHs in size, square. @@ -63,13 +67,13 @@ sub _display_map { ($input{x}) = $input{x} =~ /^(\d+)/; $input{x} ||= 0; ($input{y}) = $input{y} =~ /^(\d+)/; $input{y} ||= 0; - my ($x, $y, $px, $py) = FixMyStreet::Map::os_to_px_with_adjust($q, $params{easting}, $params{northing}, $input{x}, $input{y}); + my ($x, $y, $px, $py) = os_to_px_with_adjust($q, $params{easting}, $params{northing}, $input{x}, $input{y}); my $pins = ''; foreach my $pin (@{$params{pins}}) { - my $pin_x = FixMyStreet::Map::os_to_px($pin->[0], $x); - my $pin_y = FixMyStreet::Map::os_to_px($pin->[1], $y, 1); - $pins .= FixMyStreet::Map::display_pin($q, $pin_x, $pin_y, $pin->[2]); + my $pin_x = os_to_px($pin->[0], $x); + my $pin_y = os_to_px($pin->[1], $y, 1); + $pins .= display_pin($q, $pin_x, $pin_y, $pin->[2]); } $px = defined($px) ? $mid_point - $px : 0; @@ -129,9 +133,9 @@ $params{pre} <div id="pins">$pins</div> </div> EOF - $out .= '<div id="watermark"></div>' if $params{watermark}; + $out .= '<div id="watermark"></div>' if $self->watermark(); $out .= compass($q, $x, $y); - my $copyright = $params{copyright}; + my $copyright = $self->copyright(); $out .= <<EOF; </div> <p id="copyright">$copyright</p> @@ -142,13 +146,6 @@ EOF return $out; } -sub display_map_end { - my ($type) = @_; - my $out = '</div>'; - $out .= '</form>' if ($type); - return $out; -} - sub display_pin { my ($q, $px, $py, $col, $num) = @_; $num = '' if !$num || $num > 9; @@ -165,31 +162,32 @@ sub display_pin { } sub map_pins { - my ($q, $x, $y, $sx, $sy, $interval) = @_; + my ($self, $q, $x, $y, $sx, $sy, $interval) = @_; - my $e = FixMyStreet::Map::tile_to_os($x); - my $n = FixMyStreet::Map::tile_to_os($y); + my $e = tile_to_os($x); + my $n = tile_to_os($y); + my ( $lat, $lon ) = Utils::convert_en_to_latlon( $e, $n ); my ( $around_map, $around_map_list, $nearby, $dist ) = - FixMyStreet::Map::map_features_easting_northing( $q, $e, $n, $interval ); + FixMyStreet::Map::map_features( $q, $lat, $lon, $interval ); my $pins = ''; foreach (@$around_map) { ( $_->{easting}, $_->{northing} ) = _ll_to_en( $_->{latitude}, $_->{longitude} ); - my $px = FixMyStreet::Map::os_to_px($_->{easting}, $sx); - my $py = FixMyStreet::Map::os_to_px($_->{northing}, $sy, 1); + my $px = os_to_px($_->{easting}, $sx); + my $py = os_to_px($_->{northing}, $sy, 1); my $col = $_->{state} eq 'fixed' ? 'green' : 'red'; - $pins .= FixMyStreet::Map::display_pin($q, $px, $py, $col); + $pins .= display_pin($q, $px, $py, $col); } foreach (@$nearby) { ( $_->{easting}, $_->{northing} ) = _ll_to_en( $_->{latitude}, $_->{longitude} ); - my $px = FixMyStreet::Map::os_to_px($_->{easting}, $sx); - my $py = FixMyStreet::Map::os_to_px($_->{northing}, $sy, 1); + my $px = os_to_px($_->{easting}, $sx); + my $py = os_to_px($_->{northing}, $sy, 1); my $col = $_->{state} eq 'fixed' ? 'green' : 'red'; - $pins .= FixMyStreet::Map::display_pin($q, $px, $py, $col); + $pins .= display_pin($q, $px, $py, $col); } return ($pins, $around_map_list, $nearby, $dist); @@ -231,7 +229,7 @@ Takes the tile x,y and converts to lat, lon. =cut sub tile_xy_to_wgs84 { - my ( $x, $y ) = @_; + my ( $self, $x, $y ) = @_; my $easting = tile_to_os($x); my $northing = tile_to_os($y); @@ -253,18 +251,19 @@ sub click_to_tile { # tile they were), convert to OSGB36 and return. sub click_to_os { my ($pin_tile_x, $pin_x, $pin_tile_y, $pin_y) = @_; - my $tile_x = FixMyStreet::Map::click_to_tile($pin_tile_x, $pin_x); - my $tile_y = FixMyStreet::Map::click_to_tile($pin_tile_y, $pin_y, 1); - my $easting = FixMyStreet::Map::tile_to_os($tile_x); - my $northing = FixMyStreet::Map::tile_to_os($tile_y); + my $tile_x = click_to_tile($pin_tile_x, $pin_x); + my $tile_y = click_to_tile($pin_tile_y, $pin_y, 1); + my $easting = tile_to_os($tile_x); + my $northing = tile_to_os($tile_y); return ($easting, $northing); } # Given some click co-ords (the tile they were on, and where in the # tile they were), convert to WGS84 and return. sub click_to_wgs84 { + my $self = shift; my $q = shift; - my ( $easting, $northing ) = FixMyStreet::Map::click_to_os(@_); + my ( $easting, $northing ) = click_to_os(@_); my ( $lat, $lon ) = mySociety::GeoUtil::national_grid_to_wgs84( $easting, $northing, 'G' ); return ( $lat, $lon ); } @@ -275,8 +274,8 @@ sub click_to_wgs84 { sub os_to_px_with_adjust { my ($q, $easting, $northing, $in_x, $in_y) = @_; - my $x = FixMyStreet::Map::os_to_tile($easting); - my $y = FixMyStreet::Map::os_to_tile($northing); + my $x = os_to_tile($easting); + my $y = os_to_tile($northing); my $x_tile = $in_x || int($x); my $y_tile = $in_y || int($y); @@ -288,16 +287,16 @@ sub os_to_px_with_adjust { $y_tile += 1; } - my $px = FixMyStreet::Map::os_to_px($easting, $x_tile); - my $py = FixMyStreet::Map::os_to_px($northing, $y_tile, 1); + my $px = os_to_px($easting, $x_tile); + my $py = os_to_px($northing, $y_tile, 1); if ($q->{site} eq 'barnet') { # Map is 380px, so might need to adjust if (!$in_x && $px > 380) { $x_tile++; - $px = FixMyStreet::Map::os_to_px($easting, $x_tile); + $px = os_to_px($easting, $x_tile); } if (!$in_y && $py > 380) { $y_tile--; - $py = FixMyStreet::Map::os_to_px($northing, $y_tile, 1); + $py = os_to_px($northing, $y_tile, 1); } } diff --git a/perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm b/perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm index f97163c68..722df2a46 100644 --- a/perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm +++ b/perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm @@ -6,23 +6,23 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::Tilma::Original::1_10k; +use base 'FixMyStreet::Map::Tilma::Original'; use strict; -use constant TILE_WIDTH => 254; -use constant TIF_SIZE_M => 5000; -use constant TIF_SIZE_PX => 7874; -use constant SCALE_FACTOR => TIF_SIZE_M / (TIF_SIZE_PX / TILE_WIDTH); -use constant TILE_TYPE => '10k-full'; +sub tile_width { return 254; } +sub tif_size_m { return 5000; } +sub tif_size_px { return 7874; } +sub scale_factor { return tif_size_m() / (tif_size_px() / tile_width()); } +sub tile_type { return '10k-full'; } -use FixMyStreet::Map::Tilma::Original; +sub copyright { + return _('© Crown copyright. All rights reserved. Ministry of Justice 100037819 2008.'); +} -sub display_map { - my ($q, %params) = @_; - $params{copyright} = _('© Crown copyright. All rights reserved. Ministry of Justice 100037819 2008.'); - $params{watermark} = 1; - return _display_map($q, %params); +sub watermark { + return 1; } 1; diff --git a/perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm b/perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm index 103f4c15c..fe03fdb00 100644 --- a/perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm +++ b/perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm @@ -6,22 +6,23 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -package FixMyStreet::Map; +package FixMyStreet::Map::Tilma::Original::StreetView; +use base 'FixMyStreet::Map::Tilma::Original'; use strict; -use constant TILE_WIDTH => 250; -use constant TIF_SIZE_M => 5000; -use constant TIF_SIZE_PX => 5000; -use constant SCALE_FACTOR => TIF_SIZE_M / (TIF_SIZE_PX / TILE_WIDTH); -use constant TILE_TYPE => 'streetview'; +sub tile_width { return 250; } +sub tif_size_m { return 5000; } +sub tif_size_px { return 5000; } +sub scale_factor { return tif_size_m() / (tif_size_px() / tile_width()); } +sub tile_type { return 'streetview'; } -use FixMyStreet::Map::Tilma::Original; +sub copyright { + return _('Map contains Ordnance Survey data © Crown copyright and database right 2010.'); +} -sub display_map { - my ($q, %params) = @_; - $params{copyright} = _('Map contains Ordnance Survey data © Crown copyright and database right 2010.'); - return _display_map($q, %params); +sub watermark { + return 0; } 1; diff --git a/perllib/Page.pm b/perllib/Page.pm index 130b5b301..6c5af0fc5 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -119,6 +119,8 @@ sub microsite { $lang = 'en-gb' if $host =~ /^en\./; Cobrand::set_lang_and_domain(get_cobrand($q), $lang, 1); + FixMyStreet::Map::set_map_class($q->param('map')); + Problems::set_site_restriction($q); Memcached::set_namespace(mySociety::Config::get('BCI_DB_NAME') . ":"); } |