| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Geo::Google::Path; |
|
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
43
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use URI::Escape; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
88
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Geo::Google; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
71
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.04-rc3'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use constant FMT => <<_FMT_; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1296
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
%s |
|
12
|
|
|
|
|
|
|
_FMT_ |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
# Head southwest from Venice Blvd |
|
16
|
|
|
|
|
|
|
# Make a U-turn at Venice Blvd |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
21
|
0
|
|
|
|
|
|
my %arg = @_; |
|
22
|
0
|
|
|
|
|
|
my $self = bless \%arg, $class; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
0
|
0
|
|
sub distance { return shift->{'distance'} } |
|
26
|
0
|
|
|
0
|
0
|
|
sub polyline { return shift->{'polyline'} } |
|
27
|
0
|
0
|
|
0
|
0
|
|
sub segments { my $self = shift; return $self->{'segments'} ? @{ $self->{'segments'} } : () } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
0
|
|
sub time { return shift->{'time'} } |
|
29
|
0
|
0
|
|
0
|
0
|
|
sub locations { my $self = shift; return $self->{'locations'} ? @{ $self->{'locations'} } : () } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
0
|
|
sub panel { return shift->{'panel'} } |
|
31
|
0
|
|
|
0
|
0
|
|
sub levels { return shift->{'levels'} } |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub toXML { |
|
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
35
|
0
|
|
|
|
|
|
my $content = join "", map { $_->toXML } @{ $self->{segments} }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return sprintf( FMT, |
|
37
|
|
|
|
|
|
|
$self->distance(), |
|
38
|
|
|
|
|
|
|
$self->time(), |
|
39
|
|
|
|
|
|
|
$content, |
|
40
|
|
|
|
|
|
|
); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub toJSON { |
|
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
45
|
0
|
|
|
|
|
|
my $json = new JSON (barekey => 1); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Construct the shell of a new perl data structure that we |
|
48
|
|
|
|
|
|
|
# can pass off to the JSON module for rendering to a string |
|
49
|
0
|
|
|
|
|
|
my $preJSON = Geo::Google::_JSONrenderSkeleton(); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Fill the perl data structure with information from this |
|
52
|
|
|
|
|
|
|
# location |
|
53
|
0
|
|
|
|
|
|
my @locations = $self->locations(); |
|
54
|
0
|
|
|
|
|
|
$preJSON->{"form"}->{"l"}->{"near"} = |
|
55
|
|
|
|
|
|
|
$locations[$#locations]->title(); |
|
56
|
0
|
|
|
|
|
|
$preJSON->{"form"}->{"q"}->{"q"} = "from:" . |
|
57
|
|
|
|
|
|
|
$locations[0]->title(); |
|
58
|
0
|
|
|
|
|
|
for (my $i=1; $i<=$#locations; $i++) { |
|
59
|
0
|
|
|
|
|
|
$preJSON->{"form"}->{"q"}->{"q"} .= " to:" . |
|
60
|
|
|
|
|
|
|
$locations[$i]->title(); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
$preJSON->{"form"}->{"d"}->{"saddr"} = $locations[0]->title(); |
|
63
|
0
|
|
|
|
|
|
$preJSON->{"form"}->{"d"}->{"daddr"} = $locations[1]->title(); |
|
64
|
0
|
|
|
|
|
|
for (my $i=2; $i<=$#locations; $i++) { |
|
65
|
0
|
|
|
|
|
|
$preJSON->{"form"}->{"d"}->{"daddr"} .= " to:" . |
|
66
|
|
|
|
|
|
|
$locations[$i]->title(); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
0
|
|
|
|
|
|
$preJSON->{"form"}->{"selected"} = "q"; |
|
69
|
0
|
|
|
|
|
|
$preJSON->{"panelStyle"} = ""; |
|
70
|
|
|
|
|
|
|
# Generate the markers |
|
71
|
0
|
|
|
|
|
|
for (my $i=0; $i<=$#locations; $i++) { |
|
72
|
0
|
|
|
|
|
|
my $image = "/mapfiles/dd-pause.png"; |
|
73
|
0
|
|
|
|
|
|
my $id = "pause"; |
|
74
|
0
|
0
|
|
|
|
|
if ($i == 0 ) { |
|
|
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$image = "/mapfiles/dd-start.png"; |
|
76
|
0
|
|
|
|
|
|
$id = "start"; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
elsif ($i == $#locations) { |
|
79
|
0
|
|
|
|
|
|
$image = "/mapfiles/dd-stop.png"; |
|
80
|
0
|
|
|
|
|
|
$id = "stop"; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
0
|
|
|
|
|
|
push( @{$preJSON->{"overlays"}->{"markers"}}, { |
|
|
0
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
"laddr" => "", |
|
84
|
|
|
|
|
|
|
"svaddr" => "", |
|
85
|
|
|
|
|
|
|
"lat" => $locations[$i]->latitude(), |
|
86
|
|
|
|
|
|
|
"lng" => $locations[$i]->longitude(), |
|
87
|
|
|
|
|
|
|
"id" => $id, |
|
88
|
|
|
|
|
|
|
"image" => $image, |
|
89
|
|
|
|
|
|
|
"elms" => [()], |
|
90
|
|
|
|
|
|
|
"llcid" => "", |
|
91
|
|
|
|
|
|
|
"fid" => "", |
|
92
|
|
|
|
|
|
|
"cid" => "", |
|
93
|
|
|
|
|
|
|
"sig" => "", |
|
94
|
|
|
|
|
|
|
"infoWindow" => { |
|
95
|
|
|
|
|
|
|
"type" => "map", |
|
96
|
|
|
|
|
|
|
"_" => 0 |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
}); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"levels"} = |
|
101
|
|
|
|
|
|
|
$self->levels(); |
|
102
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"points"} = |
|
103
|
|
|
|
|
|
|
$self->polyline(); |
|
104
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"outline"} = undef; |
|
105
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"opacity"} = undef; |
|
106
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"color"} = undef; |
|
107
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"weight"} = undef; |
|
108
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"id"} = "d"; |
|
109
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"numLevels"} = 4; |
|
110
|
0
|
|
|
|
|
|
$preJSON->{"overlays"}->{"polylines"}->[0]->{"zoomFactor"} = 16; |
|
111
|
0
|
|
|
|
|
|
$preJSON->{"printheader"} = sprintf("Directions from %s to %s" |
|
112
|
|
|
|
|
|
|
. " Travel time: %s", |
|
113
|
|
|
|
|
|
|
$locations[0]->title(), |
|
114
|
|
|
|
|
|
|
$locations[$#locations]->title(), |
|
115
|
|
|
|
|
|
|
$self->time()); |
|
116
|
0
|
|
|
|
|
|
$preJSON->{"modules"} = [(undef, "multiroute")]; |
|
117
|
0
|
|
|
|
|
|
$preJSON->{"panelResizeState"} = "open"; |
|
118
|
|
|
|
|
|
|
# step through all points in the directions and determine |
|
119
|
|
|
|
|
|
|
# the maximum and minimum lat/longs |
|
120
|
0
|
|
|
|
|
|
my $maxlat = -90; |
|
121
|
0
|
|
|
|
|
|
my $minlat = 90; |
|
122
|
0
|
|
|
|
|
|
my $maxlng = -180; |
|
123
|
0
|
|
|
|
|
|
my $minlng = 180; |
|
124
|
0
|
|
|
|
|
|
foreach my $segment ($self->segments()) { |
|
125
|
0
|
|
|
|
|
|
foreach my $point ($segment->points()) { |
|
126
|
0
|
0
|
|
|
|
|
if ($point->latitude() > $maxlat) |
|
127
|
0
|
|
|
|
|
|
{ $maxlat = $point->latitude(); } |
|
128
|
0
|
0
|
|
|
|
|
if ($point->latitude() < $minlat) |
|
129
|
0
|
|
|
|
|
|
{ $minlat = $point->latitude(); } |
|
130
|
0
|
0
|
|
|
|
|
if ($point->longitude() > $maxlng) |
|
131
|
0
|
|
|
|
|
|
{ $maxlng = $point->longitude(); } |
|
132
|
0
|
0
|
|
|
|
|
if ($point->longitude() < $minlng) |
|
133
|
0
|
|
|
|
|
|
{ $minlng = $point->longitude(); } |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
} |
|
136
|
0
|
|
|
|
|
|
$preJSON->{"viewport"}->{"span"}->{"lat"} = sprintf("%.6f", |
|
137
|
|
|
|
|
|
|
( ($maxlat-$minlat) * 1.1) ); |
|
138
|
0
|
|
|
|
|
|
$preJSON->{"viewport"}->{"span"}->{"lng"} = sprintf("%.6f", |
|
139
|
|
|
|
|
|
|
( ($maxlng-$minlng) * 1.1) ); |
|
140
|
0
|
|
|
|
|
|
$preJSON->{"viewport"}->{"center"}->{"lat"} = sprintf("%.6f", |
|
141
|
|
|
|
|
|
|
( ($maxlat+$minlat) / 2) ); |
|
142
|
0
|
|
|
|
|
|
$preJSON->{"viewport"}->{"center"}->{"lng"} = sprintf("%.6f", |
|
143
|
|
|
|
|
|
|
( ($maxlng+$minlng) / 2) ); |
|
144
|
0
|
|
|
|
|
|
$preJSON->{"viewport"}->{"mapType"} = undef; |
|
145
|
0
|
|
|
|
|
|
$preJSON->{"url"} = "/maps?v=1&q=" . |
|
146
|
|
|
|
|
|
|
uri_escape(sprintf("from:%s to:%s", |
|
147
|
|
|
|
|
|
|
$locations[0]->title(), |
|
148
|
|
|
|
|
|
|
$preJSON->{"form"}->{"d"}->{"daddr"})) |
|
149
|
|
|
|
|
|
|
. "&ie=UTF8"; |
|
150
|
0
|
|
|
|
|
|
$preJSON->{"title"} = sprintf("From:%s to:%s", |
|
151
|
|
|
|
|
|
|
$locations[0]->title(), |
|
152
|
|
|
|
|
|
|
$preJSON->{"form"}->{"d"}->{"daddr"}); |
|
153
|
0
|
|
|
|
|
|
$preJSON->{"panel"} = $self->panel(); |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Render the data structure to a JSON string and return it |
|
156
|
0
|
|
|
|
|
|
return $json->objToJson($preJSON); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
|
160
|
|
|
|
|
|
|
__END__ |