aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Council.pm
blob: 5d95c2538e862d52894222c6bf76ec73631d482f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package FixMyStreet::App::Controller::Council;
use Moose;
use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }

=head1 NAME

FixMyStreet::App::Controller::Council - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=head2 load_and_check_areas_and_wards

Try to load areas and wards for this location and check that we have at least one. If
there are no areas then return false.

=cut

sub load_and_check_areas_and_wards : Private {
    my ( $self, $c ) = @_;
    my $area_types = [ @{$c->cobrand->area_types}, @{$c->cobrand->area_types_children} ];
    $c->stash->{area_types} = $area_types;
    $c->forward('load_and_check_areas');
}

=head2 load_and_check_areas

Try to load areas for this location and check that we have at least one. If
there are no areas then return false.

=cut

sub load_and_check_areas : Private {
    my ( $self, $c ) = @_;

    my $latitude  = $c->stash->{latitude};
    my $longitude = $c->stash->{longitude};

    # Look up areas and do checks for the point we've got
    my $area_types;
    if ( $c->stash->{area_types} and scalar @{ $c->stash->{area_types} } ) {
        $area_types = $c->stash->{area_types};
    } else {
        $area_types = $c->cobrand->area_types;
    }

    my $short_latitude  = Utils::truncate_coordinate($latitude);
    my $short_longitude = Utils::truncate_coordinate($longitude);

    my $all_areas;
    if ( $c->stash->{fetch_all_areas} ) {
        my %area_types = map { $_ => 1 } @$area_types;
        $all_areas =
          mySociety::MaPit::call( 'point', "4326/$short_longitude,$short_latitude" );
        $c->stash->{all_areas_mapit} = $all_areas;
        $all_areas = {
            map { $_ => $all_areas->{$_} }
            grep { $area_types{ $all_areas->{$_}->{type} } }
            keys %$all_areas
        };
    } else {
        $all_areas =
          mySociety::MaPit::call( 'point', "4326/$short_longitude,$short_latitude",
            type => $area_types );
    }
    if ($all_areas->{error}) {
        $c->stash->{location_error} = $all_areas->{error};
        return;
    }

    # Let cobrand do a check
    my ( $success, $error_msg ) =
      $c->cobrand->area_check( { all_areas => $all_areas },
        $c->stash->{area_check_action} );
    if ( !$success ) {
        $c->stash->{location_error} = $error_msg;
        return;
    }

    # edit hash in-place
    $c->cobrand->remove_redundant_areas($all_areas) if $c->stash->{remove_redundant_areas};

    # If we don't have any areas we can't accept the report
    if ( !scalar keys %$all_areas ) {
        $c->stash->{location_error} = _('That location does not appear to be covered by a council; perhaps it is offshore or outside the country. Please try again.');
        return;
    }

    # all good if we have some areas left
    $c->stash->{all_areas} = $all_areas;
    $c->stash->{all_area_names} =
      [ map { $_->{name} } values %$all_areas ];
    return 1;
}

=head1 AUTHOR

Struan Donald

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

1;
an>units: 'm', scales: [ '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500' ] }; var layer_options = { projection: new OpenLayers.Projection("EPSG:21781"), name: "Hybrid", layer: "Hybrid", matrixSet: "nativeTileMatrixSet", requestEncoding: "REST", url: "/maps/Hybrid/", style: "default", matrixIds: [ //{ identifier: "0", matrixHeight: 2, matrixWidth: 2, scaleDenominator: 250000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, //{ identifier: "1", matrixHeight: 3, matrixWidth: 3, scaleDenominator: 125000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, { identifier: "2", matrixHeight: 4, matrixWidth: 5, scaleDenominator: 64000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, { identifier: "3", matrixHeight: 7, matrixWidth: 8, scaleDenominator: 32000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, { identifier: "4", matrixHeight: 14, matrixWidth: 14, scaleDenominator: 16000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, { identifier: "5", matrixHeight: 27, matrixWidth: 27, scaleDenominator: 8000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, { identifier: "6", matrixHeight: 52, matrixWidth: 53, scaleDenominator: 4000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, { identifier: "7", matrixHeight: 104, matrixWidth: 105, scaleDenominator: 2000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, { identifier: "8", matrixHeight: 208, matrixWidth: 208, scaleDenominator: 1000, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } }, { identifier: "9", matrixHeight: 415, matrixWidth: 414, scaleDenominator: 500, supportedCRS: "urn:ogc:def:crs:EPSG::21781", tileHeight: 256, tileWidth: 256, topLeftCorner: { lat: 30814423, lon: -29386322 } } ] }; fixmystreet.layer_options = [ layer_options, OpenLayers.Util.applyDefaults({ name: "Stadtplan", layer: "Stadtplan", url: "/maps/Stadtplan/" }, layer_options) ]; // Give main code a new bbox_strategy that translates between // lat/lon and our swiss coordinates fixmystreet.bbox_strategy = new OpenLayers.Strategy.ZurichBBOX({ratio: 1}); fixmystreet.area_format = { fillColor: 'none', strokeWidth: 4, strokeColor: 'black' }; } OpenLayers.Strategy.ZurichBBOX = OpenLayers.Class(OpenLayers.Strategy.BBOX, { getMapBounds: function() { // Get the map bounds but return them in lat/lon, not // Swiss coordinates if (this.layer.map === null) { return null; } var swissBounds = this.layer.map.getExtent(); // Transform bound corners into WGS84 swissBounds.transform( new OpenLayers.Projection("EPSG:21781"), new OpenLayers.Projection("EPSG:4326") ); return swissBounds; }, CLASS_NAME: "OpenLayers.Strategy.ZurichBBOX" });