diff options
-rw-r--r-- | perllib/FixMyStreet/Map/FMS.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/MapQuest.pm | 3 | ||||
-rw-r--r-- | web/js/map-bing-ol.js | 29 |
4 files changed, 44 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/Map/FMS.pm b/perllib/FixMyStreet/Map/FMS.pm index b1dd29002..e7aa46784 100644 --- a/perllib/FixMyStreet/Map/FMS.pm +++ b/perllib/FixMyStreet/Map/FMS.pm @@ -42,8 +42,10 @@ sub map_tile_base { } sub map_tiles { - my ($self, $x, $y, $z) = @_; - if ($z >= 16) { + my ( $self, %params ) = @_; + my ( $x, $y, $z ) = ( $params{x_tile}, $params{y_tile}, $params{zoom_act} ); + my $ni = in_northern_ireland_box( $params{latitude}, $params{longitude} ); + if (!$ni && $z >= 16) { my ($tile_sep, $tile_base) = $self->map_tile_base; return [ sprintf($tile_base, 'a' . $tile_sep, $z, $x-1, $y-1), @@ -53,7 +55,7 @@ sub map_tiles { ]; } else { my $url = "g=701"; - $url .= "&productSet=mmOS" if $z > 10; + $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", @@ -63,4 +65,10 @@ sub map_tiles { } } +sub in_northern_ireland_box { + my ($lat, $lon) = @_; + return 1 if $lat >= 54.015 && $lat <= 55.315 && $lon >= -8.18 && $lon <= -5.415; + return 0; +} + 1; diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm index 119337e37..693f42e4f 100644 --- a/perllib/FixMyStreet/Map/OSM.pm +++ b/perllib/FixMyStreet/Map/OSM.pm @@ -25,7 +25,8 @@ sub map_template { } sub map_tiles { - my ($self, $x, $y, $z) = @_; + my ( $self, %params ) = @_; + my ( $x, $y, $z ) = ( $params{x_tile}, $params{y_tile}, $params{zoom_act} ); my $tile_url = $self->base_tile_url(); return [ "http://a.$tile_url/$z/" . ($x - 1) . "/" . ($y - 1) . ".png", @@ -73,26 +74,23 @@ sub display_map { my $zoom = defined $c->req->params->{zoom} ? $c->req->params->{zoom} + 0 : $default_zoom; $zoom = $numZoomLevels - 1 if $zoom >= $numZoomLevels; $zoom = 0 if $zoom < 0; - my $zoom_act = $zoomOffset + $zoom; - my ($x_tile, $y_tile) = latlon_to_tile_with_adjust($params{latitude}, $params{longitude}, $zoom_act); + $params{zoom_act} = $zoomOffset + $zoom; + ($params{x_tile}, $params{y_tile}) = latlon_to_tile_with_adjust($params{latitude}, $params{longitude}, $params{zoom_act}); foreach my $pin (@{$params{pins}}) { - ($pin->{px}, $pin->{py}) = latlon_to_px($pin->{latitude}, $pin->{longitude}, $x_tile, $y_tile, $zoom_act); + ($pin->{px}, $pin->{py}) = latlon_to_px($pin->{latitude}, $pin->{longitude}, $params{x_tile}, $params{y_tile}, $params{zoom_act}); } $c->stash->{map} = { %params, type => $self->map_template(), map_type => $self->map_type(), - tiles => $self->map_tiles( $x_tile, $y_tile, $zoom_act ), + tiles => $self->map_tiles( %params ), copyright => $self->copyright(), - x_tile => $x_tile, - y_tile => $y_tile, zoom => $zoom, - zoom_act => $zoom_act, zoomOffset => $zoomOffset, numZoomLevels => $numZoomLevels, - compass => compass( $x_tile, $y_tile, $zoom_act ), + compass => compass( $params{x_tile}, $params{y_tile}, $params{zoom_act} ), }; } diff --git a/perllib/FixMyStreet/Map/OSM/MapQuest.pm b/perllib/FixMyStreet/Map/OSM/MapQuest.pm index 9cf6de01f..4751679f5 100644 --- a/perllib/FixMyStreet/Map/OSM/MapQuest.pm +++ b/perllib/FixMyStreet/Map/OSM/MapQuest.pm @@ -16,7 +16,8 @@ sub map_type { } sub map_tiles { - my ($self, $x, $y, $z) = @_; + my ( $self, %params ) = @_; + my ( $x, $y, $z ) = ( $params{x_tile}, $params{y_tile}, $params{zoom_act} ); my $tile_url = $self->base_tile_url(); return [ "http://otile1.$tile_url/$z/" . ($x - 1) . "/" . ($y - 1) . ".png", diff --git a/web/js/map-bing-ol.js b/web/js/map-bing-ol.js index 7d40f8afc..6f9916229 100644 --- a/web/js/map-bing-ol.js +++ b/web/js/map-bing-ol.js @@ -22,12 +22,30 @@ function set_map_config(perm) { if (fixmystreet.map_type) { tile_base = fixmystreet.map_type; } - fixmystreet.map_type = OpenLayers.Layer.Bing; + fixmystreet.map_type = OpenLayers.Layer.BingUK; } -OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { +OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.XYZ, { attributionTemplate: '${logo}${copyrights}', + uk_bounds: [ + new OpenLayers.Bounds(-6.6, 49.8, 1.102680, 51), + new OpenLayers.Bounds(-5.4, 51, 2.28, 54.94), + new OpenLayers.Bounds(-5.85, 54.94, -1.15, 55.33), + new OpenLayers.Bounds(-9.35, 55.33, -0.7, 60.98) + ], + in_uk: function(c) { + c = c.clone(); + c.transform( + fixmystreet.map.getProjectionObject(), + new OpenLayers.Projection("EPSG:4326") + ); + if ( this.uk_bounds[0].contains(c.lon, c.lat) || this.uk_bounds[1].contains(c.lon, c.lat) || this.uk_bounds[2].contains(c.lon, c.lat) || this.uk_bounds[3].contains(c.lon, c.lat) ) { + return true; + } + return false; + }, + setMap: function() { OpenLayers.Layer.XYZ.prototype.setMap.apply(this, arguments); this.updateAttribution(); @@ -98,14 +116,15 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { this.map.getZoom() + this.zoomOffset; var url; - if (z >= 16) { + var in_uk = this.in_uk(bounds.getCenterLonLat()); + if (z >= 16 && in_uk) { url = []; for (var i=0; i< tile_base[0].length; i++) { url.push( tile_base[1].replace('{S}', tile_base[0][i]) + "/${z}/${x}/${y}.png" ); } } else { var type = ''; - if (z > 10) { type = '&productSet=mmOS'; } + if (z > 10 && in_uk) { type = '&productSet=mmOS'; } url = [ "//ecn.t0.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type, "//ecn.t1.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type, @@ -121,5 +140,5 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { return path; }, - CLASS_NAME: "OpenLayers.Layer.Bing" + CLASS_NAME: "OpenLayers.Layer.BingUK" }); |