line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Imager::Bing::MapLayer::Utils; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
738083
|
use v5.10.1; |
|
6
|
|
|
|
|
23
|
|
|
6
|
|
|
|
|
287
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
195
|
|
6
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
197
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
38
|
use Carp qw/ confess /; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
344
|
|
9
|
6
|
|
|
6
|
|
5408
|
use Const::Exporter; |
|
6
|
|
|
|
|
47134
|
|
|
6
|
|
|
|
|
37
|
|
10
|
6
|
|
|
6
|
|
789
|
use Const::Fast; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
37
|
|
11
|
6
|
|
|
6
|
|
393
|
use List::MoreUtils qw/ minmax /; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
330
|
|
12
|
6
|
|
|
6
|
|
3844
|
use POSIX::2008 qw/ round /; |
|
6
|
|
|
|
|
8213
|
|
|
6
|
|
|
|
|
1048
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
38
|
use version 0.77; our $VERSION = version->declare('v0.1.9'); |
|
6
|
|
|
|
|
125
|
|
|
6
|
|
|
|
|
42
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
19
|
|
|
|
|
|
|
@EXPORT, |
20
|
|
|
|
|
|
|
qw/ |
21
|
|
|
|
|
|
|
width_at_level latlon_to_pixel pixel_to_tile_coords |
22
|
|
|
|
|
|
|
tile_coords_to_pixel_origin |
23
|
|
|
|
|
|
|
tile_coords_to_quad_key quad_key_to_tile_coords |
24
|
|
|
|
|
|
|
bounding_box optimize_points |
25
|
|
|
|
|
|
|
get_ground_resolution get_map_scale |
26
|
|
|
|
|
|
|
/ |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Imager::Bing::MapLayer::Utils - utility functions for map layer modules |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This module contains utility functions for L<Imager::Bing::MapLayer>. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 EXPORTS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
By default, none. Constants and functions must be included in the |
40
|
|
|
|
|
|
|
usage line explicitly. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 CONSTANTS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 C<$TILE_WIDTH> |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 C<$TILE_HEIGHT> |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
The width and height of individual tiles. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
43
|
use Const::Exporter default => [ |
53
|
|
|
|
|
|
|
'$TILE_WIDTH' => 256, |
54
|
|
|
|
|
|
|
'$TILE_HEIGHT' => 256, |
55
|
6
|
|
|
6
|
|
885
|
]; |
|
6
|
|
|
|
|
19
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 C<$MIN_ZOOM_LEVEL> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 C<$MIN_ZOOM_LEVEL> |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
The minimum and maximum zoom levels supported by these modules. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Note that C<$MAX_ZOOM_LEVEL> can actually be as high as 23, but that |
64
|
|
|
|
|
|
|
causes bit overflows for calculations on 32-bit integers. We also |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
don't want to generate tiles beyond level 18, since the amount of |
67
|
|
|
|
|
|
|
tiles required is so large that we run out of memory (and we also |
68
|
|
|
|
|
|
|
don't need it, since Bing switches to a street view mode). |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
When the tiles are not saved in memory, then we can generate higher |
71
|
|
|
|
|
|
|
resolutions. However, Bing doesn't seem to support zoom levels higher |
72
|
|
|
|
|
|
|
than 19 at this time. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
6
|
|
|
|
|
31
|
use Const::Exporter default => [ |
77
|
|
|
|
|
|
|
'$MIN_ZOOM_LEVEL' => 1, |
78
|
|
|
|
|
|
|
'$MAX_ZOOM_LEVEL' => 19, |
79
|
6
|
|
|
6
|
|
1652
|
]; |
|
6
|
|
|
|
|
12
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Local constants used by these functions |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
const my $PI => 3.1415926535897932; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
const my $EARTH_RADIUS => 6_378_137; # Earth radius (meters) |
86
|
|
|
|
|
|
|
const my $METERS_PER_INCH => 0.0254; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 FUNCTIONS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 C<width_at_level> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $width = width_at_level( $level ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Returns the width of a zoom level. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub width_at_level { |
99
|
63
|
|
|
63
|
1
|
23672
|
my ($level) = @_; |
100
|
|
|
|
|
|
|
|
101
|
63
|
100
|
100
|
|
|
369
|
confess |
102
|
|
|
|
|
|
|
"invalid level (must be between ${MIN_ZOOM_LEVEL} and ${MAX_ZOOM_LEVEL}" |
103
|
|
|
|
|
|
|
if ( ( $level < $MIN_ZOOM_LEVEL ) || ( $level > $MAX_ZOOM_LEVEL ) ); |
104
|
|
|
|
|
|
|
|
105
|
61
|
|
|
|
|
145
|
return 1 << ( $level + 8 ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 C<latlon_to_pixel> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my ($pixel_x, $pixel_y) = latlon_to_pixel( $level, $latitude, $longitude ); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Converts latitude and longitude to pixel coodinates on a specific zoom level. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub latlon_to_pixel { |
117
|
42
|
|
|
42
|
1
|
13671
|
my ( $level, $latitude, $longitude ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
42
|
|
|
|
|
114
|
my $width = width_at_level($level); |
120
|
|
|
|
|
|
|
|
121
|
42
|
|
|
|
|
259
|
my $sin_latitude = sin( $latitude * $PI / 180 ); |
122
|
|
|
|
|
|
|
|
123
|
42
|
|
|
|
|
294
|
return map { round($_) } ( |
|
84
|
|
|
|
|
478
|
|
124
|
|
|
|
|
|
|
( ( $longitude + 180 ) / 360 ) * $width, |
125
|
|
|
|
|
|
|
( 0.5 - log( ( 1 + $sin_latitude ) / ( 1 - $sin_latitude ) ) |
126
|
|
|
|
|
|
|
/ ( 4 * $PI ) |
127
|
|
|
|
|
|
|
) * $width, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 C<pixel_to_tile_coords> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my ($tile_x, $tile_y) = pixel_to_tile_coords( $pixel_x, $pixel_y ); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Converts pixel coordinates to map tile coordinates. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub pixel_to_tile_coords { |
141
|
45
|
|
|
45
|
1
|
85
|
my ( $pixel_x, $pixel_y ) = @_; |
142
|
45
|
|
|
|
|
102
|
return map { $_ >> 8 } ( $pixel_x, $pixel_y ); |
|
90
|
|
|
|
|
229
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 C<tile_coords_to_pixel_origin> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my ($origin_x, $origin_y) = tile_coords_to_pixel_origin( $tile_x, $tile_y ); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Returns the top-left pixel coordinates from tile coordinates. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub tile_coords_to_pixel_origin { |
154
|
34
|
|
|
34
|
1
|
60
|
my ( $tile_x, $tile_y ) = @_; |
155
|
34
|
|
|
|
|
57
|
return map { $_ << 8 } ( $tile_x, $tile_y ); |
|
68
|
|
|
|
|
682
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 C<tile_coords_to_quad_key> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $quad_key = tile_coords_to_quad_key( $level, $tile_x, $tile_y ); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Returns the quadrant key ("quad key") for a given tile at a given level. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub tile_coords_to_quad_key { |
167
|
6
|
|
|
6
|
|
9614
|
use integer; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
46
|
|
168
|
|
|
|
|
|
|
|
169
|
32
|
|
|
32
|
1
|
7373
|
my ( $level, $tile_x, $tile_y ) = @_; |
170
|
|
|
|
|
|
|
|
171
|
32
|
|
|
|
|
70
|
my $mask = 1 << ( $level - 1 ); |
172
|
32
|
|
|
|
|
59
|
my $key = ''; |
173
|
|
|
|
|
|
|
|
174
|
32
|
|
|
|
|
88
|
while ($mask) { |
175
|
|
|
|
|
|
|
|
176
|
331
|
|
|
|
|
304
|
my $digit = 0; |
177
|
|
|
|
|
|
|
|
178
|
331
|
100
|
|
|
|
571
|
$digit |= 1 if ( $tile_x & $mask ); |
179
|
331
|
100
|
|
|
|
508
|
$digit |= 2 if ( $tile_y & $mask ); |
180
|
|
|
|
|
|
|
|
181
|
331
|
|
|
|
|
325
|
$key .= $digit; |
182
|
|
|
|
|
|
|
|
183
|
331
|
|
|
|
|
540
|
$mask = $mask >> 1; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
32
|
|
|
|
|
618
|
return $key; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 C<quad_key_to_tile_coords> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
my ($tile_x, $tile_y, $level) = quad_key_to_tile_coords( $quad_key ); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Returns the tile coordinates and level from the quad key. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub quad_key_to_tile_coords { |
199
|
6
|
|
|
6
|
|
708
|
use integer; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
27
|
|
200
|
|
|
|
|
|
|
|
201
|
34
|
|
|
34
|
1
|
64
|
my ($quad_key) = @_; |
202
|
|
|
|
|
|
|
|
203
|
34
|
|
|
|
|
174
|
state $re = qr/^[0-3]{$MIN_ZOOM_LEVEL,$MAX_ZOOM_LEVEL}$/; |
204
|
|
|
|
|
|
|
|
205
|
34
|
50
|
|
|
|
263
|
unless ( $quad_key =~ $re ) { |
206
|
0
|
|
|
|
|
0
|
confess "invalid quad key"; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
34
|
|
|
|
|
64
|
my ( $tile_x, $tile_y ) = ( 0, 0 ); |
210
|
|
|
|
|
|
|
|
211
|
34
|
|
|
|
|
64
|
my $level = length($quad_key); # implicitly checked by regex |
212
|
34
|
|
|
|
|
59
|
my $mask = 1 << ( $level - 1 ); |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# Translate the quad key into a string of digits |
215
|
|
|
|
|
|
|
|
216
|
34
|
|
|
|
|
187
|
foreach my $digit ( map { $_ - 48 } ( unpack 'c*', $quad_key ) ) { |
|
363
|
|
|
|
|
453
|
|
217
|
|
|
|
|
|
|
|
218
|
363
|
100
|
|
|
|
540
|
$tile_x |= $mask if ( $digit & 1 ); |
219
|
363
|
100
|
|
|
|
543
|
$tile_y |= $mask if ( $digit & 2 ); |
220
|
|
|
|
|
|
|
|
221
|
363
|
|
|
|
|
401
|
$mask = $mask >> 1; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
34
|
|
|
|
|
664
|
return ( $tile_x, $tile_y, $level ); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 C<get_ground_resolution> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
$meters_per_pixel = get_ground_resolution( $level, $latitude ); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
This returns the distance on the ground that's represented by a single |
232
|
|
|
|
|
|
|
pixel. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub get_ground_resolution { |
237
|
0
|
|
|
0
|
1
|
0
|
my ( $level, $latitude ) = @_; |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
0
|
return ( cos( $latitude * $PI / 180 ) * ( 2 * $PI * $EARTH_RADIUS ) ) |
240
|
|
|
|
|
|
|
/ width_at_level($level); |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 C<get_map_scale> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
TODO |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub get_map_scale { |
251
|
0
|
|
|
0
|
1
|
0
|
my ( $level, $latitude, $screen_dpi ) = @_; |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
0
|
|
|
0
|
$screen_dpi //= 96; # a standard screen dpi |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
0
|
return get_ground_resolution( $level, $latitude ) |
256
|
|
|
|
|
|
|
* $screen_dpi / $METERS_PER_INCH; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head2 C<bounding_box> |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
my ($left, $top, $right, $bottom) = bounding_box( %args ); |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
This parses the arguments given to L<Imager::Draw> methods to |
264
|
|
|
|
|
|
|
calculate a bounding box. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=cut |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub bounding_box { |
269
|
13
|
|
|
13
|
1
|
42
|
my (%args) = @_; |
270
|
|
|
|
|
|
|
|
271
|
13
|
|
|
|
|
51
|
my %points = ( x => [], 'y' => [] ); |
272
|
|
|
|
|
|
|
|
273
|
13
|
50
|
|
|
|
78
|
if ( my $radius = $args{r} ) { # radius for arcs and circles |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
274
|
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
0
|
foreach my $axis (qw/ x y /) { |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
0
|
push @{ $points{$axis} }, |
|
0
|
|
|
|
|
0
|
|
278
|
|
|
|
|
|
|
( $args{$axis} - $radius, $args{$axis} + $radius ); |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
} elsif ( my $box = $args{box} ) { |
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
0
|
push @{ $points{x} }, ( $box->[0], $box->[2] ); |
|
0
|
|
|
|
|
0
|
|
285
|
0
|
|
|
|
|
0
|
push @{ $points{y} }, ( $box->[1], $box->[3] ); |
|
0
|
|
|
|
|
0
|
|
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
} elsif ( my $list = $args{points} ) { |
288
|
|
|
|
|
|
|
|
289
|
0
|
|
|
|
|
0
|
foreach my $pt ( @{$list} ) { |
|
0
|
|
|
|
|
0
|
|
290
|
|
|
|
|
|
|
|
291
|
0
|
|
|
|
|
0
|
push @{ $points{x} }, $pt->[0]; |
|
0
|
|
|
|
|
0
|
|
292
|
0
|
|
|
|
|
0
|
push @{ $points{y} }, $pt->[1]; |
|
0
|
|
|
|
|
0
|
|
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
} else { |
297
|
|
|
|
|
|
|
|
298
|
13
|
|
|
|
|
34
|
foreach my $axis (qw/ x y /) { |
299
|
|
|
|
|
|
|
|
300
|
26
|
50
|
|
|
|
54
|
if ( ref $args{$axis} ) { |
301
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
0
|
push @{ $points{$axis} }, @{ $args{$axis} }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
} else { |
305
|
|
|
|
|
|
|
|
306
|
26
|
50
|
|
|
|
56
|
push @{ $points{$axis} }, $args{$axis} |
|
26
|
|
|
|
|
77
|
|
307
|
|
|
|
|
|
|
if ( defined $args{$axis} ); |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
26
|
|
|
|
|
47
|
foreach my $alt (qw/ 1 2 min max /) { |
312
|
|
|
|
|
|
|
|
313
|
104
|
|
|
|
|
119
|
my $arg = $axis . $alt; |
314
|
|
|
|
|
|
|
|
315
|
104
|
50
|
|
|
|
225
|
push @{ $points{$axis} }, $args{$arg} |
|
0
|
|
|
|
|
0
|
|
316
|
|
|
|
|
|
|
if ( defined $args{$arg} ); |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
|
324
|
13
|
|
|
|
|
22
|
my ( $xmin, $xmax ) = minmax( @{ $points{x} } ); |
|
13
|
|
|
|
|
64
|
|
325
|
13
|
|
|
|
|
18
|
my ( $ymin, $ymax ) = minmax( @{ $points{y} } ); |
|
13
|
|
|
|
|
34
|
|
326
|
|
|
|
|
|
|
|
327
|
13
|
|
|
|
|
62
|
return ( $xmin, $ymin, $xmax, $ymax ); |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
} |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=head2 C<optimize_points> |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
my @points2 = @{ optimize_points( \@points ) }; |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
This function takes a reference to a list of points and returns |
336
|
|
|
|
|
|
|
another reference to a list of points, without adjacent duplicate |
337
|
|
|
|
|
|
|
points. This reduces the number of points to plot for complex |
338
|
|
|
|
|
|
|
polylines on lower zoom levels. |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=cut |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub optimize_points { |
343
|
0
|
|
|
0
|
1
|
|
my ($points) = @_; |
344
|
|
|
|
|
|
|
|
345
|
0
|
|
|
|
|
|
my $last = $points->[0]; |
346
|
|
|
|
|
|
|
|
347
|
0
|
|
|
|
|
|
my @list = ($last); |
348
|
|
|
|
|
|
|
|
349
|
0
|
|
|
|
|
|
my $i = 1; |
350
|
|
|
|
|
|
|
|
351
|
0
|
|
|
|
|
|
while ( my $point = $points->[ $i++ ] ) { |
352
|
|
|
|
|
|
|
|
353
|
0
|
0
|
0
|
|
|
|
if ( ( $point->[0] != $last->[0] ) || ( $point->[1] != $last->[1] ) ) |
354
|
|
|
|
|
|
|
{ |
355
|
|
|
|
|
|
|
|
356
|
0
|
|
|
|
|
|
push @list, $point; |
357
|
|
|
|
|
|
|
|
358
|
0
|
|
|
|
|
|
$last = $point; |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
|
364
|
0
|
|
|
|
|
|
return \@list; |
365
|
|
|
|
|
|
|
} |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
=head1 SEE ALSO |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
=over |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=item A discussion of the Bing Maps Tile System |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
L<http://msdn.microsoft.com/en-us/library/bb259689.aspx> |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
=back |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=cut |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
1; |