File Coverage

blib/lib/Geo/Google/StaticMaps/V2/Path.pm
Criterion Covered Total %
statement 44 47 93.6
branch 22 26 84.6
condition 6 12 50.0
subroutine 9 9 100.0
pod 4 4 100.0
total 85 98 86.7


line stmt bran cond sub pod time code
1             package Geo::Google::StaticMaps::V2::Path;
2 10     10   51 use warnings;
  10         20  
  10         289  
3 10     10   48 use strict;
  10         18  
  10         302  
4 10     10   68 use base qw{Geo::Google::StaticMaps::V2::Visible};
  10         22  
  10         6436  
5             our $VERSION = '0.08';
6             our $PACKAGE = __PACKAGE__;
7              
8             =head1 NAME
9              
10             Geo::Google::StaticMaps::V2::Path - Generate Images from Google Static Maps V2 API
11              
12             =head1 SYNOPSIS
13              
14             use Geo::Google::StaticMaps::V2;
15             my $map=Geo::Google::StaticMaps::V2->new;
16             my $path=$map->path(locations=>["Clifton, VA", "Pag, Croatia"], geodesic=>1); #isa Geo::Google::StaticMaps::V2::Path
17             print $map->url, "\n";
18              
19             =head1 DESCRIPTION
20              
21             The packages generates images from the Google Static Maps V2 API which can be saved locally for use in accordance with your license with Google.
22              
23             =head1 USAGE
24              
25             =head1 PROPERTIES
26              
27             =cut
28              
29             sub _styles {
30 24     24   30 my $self=shift;
31 24         32 my @styles=();
32 24 50       80 push @styles, join ":", weight => $self->weight if defined $self->weight;
33 24 100       59 push @styles, join ":", color => $self->color if defined $self->color;
34 24 100       57 push @styles, join ":", fillcolor => $self->fillcolor if defined $self->fillcolor;
35 24 50       58 push @styles, join ":", geodesic => $self->geodesic ? "true" : "false" if defined $self->geodesic;
    100          
36 24         118 return @styles;
37             }
38              
39             =head2 weight
40              
41             weight: (optional) specifies the thickness of the path in pixels. If no weight parameter is set, the path will appear in its default thickness (5 pixels).
42              
43             =cut
44              
45             sub weight {
46 24     24 1 29 my $self=shift;
47 24 50       65 $self->{"weight"}=shift if @_;
48 24         68 return $self->{"weight"};
49             }
50              
51             =head2 color
52              
53             color: (optional) specifies a color either as a 24-bit (example: color=0xFFFFCC) or 32-bit hexadecimal value (example: color=0xFFFFCCFF), or from the set {black, brown, green, purple, yellow, blue, gray, orange, red, white}.
54              
55             When a 32-bit hex value is specified, the last two characters specify the 8-bit alpha transparency value. This value varies between 00 (completely transparent) and FF (completely opaque). Note that transparencies are supported in paths, though they are not supported for markers.
56              
57             my $color=$path->color("blue");
58             my $color=$path->color("0xFFFFCC");
59             my $color=$path->color({r=>255,g=>0,b=>0,a=>64}); #maps to red 25% returns 0xFF000040
60             my $color=$path->color([0,255,0,"75%"]); #maps to green 75% returns 0x00FF00C0
61              
62             =cut
63              
64             sub _color {
65 85     85   97 my $self=shift;
66 85         99 my $key=shift; #color||fillcolor
67 85 100       181 $self->{$key}=shift if @_;
68 85 100       185 if (ref($self->{$key})) {
69 30         30 my $r;
70             my $g;
71 0         0 my $b;
72 0         0 my $a;
73 30 100       75 if (ref($self->{$key}) eq "HASH") {
    50          
74 18   50     45 $r = $self->{$key}->{"r"} || 0;
75 18   50     63 $g = $self->{$key}->{"g"} || 0;
76 18   50     89 $b = $self->{$key}->{"b"} || 0;
77 18         24 $a = $self->{$key}->{"a"};
78             } elsif (ref($self->{$key}) eq "ARRAY") {
79 12   50     30 $r = $self->{$key}->[0] || 0;
80 12   50     41 $g = $self->{$key}->[1] || 0;
81 12   50     43 $b = $self->{$key}->[2] || 0;
82 12         17 $a = $self->{$key}->[3];
83             } else {
84 0         0 die("Error: Unknown reference type expecting HASH or ARRAY.");
85             }
86 30 100       50 if (defined $a) {
87 24 100       72 if ($a =~ m/^(100|\d\d|\d)\%$/) {
88 12         32 $a=int($1/100*255);
89             }
90 24         117 return sprintf("0x%02X%02X%02X%02X", $r, $g, $b, $a);
91             } else {
92 6         32 return sprintf("0x%02X%02X%02X", $r, $g, $b);
93             }
94             } else {
95 55         209 return $self->{$key};
96             }
97             }
98              
99 41     41 1 97 sub color {shift->_color(color=>@_)};
100              
101             =head2 fillcolor
102              
103             fillcolor: (optional) indicates both that the path marks off a polygonal area and specifies the fill color to use as an overlay within that area. The set of locations following need not be a "closed" loop; the Static Map server will automatically join the first and last points. Note, however, that any stroke on the exterior of the filled area will not be closed unless you specifically provide the same beginning and end location.
104              
105             =cut
106              
107 44     44 1 132 sub fillcolor {shift->_color(fillcolor=>@_)};
108              
109             =head2 geodesic
110              
111             geodesic: (optional) indicates that the requested path should be interpreted as a geodesic line that follows the curvature of the Earth. When false, the path is rendered as a straight line in screen space. Defaults to false.
112              
113             =cut
114              
115             sub geodesic {
116 26     26 1 34 my $self=shift;
117 26 100       55 $self->{"geodesic"}=shift if @_;
118 26         72 return $self->{"geodesic"};
119             }
120              
121             =head1 METHODS
122              
123             =head2 addLocation
124              
125             $marker->addLocation("Clifton, VA");
126              
127             =head1 BUGS
128              
129             Please log on RT and send an email to the author.
130              
131             =head1 SUPPORT
132              
133             DavisNetworks.com supports all Perl applications including this package.
134              
135             =head1 AUTHOR
136              
137             Michael R. Davis
138             CPAN ID: MRDVT
139             Satellite Tracking of People, LLC
140             mdavis@stopllc.com
141             http://www.stopllc.com/
142              
143             =head1 COPYRIGHT
144              
145             This program is free software licensed under the...
146              
147             The General Public License (GPL) Version 2, June 1991
148              
149             The full text of the license can be found in the LICENSE file included with this module.
150              
151             =head1 SEE ALSO
152              
153             L
154              
155             =cut
156              
157             1;