#!/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::Tilma::Original; use strict; use LWP::Simple; use Cobrand; use mySociety::GeoUtil; use mySociety::Locale; 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 ); } sub header_js { return ' '; } # display_map Q PARAMS # PARAMS include: # latitude, longitude 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 ($self, $q, %params) = @_; $params{pre} ||= ''; $params{post} ||= ''; my $mid_point = TILE_WIDTH; # Map is 2 TILE_WIDTHs in size, square. if (my $mp = Cobrand::tilma_mid_point(Page::get_cobrand($q))) { $mid_point = $mp; } # convert map center point to easting, northing ( $params{easting}, $params{northing} ) = _ll_to_en( $params{latitude}, $params{longitude} ); # FIXME - convert all pins to lat, lng # all the pins are currently [lat, lng, colour] - convert them foreach my $pin ( @{ $params{pins} ||= [] } ) { my ( $lat, $lon ) = ( $pin->[0], $pin->[1] ); my ( $e, $n ) = _ll_to_en( $lat, $lon ); ( $pin->[0], $pin->[1] ) = ( $e, $n ); } # X/Y tile co-ords may be overridden in the query string my @vars = qw(x y); my %input = map { $_ => $q->param($_) || '' } @vars; ($input{x}) = $input{x} =~ /^(\d+)/; $input{x} ||= 0; ($input{y}) = $input{y} =~ /^(\d+)/; $input{y} ||= 0; 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 = 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; $py = defined($py) ? $mid_point - $py : 0; $x = int($x)<=0 ? 0 : $x; $y = int($y)<=0 ? 0 : $y; 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 '
$copyright
$params{post}