diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-09-16 14:55:45 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-09-19 16:11:08 +0100 |
commit | cc2ca7a697e1750ef197e222a1d45c4b345e61d4 (patch) | |
tree | 7db9414a7b0905ac72eb595eb3d8195840f22b79 | |
parent | 5bf5c08a3a25c91866ce478f01fc6c4ad9d25eb6 (diff) |
[Bexley] Add new map tiles.
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bexley.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Bexley.pm | 39 | ||||
-rw-r--r-- | t/cobrand/bexley.t | 19 | ||||
-rw-r--r-- | t/map/tests.t | 1 | ||||
-rw-r--r-- | web/js/map-bexley.js | 24 |
5 files changed, 84 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm index a395543bd..1a4b698df 100644 --- a/perllib/FixMyStreet/Cobrand/Bexley.pm +++ b/perllib/FixMyStreet/Cobrand/Bexley.pm @@ -9,7 +9,7 @@ sub council_area { 'Bexley' } sub council_name { 'London Borough of Bexley' } sub council_url { 'bexley' } sub get_geocoder { 'OSM' } -sub map_type { 'OSM' } +sub map_type { 'Bexley' } sub disambiguate_location { my $self = shift; diff --git a/perllib/FixMyStreet/Map/Bexley.pm b/perllib/FixMyStreet/Map/Bexley.pm new file mode 100644 index 000000000..d3c7a013a --- /dev/null +++ b/perllib/FixMyStreet/Map/Bexley.pm @@ -0,0 +1,39 @@ +# FixMyStreet:Map::Bexley +# +# A combination of FMS OS maps and our own tiles + +package FixMyStreet::Map::Bexley; +use base 'FixMyStreet::Map::FMS'; + +use strict; + +use constant ZOOM_LEVELS => 7; + +sub map_template { 'fms' } + +sub map_javascript { [ + '/vendor/OpenLayers/OpenLayers.wfs.js', + '/js/map-OpenLayers.js', + '/js/map-bing-ol.js', + '/js/map-fms.js', + '/js/map-bexley.js', +] } + +sub map_tiles { + my ( $self, %params ) = @_; + my ( $x, $y, $z ) = ( $params{x_tile}, $params{y_tile}, $params{zoom_act} ); + if ($z >= 17) { + my $base = "//%stilma.mysociety.org/bexley/%d/%d/%d.png"; + return [ + sprintf($base, 'a.', $z, $x-1, $y-1), + sprintf($base, 'b.', $z, $x, $y-1), + sprintf($base, 'c.', $z, $x-1, $y), + sprintf($base, '', $z, $x, $y), + ]; + } else { + return $self->SUPER::map_tiles(%params); + } +} + +1; + diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t index f227e7450..b929cbce1 100644 --- a/t/cobrand/bexley.t +++ b/t/cobrand/bexley.t @@ -4,6 +4,7 @@ use FixMyStreet::TestMech; use FixMyStreet::Script::Reports; use_ok 'FixMyStreet::Cobrand::Bexley'; +use_ok 'FixMyStreet::Map::Bexley'; my $ukc = Test::MockModule->new('FixMyStreet::Cobrand::UKCouncils'); $ukc->mock('lookup_site_code', sub { @@ -40,6 +41,7 @@ $category->update; FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'bexley' ], MAPIT_URL => 'http://mapit.uk/', + MAP_TYPE => 'Bexley', STAGING_FLAGS => { send_reports => 1, skip_checks => 0 }, COBRAND_FEATURES => { open311_email => { bexley => { p1 => 'p1@bexley', lighting => 'thirdparty@notbexley.example.com' } } }, }, sub { @@ -147,4 +149,21 @@ subtest 'nearest road returns correct road' => sub { is $cobrand->_nearest_feature($cfg, 545451, 174380, $features), '20101226'; }; +subtest 'correct map tiles used' => sub { + my %test = ( + 16 => [ '-', 'oml' ], + 20 => [ '.', 'bexley' ] + ); + foreach my $zoom (qw(16 20)) { + my $tiles = FixMyStreet::Map::Bexley->map_tiles(x_tile => 123, y_tile => 456, zoom_act => $zoom); + my ($sep, $lyr) = @{$test{$zoom}}; + is_deeply $tiles, [ + "//a${sep}tilma.mysociety.org/$lyr/$zoom/122/455.png", + "//b${sep}tilma.mysociety.org/$lyr/$zoom/123/455.png", + "//c${sep}tilma.mysociety.org/$lyr/$zoom/122/456.png", + "//tilma.mysociety.org/$lyr/$zoom/123/456.png", + ]; + } +}; + done_testing(); diff --git a/t/map/tests.t b/t/map/tests.t index a06759a33..1b152620e 100644 --- a/t/map/tests.t +++ b/t/map/tests.t @@ -2,6 +2,7 @@ use FixMyStreet::Map; use Test::More; my $requires = { + 'Bexley' => 'map-bexley.js', 'Bing' => 'map-bing-ol.js', 'Bristol' => 'map-wmts-bristol.js', 'Bromley' => 'map-fms.js', diff --git a/web/js/map-bexley.js b/web/js/map-bexley.js new file mode 100644 index 000000000..38911f950 --- /dev/null +++ b/web/js/map-bexley.js @@ -0,0 +1,24 @@ +fixmystreet.maps.config = (function(original) { + return function(){ + original(); + fixmystreet.map_type = OpenLayers.Layer.Bexley; + }; +})(fixmystreet.maps.config); + +OpenLayers.Layer.Bexley = OpenLayers.Class(OpenLayers.Layer.BingUK, { + get_urls: function(bounds, z) { + if (z < 17) { + return OpenLayers.Layer.BingUK.prototype.get_urls.apply(this, arguments); + } + + var urls = []; + var servers = [ '', 'a.', 'b.', 'c.' ]; + var base = "//{S}tilma.mysociety.org/bexley/${z}/${x}/${y}.png"; + for (var i=0; i < servers.length; i++) { + urls.push( base.replace('{S}', servers[i]) ); + } + return urls; + }, + + CLASS_NAME: "OpenLayers.Layer.Bexley" +}); |