aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original.pm (renamed from perllib/FixMyStreet/Map.pm)114
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm28
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm27
-rw-r--r--perllib/FixMyStreet/Map/Utils.pm128
4 files changed, 191 insertions, 106 deletions
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm
index 315de0958..5772f6ccd 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map/Tilma/Original.pm
@@ -11,19 +11,9 @@ package FixMyStreet::Map;
use strict;
use LWP::Simple;
-use Problems;
use Cobrand;
-use mySociety::Config;
-use mySociety::Gaze;
-use mySociety::GeoUtil;
-use mySociety::Locale;
use mySociety::Web qw(ent NewURL);
-use constant TILE_WIDTH => mySociety::Config::get('TILES_WIDTH');
-use constant TIF_SIZE_M => mySociety::Config::get('TILES_TIFF_SIZE_METRES');
-use constant TIF_SIZE_PX => mySociety::Config::get('TILES_TIFF_SIZE_PIXELS');
-use constant SCALE_FACTOR => TIF_SIZE_M / (TIF_SIZE_PX / TILE_WIDTH);
-
sub header_js {
return '
<script type="text/javascript" src="/js/map-tilma.js"></script>
@@ -37,7 +27,7 @@ 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 {
+sub _display_map {
my ($q, %params) = @_;
$params{pre} ||= '';
$params{post} ||= '';
@@ -65,7 +55,7 @@ sub display_map {
$py = defined($py) ? $mid_point - $py : 0;
$x = int($x)<=0 ? 0 : $x;
$y = int($y)<=0 ? 0 : $y;
- my $url = mySociety::Config::get('TILES_URL');
+ my $url = 'http://tilma.mysociety.org/tileserver/' . TILE_TYPE . '/';
my $tiles_url = $url . ($x-1) . '-' . $x . ',' . ($y-1) . '-' . $y . '/RABX';
my $tiles = LWP::Simple::get($tiles_url);
return '<div id="map_box"> <div id="map"><div id="drag">' . _("Unable to fetch the map tiles from the tile server.") . '</div></div></div><div id="side">' if !$tiles;
@@ -80,24 +70,14 @@ sub display_map {
my $bl_src = $url . $tileids->[1][0];
my $br_src = $url . $tileids->[1][1];
- my $out = '';
my $cobrand = Page::get_cobrand($q);
my $root_path_js = Cobrand::root_path_js($cobrand, $q);
- my $cobrand_form_elements = Cobrand::form_elements($cobrand, 'mapForm', $q);
+ my $out = FixMyStreet::Map::header($q, $params{type});
my $img_type;
- my $form_action = Cobrand::url($cobrand, '', $q);
if ($params{type}) {
- my $encoding = '';
- $encoding = ' enctype="multipart/form-data"' if ($params{type}==2);
- my $pc = $q->param('pc') || '';
- my $pc_enc = ent($pc);
$out .= <<EOF;
-<form action="$form_action" method="post" name="mapForm" id="mapForm"$encoding>
-<input type="hidden" name="submit_map" value="1">
<input type="hidden" name="x" id="formX" value="$x">
<input type="hidden" name="y" id="formY" value="$y">
-<input type="hidden" name="pc" value="$pc_enc">
-$cobrand_form_elements
EOF
$img_type = '<input type="image"';
} else {
@@ -105,7 +85,7 @@ EOF
}
my $imgw = TILE_WIDTH . 'px';
my $tile_width = TILE_WIDTH;
- my $tile_type = mySociety::Config::get('TILES_TYPE');
+ my $tile_type = TILE_TYPE;
$out .= <<EOF;
<script type="text/javascript">
$root_path_js
@@ -126,23 +106,16 @@ $params{pre}
<div id="pins">$pins</div>
</div>
EOF
- if (Cobrand::show_watermark($cobrand) && mySociety::Config::get('TILES_TYPE') ne 'streetview') {
- $out .= '<div id="watermark"></div>';
- }
+ $out .= '<div id="watermark"></div>' if $params{watermark};
$out .= compass($q, $x, $y);
- my $copyright;
- if (mySociety::Config::get('TILES_TYPE') eq 'streetview') {
- $copyright = _('Map contains Ordnance Survey data &copy; Crown copyright and database right 2010.');
- } else {
- $copyright = _('&copy; Crown copyright. All rights reserved. Ministry of Justice 100037819&nbsp;2008.');
- }
+ my $copyright = $params{copyright};
$out .= <<EOF;
</div>
<p id="copyright">$copyright</p>
$params{post}
+</div>
+<div id="side">
EOF
- $out .= '</div>';
- $out .= '<div id="side">';
return $out;
}
@@ -176,46 +149,6 @@ sub display_pin {
return $out;
}
-sub map_features {
- my ($q, $easting, $northing, $interval) = @_;
-
- my $xx = FixMyStreet::Map::os_to_tile($easting);
- my $yy = FixMyStreet::Map::os_to_tile($northing);
- my $x = int($xx);
- my $y = int($yy);
- $x += 1 if ($xx - $x > 0.5);
- $y += 1 if ($yy - $y > 0.5);
-
- my $min_e = FixMyStreet::Map::tile_to_os($x-3); # Due to when the front-end AJAX look ups pins
- my $min_n = FixMyStreet::Map::tile_to_os($y-3);
- my $mid_e = FixMyStreet::Map::tile_to_os($x);
- my $mid_n = FixMyStreet::Map::tile_to_os($y);
- my $max_e = FixMyStreet::Map::tile_to_os($x+2);
- my $max_n = FixMyStreet::Map::tile_to_os($y+2);
-
- # list of problems aoround map can be limited, but should show all pins
- my ($around_map, $around_map_list);
- if (my $around_limit = Cobrand::on_map_list_limit(Page::get_cobrand($q))) {
- $around_map_list = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, $around_limit);
- $around_map = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, undef);
- } else {
- $around_map = $around_map_list = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, undef);
- }
-
- my $dist;
- mySociety::Locale::in_gb_locale {
- my ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($mid_e, $mid_n, 'G');
- $dist = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
- };
- $dist = int($dist*10+0.5)/10;
-
- my $limit = 20;
- my @ids = map { $_->{id} } @$around_map_list;
- my $nearby = Problems::nearby($dist, join(',', @ids), $limit, $mid_e, $mid_n, $interval);
-
- return ($around_map, $around_map_list, $nearby, $dist);
-}
-
sub map_pins {
my ($q, $x, $y, $sx, $sy, $interval) = @_;
@@ -241,37 +174,6 @@ sub map_pins {
return ($pins, $around_map_list, $nearby, $dist);
}
-sub compass ($$$) {
- my ($q, $x, $y) = @_;
- my @compass;
- for (my $i=$x-1; $i<=$x+1; $i++) {
- for (my $j=$y-1; $j<=$y+1; $j++) {
- $compass[$i][$j] = NewURL($q, x=>$i, y=>$j);
- }
- }
- my $recentre = NewURL($q);
- my $host = Page::base_url_with_lang($q, undef);
- return <<EOF;
-<table cellpadding="0" cellspacing="0" border="0" id="compass">
-<tr valign="bottom">
-<td align="right"><a rel="nofollow" href="${compass[$x-1][$y+1]}"><img src="$host/i/arrow-northwest.gif" alt="NW" width=11 height=11></a></td>
-<td align="center"><a rel="nofollow" href="${compass[$x][$y+1]}"><img src="$host/i/arrow-north.gif" vspace="3" alt="N" width=13 height=11></a></td>
-<td><a rel="nofollow" href="${compass[$x+1][$y+1]}"><img src="$host/i/arrow-northeast.gif" alt="NE" width=11 height=11></a></td>
-</tr>
-<tr>
-<td><a rel="nofollow" href="${compass[$x-1][$y]}"><img src="$host/i/arrow-west.gif" hspace="3" alt="W" width=11 height=13></a></td>
-<td align="center"><a rel="nofollow" href="$recentre"><img src="$host/i/rose.gif" alt="Recentre" width=35 height=34></a></td>
-<td><a rel="nofollow" href="${compass[$x+1][$y]}"><img src="$host/i/arrow-east.gif" hspace="3" alt="E" width=11 height=13></a></td>
-</tr>
-<tr valign="top">
-<td align="right"><a rel="nofollow" href="${compass[$x-1][$y-1]}"><img src="$host/i/arrow-southwest.gif" alt="SW" width=11 height=11></a></td>
-<td align="center"><a rel="nofollow" href="${compass[$x][$y-1]}"><img src="$host/i/arrow-south.gif" vspace="3" alt="S" width=13 height=11></a></td>
-<td><a rel="nofollow" href="${compass[$x+1][$y-1]}"><img src="$host/i/arrow-southeast.gif" alt="SE" width=11 height=11></a></td>
-</tr>
-</table>
-EOF
-}
-
# P is easting or northing
# C is centre tile reference of displayed map
sub os_to_px {
diff --git a/perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm b/perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm
new file mode 100644
index 000000000..f97163c68
--- /dev/null
+++ b/perllib/FixMyStreet/Map/Tilma/Original/1_10k.pm
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+#
+# FixMyStreet:Map
+# Adding the ability to have different maps on FixMyStreet.
+#
+# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+package FixMyStreet::Map;
+
+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';
+
+use FixMyStreet::Map::Tilma::Original;
+
+sub display_map {
+ my ($q, %params) = @_;
+ $params{copyright} = _('&copy; Crown copyright. All rights reserved. Ministry of Justice 100037819&nbsp;2008.');
+ $params{watermark} = 1;
+ return _display_map($q, %params);
+}
+
+1;
diff --git a/perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm b/perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm
new file mode 100644
index 000000000..103f4c15c
--- /dev/null
+++ b/perllib/FixMyStreet/Map/Tilma/Original/StreetView.pm
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+#
+# FixMyStreet:Map
+# Adding the ability to have different maps on FixMyStreet.
+#
+# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+package FixMyStreet::Map;
+
+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';
+
+use FixMyStreet::Map::Tilma::Original;
+
+sub display_map {
+ my ($q, %params) = @_;
+ $params{copyright} = _('Map contains Ordnance Survey data &copy; Crown copyright and database right 2010.');
+ return _display_map($q, %params);
+}
+
+1;
diff --git a/perllib/FixMyStreet/Map/Utils.pm b/perllib/FixMyStreet/Map/Utils.pm
new file mode 100644
index 000000000..695206785
--- /dev/null
+++ b/perllib/FixMyStreet/Map/Utils.pm
@@ -0,0 +1,128 @@
+#!/usr/bin/perl
+#
+# FixMyStreet:Map
+# Adding the ability to have different maps on FixMyStreet.
+#
+# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+package FixMyStreet::Map;
+
+use strict;
+
+use Problems;
+use Cobrand;
+use mySociety::Gaze;
+use mySociety::GeoUtil;
+use mySociety::Locale;
+use mySociety::Web qw(NewURL);
+
+sub header {
+ my ($q, $type) = @_;
+ return '' unless $type;
+
+ my $cobrand = Page::get_cobrand($q);
+ my $cobrand_form_elements = Cobrand::form_elements($cobrand, 'mapForm', $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);
+ 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">
+$cobrand_form_elements
+EOF
+}
+
+sub map_features {
+ my ($q, $easting, $northing, $interval) = @_;
+
+ my $min_e = $easting - 500;
+ my $min_n = $northing - 500;
+ my $mid_e = $easting;
+ my $mid_n = $northing;
+ my $max_e = $easting + 500;
+ my $max_n = $northing + 500;
+
+ # list of problems aoround map can be limited, but should show all pins
+ my ($around_map, $around_map_list);
+ if (my $around_limit = Cobrand::on_map_list_limit(Page::get_cobrand($q))) {
+ $around_map_list = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, $around_limit);
+ $around_map = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, undef);
+ } else {
+ $around_map = $around_map_list = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, undef);
+ }
+
+ my $dist;
+ mySociety::Locale::in_gb_locale {
+ my ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($mid_e, $mid_n, 'G');
+ $dist = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
+ };
+ $dist = int($dist*10+0.5)/10;
+
+ my $limit = 20;
+ my @ids = map { $_->{id} } @$around_map_list;
+ my $nearby = Problems::nearby($dist, join(',', @ids), $limit, $mid_e, $mid_n, $interval);
+
+ return ($around_map, $around_map_list, $nearby, $dist);
+}
+
+sub map_pins {
+ my ($q, $x, $y, $sx, $sy, $interval) = @_;
+
+ my $e = FixMyStreet::Map::tile_to_os($x);
+ my $n = FixMyStreet::Map::tile_to_os($y);
+ my ($around_map, $around_map_list, $nearby, $dist) = FixMyStreet::Map::map_features($q, $e, $n, $interval);
+
+ my $pins = '';
+ foreach (@$around_map) {
+ my $px = FixMyStreet::Map::os_to_px($_->{easting}, $sx);
+ my $py = FixMyStreet::Map::os_to_px($_->{northing}, $sy, 1);
+ my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
+ $pins .= FixMyStreet::Map::display_pin($q, $px, $py, $col);
+ }
+
+ foreach (@$nearby) {
+ my $px = FixMyStreet::Map::os_to_px($_->{easting}, $sx);
+ my $py = FixMyStreet::Map::os_to_px($_->{northing}, $sy, 1);
+ my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
+ $pins .= FixMyStreet::Map::display_pin($q, $px, $py, $col);
+ }
+
+ return ($pins, $around_map_list, $nearby, $dist);
+}
+
+sub compass ($$$) {
+ my ($q, $x, $y) = @_;
+ my @compass;
+ for (my $i=$x-1; $i<=$x+1; $i++) {
+ for (my $j=$y-1; $j<=$y+1; $j++) {
+ $compass[$i][$j] = NewURL($q, x=>$i, y=>$j);
+ }
+ }
+ my $recentre = NewURL($q);
+ my $host = Page::base_url_with_lang($q, undef);
+ return <<EOF;
+<table cellpadding="0" cellspacing="0" border="0" id="compass">
+<tr valign="bottom">
+<td align="right"><a rel="nofollow" href="${compass[$x-1][$y+1]}"><img src="$host/i/arrow-northwest.gif" alt="NW" width=11 height=11></a></td>
+<td align="center"><a rel="nofollow" href="${compass[$x][$y+1]}"><img src="$host/i/arrow-north.gif" vspace="3" alt="N" width=13 height=11></a></td>
+<td><a rel="nofollow" href="${compass[$x+1][$y+1]}"><img src="$host/i/arrow-northeast.gif" alt="NE" width=11 height=11></a></td>
+</tr>
+<tr>
+<td><a rel="nofollow" href="${compass[$x-1][$y]}"><img src="$host/i/arrow-west.gif" hspace="3" alt="W" width=11 height=13></a></td>
+<td align="center"><a rel="nofollow" href="$recentre"><img src="$host/i/rose.gif" alt="Recentre" width=35 height=34></a></td>
+<td><a rel="nofollow" href="${compass[$x+1][$y]}"><img src="$host/i/arrow-east.gif" hspace="3" alt="E" width=11 height=13></a></td>
+</tr>
+<tr valign="top">
+<td align="right"><a rel="nofollow" href="${compass[$x-1][$y-1]}"><img src="$host/i/arrow-southwest.gif" alt="SW" width=11 height=11></a></td>
+<td align="center"><a rel="nofollow" href="${compass[$x][$y-1]}"><img src="$host/i/arrow-south.gif" vspace="3" alt="S" width=13 height=11></a></td>
+<td><a rel="nofollow" href="${compass[$x+1][$y-1]}"><img src="$host/i/arrow-southeast.gif" alt="SE" width=11 height=11></a></td>
+</tr>
+</table>
+EOF
+}
+
+1;