aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Map/Google.pm
blob: 46823f3580c805ac2be8df64c62c38c5889727dd (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
# FixMyStreet:Map::Google
# Google maps on FixMyStreet.
#
# Copyright (c) 2013 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/

package FixMyStreet::Map::Google;

use strict;
use mySociety::Gaze;
use Utils;

use constant ZOOM_LEVELS    => 6;
use constant MIN_ZOOM_LEVEL => 13;

# 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) = @_;

    my $numZoomLevels = ZOOM_LEVELS;
    my $zoomOffset = MIN_ZOOM_LEVEL;
    if ($params{any_zoom}) {
        $numZoomLevels = 19;
        $zoomOffset = 0;
    }

    # Adjust zoom level dependent upon population density
    my $dist = $c->stash->{distance}
        || mySociety::Gaze::get_radius_containing_population( $params{latitude}, $params{longitude}, 200_000 );
    my $default_zoom = $c->cobrand->default_map_zoom() ? $c->cobrand->default_map_zoom() : $numZoomLevels - 4;
    $default_zoom = $numZoomLevels - 3 if $dist < 10;

    # Map centre may be overridden in the query string
    $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->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;

    $c->stash->{map} = {
        %params,
        type => 'google',
        zoom => $zoom,
        zoomOffset => $zoomOffset,
        numZoomLevels => $numZoomLevels,
    };
}

1;