diff options
Diffstat (limited to 'perllib/FixMyStreet/Map')
-rw-r--r-- | perllib/FixMyStreet/Map/Bing.pm | 52 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/FMS.pm | 41 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Google.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/MapQuest.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/StreetView.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/TonerLite.pm | 38 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Zurich.pm | 14 |
8 files changed, 107 insertions, 67 deletions
diff --git a/perllib/FixMyStreet/Map/Bing.pm b/perllib/FixMyStreet/Map/Bing.pm index 09c951a5f..4c1887641 100644 --- a/perllib/FixMyStreet/Map/Bing.pm +++ b/perllib/FixMyStreet/Map/Bing.pm @@ -1,25 +1,45 @@ # FixMyStreet:Map::Bing -# Bing maps on FixMyStreet. -# -# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ +# Bing maps on FixMyStreet, using OpenLayers. package FixMyStreet::Map::Bing; +use base 'FixMyStreet::Map::OSM'; use strict; -# display_map C PARAMS -# PARAMS include: -# latitude, longitude for the centre point of the map -# CLICKABLE is set if the map is clickable -# PINS is array of pins to show, location and colour -sub display_map { - my ($self, $c, %params) = @_; - $c->stash->{map} = { - %params, - type => 'bing', - key => mySociety::Config::get('BING_MAPS_API_KEY'), - }; +# Is set by the JavaScript +sub map_type { '""' } + +sub map_template { 'bing' } + +sub copyright { '' } + +sub get_quadkey { + my ($self, $x, $y, $z) = @_; + my $key = ''; + for (my $i = $z; $i > 0; $i--) { + my $digit = 0; + my $mask = 1 << ($i - 1); + $digit++ if ($x & $mask) != 0; + $digit += 2 if ($y & $mask) != 0; + $key .= $digit; + } + return $key; +} + +sub map_tile_base { + '', "//ecn.%s.tiles.virtualearth.net/tiles/r%s.png?g=3467"; +} + +sub map_tiles { + my ( $self, %params ) = @_; + my ( $x, $y, $z ) = ( $params{x_tile}, $params{y_tile}, $params{zoom_act} ); + my ($tile_sep, $tile_base) = $self->map_tile_base; + return [ + sprintf($tile_base, 't0', $self->get_quadkey($x-1, $y-1, $z)), + sprintf($tile_base, 't1', $self->get_quadkey($x, $y-1, $z)), + sprintf($tile_base, 't2', $self->get_quadkey($x-1, $y, $z)), + sprintf($tile_base, 't3', $self->get_quadkey($x, $y, $z)), + ]; } 1; diff --git a/perllib/FixMyStreet/Map/FMS.pm b/perllib/FixMyStreet/Map/FMS.pm index 96e265a4d..50a21c125 100644 --- a/perllib/FixMyStreet/Map/FMS.pm +++ b/perllib/FixMyStreet/Map/FMS.pm @@ -5,35 +5,11 @@ # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ package FixMyStreet::Map::FMS; -use base 'FixMyStreet::Map::OSM'; +use base 'FixMyStreet::Map::Bing'; use strict; -# Is set by the JavaScript -sub map_type { - return '""'; -} - -sub map_template { - return 'fms'; -} - -sub copyright { - return ''; -} - -sub get_quadkey { - my ($x, $y, $z) = @_; - my $key = ''; - for (my $i = $z; $i > 0; $i--) { - my $digit = 0; - my $mask = 1 << ($i - 1); - $digit++ if ($x & $mask) != 0; - $digit += 2 if ($y & $mask) != 0; - $key .= $digit; - } - return $key; -} +sub map_template { 'fms' } sub map_tile_base { '-', "//%stilma.mysociety.org/sv/%d/%d/%d.png"; @@ -52,13 +28,14 @@ sub map_tiles { sprintf($tile_base, '', $z, $x, $y), ]; } else { - my $url = "g=701"; - $url .= "&productSet=mmOS" if $z > 10 && !$ni; + my $key = FixMyStreet->config('BING_MAPS_API_KEY'); + my $url = "g=3467"; + $url .= "&productSet=mmOS&key=$key" if $z > 10 && !$ni; return [ - "//ecn.t0.tiles.virtualearth.net/tiles/r" . get_quadkey($x-1, $y-1, $z) . ".png?$url", - "//ecn.t1.tiles.virtualearth.net/tiles/r" . get_quadkey($x, $y-1, $z) . ".png?$url", - "//ecn.t2.tiles.virtualearth.net/tiles/r" . get_quadkey($x-1, $y, $z) . ".png?$url", - "//ecn.t3.tiles.virtualearth.net/tiles/r" . get_quadkey($x, $y, $z) . ".png?$url", + "//ecn.t0.tiles.virtualearth.net/tiles/r" . $self->get_quadkey($x-1, $y-1, $z) . ".png?$url", + "//ecn.t1.tiles.virtualearth.net/tiles/r" . $self->get_quadkey($x, $y-1, $z) . ".png?$url", + "//ecn.t2.tiles.virtualearth.net/tiles/r" . $self->get_quadkey($x-1, $y, $z) . ".png?$url", + "//ecn.t3.tiles.virtualearth.net/tiles/r" . $self->get_quadkey($x, $y, $z) . ".png?$url", ]; } } diff --git a/perllib/FixMyStreet/Map/Google.pm b/perllib/FixMyStreet/Map/Google.pm index 172d2d60e..46823f358 100644 --- a/perllib/FixMyStreet/Map/Google.pm +++ b/perllib/FixMyStreet/Map/Google.pm @@ -35,12 +35,12 @@ sub display_map { $default_zoom = $numZoomLevels - 3 if $dist < 10; # Map centre may be overridden in the query string - $params{latitude} = Utils::truncate_coordinate($c->req->params->{lat} + 0) - if defined $c->req->params->{lat}; - $params{longitude} = Utils::truncate_coordinate($c->req->params->{lon} + 0) - if defined $c->req->params->{lon}; + $params{latitude} = Utils::truncate_coordinate($c->get_param('lat') + 0) + if defined $c->get_param('lat'); + $params{longitude} = Utils::truncate_coordinate($c->get_param('lon') + 0) + if defined $c->get_param('lon'); - my $zoom = defined $c->req->params->{zoom} ? $c->req->params->{zoom} + 0 : $default_zoom; + my $zoom = defined $c->get_param('zoom') ? $c->get_param('zoom') + 0 : $default_zoom; $zoom = $numZoomLevels - 1 if $zoom >= $numZoomLevels; $zoom = 0 if $zoom < 0; $params{zoom_act} = $zoomOffset + $zoom; diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm index df2d16b82..7d91a9ee7 100644 --- a/perllib/FixMyStreet/Map/OSM.pm +++ b/perllib/FixMyStreet/Map/OSM.pm @@ -39,7 +39,7 @@ sub base_tile_url { } sub copyright { - return _('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>'); + _('© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'); } # display_map C PARAMS @@ -64,12 +64,12 @@ sub display_map { $default_zoom = $numZoomLevels - 3 if $dist < 10; # Map centre may be overridden in the query string - $params{latitude} = Utils::truncate_coordinate($c->req->params->{lat} + 0) - if defined $c->req->params->{lat}; - $params{longitude} = Utils::truncate_coordinate($c->req->params->{lon} + 0) - if defined $c->req->params->{lon}; + $params{latitude} = Utils::truncate_coordinate($c->get_param('lat') + 0) + if defined $c->get_param('lat'); + $params{longitude} = Utils::truncate_coordinate($c->get_param('lon') + 0) + if defined $c->get_param('lon'); - my $zoom = defined $c->req->params->{zoom} ? $c->req->params->{zoom} + 0 : $default_zoom; + my $zoom = defined $c->get_param('zoom') ? $c->get_param('zoom') + 0 : $default_zoom; $zoom = $numZoomLevels - 1 if $zoom >= $numZoomLevels; $zoom = 0 if $zoom < 0; $params{zoom_act} = $zoomOffset + $zoom; @@ -168,7 +168,7 @@ sub click_to_wgs84 { my ($self, $c, $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 = MIN_ZOOM_LEVEL + (defined $c->req->params->{zoom} ? $c->req->params->{zoom} : 3); + my $zoom = MIN_ZOOM_LEVEL + (defined $c->get_param('zoom') ? $c->get_param('zoom') : 3); my ($lat, $lon) = tile_to_latlon($tile_x, $tile_y, $zoom); return ( $lat, $lon ); } diff --git a/perllib/FixMyStreet/Map/OSM/MapQuest.pm b/perllib/FixMyStreet/Map/OSM/MapQuest.pm index 2c3cbaf00..4fc8ba57d 100644 --- a/perllib/FixMyStreet/Map/OSM/MapQuest.pm +++ b/perllib/FixMyStreet/Map/OSM/MapQuest.pm @@ -33,4 +33,8 @@ sub base_tile_url { return 'mqcdn.com/tiles/1.0.0/map/'; } +sub copyright { + 'Data, imagery and map information provided by <a href="http://www.mapquest.com/">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png" />, <a href="http://openstreetmap.org/">OpenStreetMap</a> and contributors, <a href="http://opendatacommons.org/licenses/odbl/">ODbL</a>' +} + 1; diff --git a/perllib/FixMyStreet/Map/OSM/StreetView.pm b/perllib/FixMyStreet/Map/OSM/StreetView.pm index c70dd93aa..87c335dd6 100644 --- a/perllib/FixMyStreet/Map/OSM/StreetView.pm +++ b/perllib/FixMyStreet/Map/OSM/StreetView.pm @@ -22,6 +22,7 @@ sub base_tile_url { } sub copyright { + 'Contains OS data © Crown copyright and database right 2013'; } 1; diff --git a/perllib/FixMyStreet/Map/OSM/TonerLite.pm b/perllib/FixMyStreet/Map/OSM/TonerLite.pm new file mode 100644 index 000000000..543cd6002 --- /dev/null +++ b/perllib/FixMyStreet/Map/OSM/TonerLite.pm @@ -0,0 +1,38 @@ +#!/usr/bin/perl +# +# FixMyStreet:Map::OSM::TonerLite +# OSM TonerLite maps on FixMyStreet. +# +# Map tiles by <http://stamen.com> Stamen Design, +# under <http://creativecommons.org/licenses/by/3.0>CC BY 3.0. +# Data by <http://openstreetmap.org> OpenStreetMap, +# under <http://www.openstreetmap.org/copyright> ODbL. +# +# Copyright (c) 2014 UK Citizens Online Democracy. All rights reserved. +# Email: hakim@mysociety.org; WWW: http://www.mysociety.org/ + +package FixMyStreet::Map::OSM::TonerLite; +use base 'FixMyStreet::Map::OSM'; + +use strict; + +sub map_type { 'OpenLayers.Layer.Stamen' } + +sub map_template { 'osm-toner-lite' } + +sub copyright { + 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.' +} + +sub map_tiles { + my ( $self, %params ) = @_; + my ( $x, $y, $z ) = ( $params{x_tile}, $params{y_tile}, $params{zoom_act} ); + return [ + "https://stamen-tiles-a.a.ssl.fastly.net/toner-lite/$z/" . ($x - 1) . "/" . ($y - 1) . ".png", + "https://stamen-tiles-b.a.ssl.fastly.net/toner-lite/$z/$x/" . ($y - 1) . ".png", + "https://stamen-tiles-c.a.ssl.fastly.net/toner-lite/$z/" . ($x - 1) . "/$y.png", + "https://stamen-tiles-d.a.ssl.fastly.net/toner-lite/$z/$x/$y.png", + ]; +} + +1; diff --git a/perllib/FixMyStreet/Map/Zurich.pm b/perllib/FixMyStreet/Map/Zurich.pm index d667a4701..9b01f2978 100644 --- a/perllib/FixMyStreet/Map/Zurich.pm +++ b/perllib/FixMyStreet/Map/Zurich.pm @@ -45,13 +45,13 @@ sub display_map { my ($self, $c, %params) = @_; # Map centre may be overridden in the query string - $params{latitude} = Utils::truncate_coordinate($c->req->params->{lat} + 0) - if defined $c->req->params->{lat}; - $params{longitude} = Utils::truncate_coordinate($c->req->params->{lon} + 0) - if defined $c->req->params->{lon}; + $params{latitude} = Utils::truncate_coordinate($c->get_param('lat') + 0) + if defined $c->get_param('lat'); + $params{longitude} = Utils::truncate_coordinate($c->get_param('lon') + 0) + if defined $c->get_param('lon'); - my $zoom = defined $c->req->params->{zoom} - ? $c->req->params->{zoom} + 0 + my $zoom = defined $c->get_param('zoom') + ? $c->get_param('zoom') + 0 : $c->stash->{page} eq 'report' ? DEFAULT_ZOOM+1 : DEFAULT_ZOOM; @@ -159,7 +159,7 @@ sub click_to_wgs84 { my ($self, $c, $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 = (defined $c->req->params->{zoom} ? $c->req->params->{zoom} : DEFAULT_ZOOM); + my $zoom = (defined $c->get_param('zoom') ? $c->get_param('zoom') : DEFAULT_ZOOM); my ($lat, $lon) = tile_to_latlon($tile_x, $tile_y, $zoom); return ( $lat, $lon ); } |