line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::GoogleMaps::MobileTool; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
381645
|
use warnings; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
164
|
|
4
|
6
|
|
|
6
|
|
29
|
use strict; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
150
|
|
5
|
6
|
|
|
6
|
|
26
|
use Carp; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
442
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
10336
|
use version; our $VERSION = qv('0.0.1'); |
|
6
|
|
|
|
|
14516
|
|
|
6
|
|
|
|
|
35
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
11286
|
use Math::Trig; |
|
6
|
|
|
|
|
131049
|
|
|
6
|
|
|
|
|
1512
|
|
10
|
6
|
|
|
6
|
|
78
|
use base 'Exporter'; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
1320
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( |
13
|
|
|
|
|
|
|
lnglat2pixel |
14
|
|
|
|
|
|
|
pixel2lnglat |
15
|
|
|
|
|
|
|
deltapixel2lnglat |
16
|
|
|
|
|
|
|
deltalnglat_perpixel |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $zmbase = 128; |
20
|
|
|
|
|
|
|
my @zmmax; |
21
|
|
|
|
|
|
|
my $offproj; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub import { |
24
|
6
|
|
|
6
|
|
120
|
my ( $class, $opt ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
6
|
100
|
66
|
|
|
146
|
$offproj = ( $opt && $opt eq 'unableProj' ) ? 1 : 0; |
27
|
6
|
100
|
|
|
|
24
|
unless ( $offproj ) { |
28
|
4
|
|
|
|
|
9
|
eval { require Geo::Proj }; |
|
4
|
|
|
|
|
1932
|
|
29
|
4
|
50
|
|
|
|
48
|
if ( $@ ) { |
30
|
4
|
|
|
|
|
9
|
$offproj = 1; |
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
0
|
Geo::Proj->import(); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
6
|
|
|
|
|
23
|
foreach my $zm (0..20) { |
37
|
126
|
|
|
|
|
229
|
$zmmax[$zm] = $zmbase * 2 ** $zm; |
38
|
126
|
50
|
|
|
|
267
|
unless ( $offproj ) { |
39
|
0
|
|
|
|
|
0
|
my $name = "gmapzm$zm"; |
40
|
0
|
|
|
|
|
0
|
my $r = $zmmax[$zm] / pi; |
41
|
0
|
|
|
|
|
0
|
my $proj = "+proj=merc +a=$r +b=$r +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=\@null +no |
42
|
|
|
|
|
|
|
_defs"; |
43
|
0
|
|
|
|
|
0
|
Geo::Proj->new( |
44
|
|
|
|
|
|
|
nick => $name, |
45
|
|
|
|
|
|
|
proj4 => $proj, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
6
|
|
|
|
|
19
|
local $Exporter::ExportLevel = $Exporter::ExportLevel + 1; |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
10794
|
$class->SUPER::import(); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub lnglat2pixel { |
56
|
12
|
|
|
12
|
1
|
13940
|
my ( $lng, $lat, $zm, $intoff ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
12
|
|
|
|
|
13
|
my ( $x, $y ); |
59
|
|
|
|
|
|
|
|
60
|
12
|
50
|
|
|
|
23
|
if ( $offproj ) { |
61
|
12
|
|
|
|
|
32
|
$x = $lng / 180.0 * $zmmax[$zm]; |
62
|
12
|
|
|
|
|
51
|
$y = log( tan( pi * ( 0.25 + $lat / 360.0 ) ) ) / pi * $zmmax[$zm]; |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
0
|
my $pt = Geo::Proj->to( 'wgs84', "gmapzm$zm", [ $lng, $lat ] ); |
65
|
0
|
|
|
|
|
0
|
( $x, $y ) = @{ $pt }; |
|
0
|
|
|
|
|
0
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
12
|
|
|
|
|
194
|
$x += $zmmax[$zm]; |
69
|
12
|
|
|
|
|
20
|
$y = -1.0 * ( $y - $zmmax[$zm] ); |
70
|
|
|
|
|
|
|
|
71
|
12
|
100
|
|
|
|
28
|
( $x, $y ) = map { int( $_ ) } ( $x, $y ) unless ( $intoff ); |
|
8
|
|
|
|
|
16
|
|
72
|
|
|
|
|
|
|
|
73
|
12
|
50
|
|
|
|
41
|
return wantarray ? ( $x, $y ) : [ $x, $y ]; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub pixel2lnglat { |
77
|
12
|
|
|
12
|
1
|
13964
|
my ( $x, $y, $zm, $intoff ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
12
|
100
|
|
|
|
28
|
( $x, $y ) = map { $_ + 0.5 } ( $x, $y ) unless ( $intoff ); |
|
8
|
|
|
|
|
20
|
|
80
|
|
|
|
|
|
|
|
81
|
12
|
|
|
|
|
20
|
$x -= $zmmax[$zm]; |
82
|
12
|
|
|
|
|
21
|
$y = -1.0 * $y + $zmmax[$zm]; |
83
|
|
|
|
|
|
|
|
84
|
12
|
|
|
|
|
34
|
my ( $lng, $lat ); |
85
|
|
|
|
|
|
|
|
86
|
12
|
50
|
|
|
|
21
|
if ( $offproj ) { |
87
|
12
|
|
|
|
|
21
|
$lng = $x / $zmmax[$zm] * 180.0; |
88
|
12
|
|
|
|
|
38
|
$lat = atan( sinh( $y / $zmmax[$zm] * pi ) ) / pi *180.0; |
89
|
|
|
|
|
|
|
} else { |
90
|
0
|
|
|
|
|
0
|
my $pt = Geo::Proj->to( "gmapzm$zm", 'wgs84', [ $x, $y ] ); |
91
|
0
|
|
|
|
|
0
|
( $lng, $lat ) = @{$pt}; |
|
0
|
|
|
|
|
0
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
12
|
50
|
|
|
|
211
|
return wantarray ? ( $lng, $lat ) : [ $lng, $lat ]; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub deltapixel2lnglat { |
98
|
8
|
|
|
8
|
1
|
38
|
my ( $lng, $lat, $dpxx, $dpxy, $zm ) = @_; |
99
|
|
|
|
|
|
|
|
100
|
8
|
|
|
|
|
18
|
my ( $fx, $fy ) = lnglat2pixel( $lng, $lat, $zm, 1 ); |
101
|
|
|
|
|
|
|
|
102
|
8
|
|
|
|
|
10
|
$fx += $dpxx; |
103
|
|
|
|
|
|
|
|
104
|
8
|
|
|
|
|
10
|
$fy += $dpxy; |
105
|
|
|
|
|
|
|
|
106
|
8
|
|
|
|
|
16
|
return pixel2lnglat( $fx, $fy, $zm, 1 ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub deltalnglat_perpixel { |
110
|
4
|
|
|
4
|
1
|
14614
|
my ( $lng, $lat, $zm ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
4
|
|
|
|
|
15
|
my $dpx_plng = $zmmax[$zm] / 180.0; |
113
|
4
|
|
|
|
|
22
|
my $dpy_plat = sec( $lat / 180.0 * pi ) * $zmmax[$zm] / 180.0; |
114
|
|
|
|
|
|
|
|
115
|
4
|
|
|
|
|
76
|
return map { 1.0 / $_ } ( $dpx_plng, $dpy_plat ); |
|
8
|
|
|
|
|
20
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
119
|
|
|
|
|
|
|
__END__ |