diff options
author | Matthew Somerville <matthew@mysociety.org> | 2014-10-06 15:47:21 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-02-23 17:10:05 +0000 |
commit | 032db2fbb6bd2bf0cf0cf2daa379610ab319a6a8 (patch) | |
tree | 7c23e16a551d80ebc2b3ebf05cbc5dac16e1be6e /perllib/FixMyStreet/Map | |
parent | c763a5e8e78849d736f9c0cec92ee2687ac9e75d (diff) |
Support Stamen toner-lite and Bing Maps tiles.
Diffstat (limited to 'perllib/FixMyStreet/Map')
-rw-r--r-- | perllib/FixMyStreet/Map/Bing.pm | 52 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/FMS.pm | 38 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/TonerLite.pm | 38 |
3 files changed, 81 insertions, 47 deletions
diff --git a/perllib/FixMyStreet/Map/Bing.pm b/perllib/FixMyStreet/Map/Bing.pm index 09c951a5f..46b8f68cd 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=3293"; +} + +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..7e61f334c 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,13 @@ sub map_tiles { sprintf($tile_base, '', $z, $x, $y), ]; } else { - my $url = "g=701"; + my $url = "g=3293"; $url .= "&productSet=mmOS" 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/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; |