line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Leafletjs; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
50549
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
4
|
1
|
|
|
1
|
|
1776
|
use File::Basename 'dirname'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
101
|
|
5
|
1
|
|
|
1
|
|
1061
|
use File::Spec::Functions 'catdir'; |
|
1
|
|
|
|
|
1558
|
|
|
1
|
|
|
|
|
70
|
|
6
|
1
|
|
|
1
|
|
1403
|
use File::ShareDir ':ALL'; |
|
1
|
|
|
|
|
10347
|
|
|
1
|
|
|
|
|
730
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %defaults = ( |
11
|
|
|
|
|
|
|
name => 'map', |
12
|
|
|
|
|
|
|
cssid => 'map', |
13
|
|
|
|
|
|
|
longitude => undef, |
14
|
|
|
|
|
|
|
latitude => undef, |
15
|
|
|
|
|
|
|
zoomLevel => 13, |
16
|
|
|
|
|
|
|
tileLayer => |
17
|
|
|
|
|
|
|
'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', |
18
|
|
|
|
|
|
|
maxZoom => 18, |
19
|
|
|
|
|
|
|
attribution => |
20
|
|
|
|
|
|
|
'Map data © OpenStreetMap contributors, ' |
21
|
|
|
|
|
|
|
. 'CC-BY-SA, ' |
22
|
|
|
|
|
|
|
. 'Imagery © CloudMade', |
23
|
|
|
|
|
|
|
markers => [ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Example |
26
|
|
|
|
|
|
|
# { name => 'Stubby', |
27
|
|
|
|
|
|
|
# longitude => undef, |
28
|
|
|
|
|
|
|
# latitude => undef, |
29
|
|
|
|
|
|
|
# popup => 'A new message here.', |
30
|
|
|
|
|
|
|
# } |
31
|
|
|
|
|
|
|
], |
32
|
|
|
|
|
|
|
circles => [ |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Example: |
35
|
|
|
|
|
|
|
# { name => 'circly', |
36
|
|
|
|
|
|
|
# longitude => undef, |
37
|
|
|
|
|
|
|
# latitude => undef, |
38
|
|
|
|
|
|
|
# color => 'red', |
39
|
|
|
|
|
|
|
# fillColor => '#f03', |
40
|
|
|
|
|
|
|
# fillOpacity => 0.5, |
41
|
|
|
|
|
|
|
# radius => 500, |
42
|
|
|
|
|
|
|
# } |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
], |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub register { |
51
|
0
|
|
|
0
|
1
|
|
my ($plugin, $app) = @_; |
52
|
0
|
0
|
|
|
|
|
my (%conf) = (%defaults, %{$_[2] || {}}); |
|
0
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
push @{$app->static->paths}, |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
catdir(dist_dir('Mojolicious-Plugin-Leafletjs'), 'public'); |
55
|
0
|
|
|
|
|
|
push @{$app->renderer->classes}, __PACKAGE__; |
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$app->helper( |
57
|
|
|
|
|
|
|
leaflet => sub { |
58
|
0
|
|
|
0
|
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
%conf = (%conf, %{shift()}); |
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->render( |
61
|
|
|
|
|
|
|
template => 'leaflet_template', |
62
|
|
|
|
|
|
|
partial => 1, |
63
|
|
|
|
|
|
|
attrs => \%conf, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$app->helper( |
69
|
|
|
|
|
|
|
leaflet_include => sub { |
70
|
0
|
|
|
0
|
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
$self->render( |
72
|
|
|
|
|
|
|
template => 'leaflet_include', |
73
|
|
|
|
|
|
|
partial => 1, |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
$app->hook( |
78
|
|
|
|
|
|
|
after_dispatch => sub { |
79
|
0
|
|
|
0
|
|
|
my $c = shift; |
80
|
0
|
|
|
|
|
|
my $dom = $c->res->dom; |
81
|
0
|
0
|
|
|
|
|
my $head = $dom->at('head') or return; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $append = $c->leaflet_include; |
84
|
0
|
|
|
|
|
|
$head->append_content($append); |
85
|
0
|
|
|
|
|
|
$c->tx->res->body($dom->to_xml); |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__DATA__ |