StaticGoogleMapSmarter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create_map() 0 25 5
1
<?php
2
3
4
class StaticGoogleMapSmarter extends Object
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    /**
7
     * Array is Formatted Like This:
8
     * LocationOfIcon, LinkOfMapPin
9
     * Locations can be: 12 Main Street, bla bla OR -45,180 (lat, lng)
10
     * Icon can be something like: /themes/mysite/images/MyIcon.png (max 64 x 64)
11
     *
12
     *
13
     * @param  int  $width
14
     * @param  int  $height
15
     * @param  array  $locationsAndIcons
16
     *
17
     * @return string
18
     */
19
    public static function create_map($width = 640, $height = 640, $locationsAndIcons = array())
20
    {
21
        $link = 'https://maps.googleapis.com/maps/api/staticmap?'.
22
            'autoscale=2'.
23
            '&size='.$width.'x'.$height.
24
            '&type=roadmap'.
25
            '&format=png'.
26
            '&visual_refresh=true';
27
        $key = Config::inst()->get('GoogleMapSmarter', 'api_key');
28
        if ($key) {
29
            $link .= '&key='.$key;
30
        }
31
32
33
        foreach ($locationsAndIcons as $locationAndIcon) {
34
            $location = $locationAndIcon[0];
35
            $iconLink = isset($locationAndIcon[1]) ? urlencode(Director::absoluteURL($locationAndIcon[1])) : '';
36
            if ($iconLink) {
37
                $link .= '&markers=icon:'.$iconLink.'%7Cshadow:true%7C'.$location;
38
            } else {
39
                $link .= '&markers=size:mid%7Ccolor:0xff0000%7Clabel:%7C'.$location;
40
            }
41
        }
42
        return $link;
43
    }
44
}
45