$params{pre}
$img_type alt="NW map tile" id="t2.2" name="tile_$tl" src="$tl_src" style="top:0px; left:0;">$img_type alt="NE map tile" id="t2.3" name="tile_$tr" src="$tr_src" style="top:0px; left:$imgw;">
$img_type alt="SW map tile" id="t3.2" name="tile_$bl" src="$bl_src" style="top:$imgw; left:0;">$img_type alt="SE map tile" id="t3.3" name="tile_$br" src="$br_src" style="top:$imgw; left:$imgw;">
$params{pins}
EOF
if (Cobrand::show_watermark($cobrand) && mySociety::Config::get('TILES_TYPE') ne 'streetview') {
$out .= '
';
}
$out .= compass($q, $x, $y);
my $copyright;
if (mySociety::Config::get('TILES_TYPE') eq 'streetview') {
$copyright = _('Map contains Ordnance Survey data © Crown copyright and database right 2010.');
} else {
$copyright = _('© Crown copyright. All rights reserved. Ministry of Justice 100037819 2008.');
}
$out .= <
$copyright
$params{post}
EOF
$out .= '';
$out .= '
';
return $out;
}
sub display_map_end {
my ($type) = @_;
my $out = '
';
$out .= '' if ($type);
return $out;
}
sub display_pin {
my ($q, $px, $py, $col, $num) = @_;
$num = '' if !$num || $num > 9;
my $host = Page::base_url_with_lang($q, undef);
my %cols = (red=>'R', green=>'G', blue=>'B', purple=>'P');
my $out = '

';
return $out unless $_ && $_->{id} && $col ne 'blue';
my $cobrand = Page::get_cobrand($q);
my $url = Cobrand::url($cobrand, NewURL($q, -retain => 1,
-url => '/report/' . $_->{id},
pc => undef,
x => undef,
y => undef,
sx => undef,
sy => undef,
all_pins => undef,
no_pins => undef), $q);
$out = '
' . $out . '';
return $out;
}
sub map_pins {
my ($q, $x, $y, $sx, $sy, $interval) = @_;
my $pins = '';
my $min_e = FixMyStreet::Map::tile_to_os($x-3); # Extra space to left/below due to rounding, I think
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);
my $cobrand = Page::get_cobrand($q);
# list of problems aoround map can be limited, but should show all pins
my $around_limit = Cobrand::on_map_list_limit($cobrand);
my $around_map;
my $around_map_list = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, $around_limit);
if ($around_limit) {
$around_map = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, undef);
} else {
$around_map = $around_map_list;
}
my @ids = ();
foreach (@$around_map_list) {
push(@ids, $_->{id});
}
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);
}
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; # - @$current_map;
my $nearby = Problems::nearby($dist, join(',', @ids), $limit, $mid_e, $mid_n, $interval);
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
}
# P is easting or northing
# C is centre tile reference of displayed map
sub os_to_px {
my ($p, $c, $invert) = @_;
return tile_to_px(os_to_tile($p), $c, $invert);
}
# Convert tile co-ordinates to pixel co-ordinates from top left of map
# C is centre tile reference of displayed map
sub tile_to_px {
my ($p, $c, $invert) = @_;
$p = TILE_WIDTH * ($p - $c + 1);
$p = 2 * TILE_WIDTH - $p if $invert;
$p = int($p + .5 * ($p <=> 0));
return $p;
}
# Tile co-ordinates are linear scale of OS E/N
# Will need more generalising when more zooms appear
sub os_to_tile {
return $_[0] / SCALE_FACTOR;
}
sub tile_to_os {
return int($_[0] * SCALE_FACTOR + 0.5);
}
sub click_to_tile {
my ($pin_tile, $pin, $invert) = @_;
$pin -= TILE_WIDTH while $pin > TILE_WIDTH;
$pin += TILE_WIDTH while $pin < 0;
$pin = TILE_WIDTH - $pin if $invert; # image submits measured from top down
return $pin_tile + $pin / TILE_WIDTH;
}
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_tile = $in_x || int($x);
my $y_tile = $in_y || int($y);
my $px = FixMyStreet::Map::os_to_px($easting, $x_tile);
my $py = FixMyStreet::Map::os_to_px($northing, $y_tile, 1);
if ($q->{site} eq 'barnet') { # Map is 380px
if ($py > 380) {
$y_tile--;
$py = FixMyStreet::Map::os_to_px($northing, $y_tile, 1);
}
if ($px > 380) {
$x_tile++;
$px = FixMyStreet::Map::os_to_px($easting, $x_tile);
}
}
return ($x, $y, $x_tile, $y_tile, $px, $py);
}
1;