| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
2256
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
59
|
|
|
2
|
|
|
|
|
|
|
# $Id: YahooMaps.pm,v 1.24 2008/08/03 17:08:40 asc Exp $ |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Net::Flickr::Geo::YahooMaps; |
|
5
|
1
|
|
|
1
|
|
7
|
use base qw (Net::Flickr::Geo); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
158
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$Net::Flickr::Geo::YahooMaps::VERSION = '0.72'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Net::Flickr::Geo::YahooMaps - tools for working with geotagged Flickr photos and Yahoo! Maps |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %opts = (); |
|
16
|
|
|
|
|
|
|
getopts('c:i:', \%opts); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $cfg = Config::Simple->new($opts{'c'}); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $fl = Net::Flickr::Geo::YahooMaps->new($cfg); |
|
21
|
|
|
|
|
|
|
$fl->log()->add(Log::Dispatch::Screen->new('name' => 'scr', min_level => 'info')); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my @map = $fl->mk_pinwin_map_for_photo($opts{'i'}); |
|
24
|
|
|
|
|
|
|
print Dumper(\@map); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# returns : |
|
27
|
|
|
|
|
|
|
# ['/tmp/GGsf4552h.jpg', '99999992']; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Tools for working with geotagged Flickr photos and Yahoo! Maps |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 OPTIONS |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Options are passed to Net::Flickr::Backup using a Config::Simple object or |
|
38
|
|
|
|
|
|
|
a valid Config::Simple config file. Options are grouped by "block". |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 flickr |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=over 4 |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item * B |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
String. I |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
A valid Flickr API key. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item * B |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
String. I |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
A valid Flickr Auth API secret key. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item * B |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
String. I |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
A valid Flickr Auth API token. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The B defines which XML/XPath handler to use to process API responses. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=over 4 |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item * B |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Use XML::LibXML. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item * B |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Use XML::XPath. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=back |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 pinwin |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item * B |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The height of the background map on which the pinwin/thumbnail will be |
|
83
|
|
|
|
|
|
|
placed. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Default is 1024. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * B |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The width of the background map on which the pinwin/thumbnail will be |
|
90
|
|
|
|
|
|
|
placed. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Default is 1024. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item * B |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Boolean. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Automatically upload newly create map images to Flickr. Photos will be tagged with the following machine tags : |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over 4 |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * B |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Where I is the photo that has been added to the map image. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * B |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=back |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Default is false. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * B |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Boolean. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Mark pinwin uploads to Flickr as viewable by anyone. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Default is false. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * B |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Boolean. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Mark pinwin uploads to Flickr as viewable only by friends. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Default is false. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * B |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Boolean. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Mark pinwin uploads to Flickr as viewable only by family. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Default is false. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * B |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Int. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
By default, the object will try to map the (Flickr) accuracy to the corresponding |
|
141
|
|
|
|
|
|
|
zoom level of the Modest Maps provider you have chosen. If this option is defined |
|
142
|
|
|
|
|
|
|
then it will be used as the zoom level regardless of what Flickr says. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * B |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Int (or array reference of ints) |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Used by I related object methods, a list of photos to exclude from the list |
|
149
|
|
|
|
|
|
|
returned by the Flickr API. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * B |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
String (or array reference of strings) |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Used by I related object methods, a list of tags that all photos must B have if |
|
156
|
|
|
|
|
|
|
they are to be included in the final output. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * B |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
String (or array reference of strings) |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Used by I related object methods, a list of tags that all photos must have if |
|
163
|
|
|
|
|
|
|
they are to be included in the final output. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 yahoo |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=over 4 |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * B |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
A valid Yahoo! developers API key. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * B |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Set the Yahoo! Map Image API 'radius' property. From the docs : |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
"How far (in miles) from the specified location to display on the map." |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Default is none, and to use a zoom level that maps to the I property |
|
180
|
|
|
|
|
|
|
of a photo. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=back |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
use FileHandle; |
|
187
|
|
|
|
|
|
|
use File::Temp qw (tempfile); |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 PACKAGE METHODS |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 __PACKAGE__->new($cfg) |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Returns a I object. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# Defined in Net::Flickr::API |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 $obj->mk_pinwin_map_for_photo($photo_id) |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Fetch a map using the Yahoo! Map Image API for a geotagged Flickr photo |
|
208
|
|
|
|
|
|
|
and place a "pinwin" style thumbnail of the photo over the map's marker. |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Returns an array of arrays (kind of pointless really, but at least consistent). |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
The first element of the (second-level) array will be the path to the newly created map |
|
213
|
|
|
|
|
|
|
image. If uploads are enabled the newly created Flickr photo ID will be |
|
214
|
|
|
|
|
|
|
passed as the second element. |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# Defined in Net::Flickr::Geo |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 $obj->mk_pinwin_maps_for_photoset($photoset_id) |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
For each geotagged photo in a set, fetch a map using the Yahoo! Map |
|
223
|
|
|
|
|
|
|
Image API for a geotagged Flickr photo and place a "pinwin" style |
|
224
|
|
|
|
|
|
|
thumbnail of the photo over the map's marker. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
If uploads are enabled then each map for a given photo will be |
|
227
|
|
|
|
|
|
|
added such that it appears before the photo it references. |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Returns an array of arrays. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
The first element of each (second-level) array reference will be the path to the newly |
|
232
|
|
|
|
|
|
|
created map image. If uploads are enabled the newly created Flickr photo |
|
233
|
|
|
|
|
|
|
ID will be passed as the second element. |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# Defined in Net::Flickr::Geo |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub fetch_map_image { |
|
240
|
|
|
|
|
|
|
my $self = shift; |
|
241
|
|
|
|
|
|
|
my $ph = shift; |
|
242
|
|
|
|
|
|
|
my $thumb_data = shift; |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
my $lat = $self->get_geo_property($ph, "latitude"); |
|
245
|
|
|
|
|
|
|
my $lon = $self->get_geo_property($ph, "longitude"); |
|
246
|
|
|
|
|
|
|
my $acc = $self->get_geo_property($ph, "accuracy"); |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
if ((! $lat) || (! $lon)){ |
|
249
|
|
|
|
|
|
|
return undef; |
|
250
|
|
|
|
|
|
|
} |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my $appid = $self->divine_option("yahoo.appid"); |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
my $h = $self->divine_option("pinwin.map_height", 1024); |
|
257
|
|
|
|
|
|
|
my $w = $self->divine_option("pinwin.map_width", 1024); |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
|
260
|
|
|
|
|
|
|
my $url = "http://local.yahooapis.com/MapsService/V1/mapImage?image_width=" . $w . "&image_height=" . $h . "&appid=" . $appid . "&latitude=" . $lat . "&longitude=" . $lon; |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
if (my $r = $self->divine_option("yahoo.map_radius")){ |
|
263
|
|
|
|
|
|
|
$url .= "&radius=$r"; |
|
264
|
|
|
|
|
|
|
} |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
else { |
|
267
|
|
|
|
|
|
|
my $z = $self->flickr_accuracy_to_zoom($acc); |
|
268
|
|
|
|
|
|
|
$z = $self->divine_option("pinwin.zoom", $z); |
|
269
|
|
|
|
|
|
|
$url .= "&zoom=$z"; |
|
270
|
|
|
|
|
|
|
} |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
$self->log()->info("fetch yahoo map : $url"); |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
my $req = HTTP::Request->new(GET => $url); |
|
275
|
|
|
|
|
|
|
my $res = $ua->request($req); |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
if (! $res->is_success()){ |
|
278
|
|
|
|
|
|
|
$self->log()->error("failed to retrieve yahoo map : " . $res->code()); |
|
279
|
|
|
|
|
|
|
return 0; |
|
280
|
|
|
|
|
|
|
} |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
my $xml = $self->_parse_results_xml($res); |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
if (! $xml){ |
|
285
|
|
|
|
|
|
|
$self->log()->error("failed to parse yahoo api response"); |
|
286
|
|
|
|
|
|
|
return 0; |
|
287
|
|
|
|
|
|
|
} |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
my $map = $xml->findvalue("/Result"); |
|
290
|
|
|
|
|
|
|
my $path = $self->simple_get($map, $self->mk_tempfile(".png")); |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
return { |
|
293
|
|
|
|
|
|
|
'url' => $map, |
|
294
|
|
|
|
|
|
|
'path' => $path, |
|
295
|
|
|
|
|
|
|
}; |
|
296
|
|
|
|
|
|
|
} |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
sub flickr_accuracy_to_zoom { |
|
299
|
|
|
|
|
|
|
my $self = shift; |
|
300
|
|
|
|
|
|
|
my $acc = shift; |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
my %map = (1 => 12, |
|
303
|
|
|
|
|
|
|
2 => 12, |
|
304
|
|
|
|
|
|
|
3 => 12, |
|
305
|
|
|
|
|
|
|
4 => 11, |
|
306
|
|
|
|
|
|
|
5 => 10, |
|
307
|
|
|
|
|
|
|
6 => 9, |
|
308
|
|
|
|
|
|
|
7 => 8, |
|
309
|
|
|
|
|
|
|
8 => 7, |
|
310
|
|
|
|
|
|
|
9 => 6, |
|
311
|
|
|
|
|
|
|
10 => 5, |
|
312
|
|
|
|
|
|
|
12 => 4, |
|
313
|
|
|
|
|
|
|
13 => 3, |
|
314
|
|
|
|
|
|
|
14 => 2, |
|
315
|
|
|
|
|
|
|
15 => 1, |
|
316
|
|
|
|
|
|
|
16 => 1); |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
return $map{$acc}; |
|
319
|
|
|
|
|
|
|
} |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head1 VERSION |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
0.72 |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head1 DATE |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
$Date: 2008/08/03 17:08:40 $ |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=head1 AUTHOR |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
Aaron Straup Cope Eascope@cpan.orgE |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=head1 REQUIREMENTS |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
B
|
|
336
|
|
|
|
|
|
|
to have the pinwin marker successfully composited on to the map.> |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
The transparency is otherwise not honoured by either I or I. Please for your |
|
339
|
|
|
|
|
|
|
patches or cluebats... |
|
340
|
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=head1 NOTES |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
All uploads to Flickr are marked with a content-type of "other". |
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
346
|
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
L |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
L |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head1 BUGS |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
Sure, why not. |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
Please report all bugs via L |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=head1 LICENSE |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
Copyright (c) 2007-2008 Aaron Straup Cope. All Rights Reserved. |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
This is free software. You may redistribute it and/or |
|
362
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=cut |
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
return 1; |