File Coverage

blib/lib/Geo/Leaflet/DivIcon.pm
Criterion Covered Total %
statement 9 37 24.3
branch 0 26 0.0
condition 0 3 0.0
subroutine 3 8 37.5
pod 4 4 100.0
total 16 78 20.5


line stmt bran cond sub pod time code
1             package Geo::Leaflet::DivIcon;
2 2     2   11 use strict;
  2         3  
  2         59  
3 2     2   7 use warnings;
  2         2  
  2         72  
4 2     2   7 use base qw{Geo::Leaflet::Icon};
  2         2  
  2         1293  
5              
6             our $VERSION = '0.04';
7             our $PACKAGE = __PACKAGE__;
8              
9             =head1 NAME
10              
11             Geo::Leaflet::DivIcon - Leaflet HTML/CSS icon object
12              
13             =head1 SYNOPSIS
14              
15             use Geo::Leaflet;
16             my $map = Geo::Leaflet->new;
17              
18             =head1 DESCRIPTION
19              
20             This package constructs a Leaflet divIcon object for use in a L object.
21              
22             =head1 CONSTRUCTORS
23              
24             =head2 new
25              
26             =head1 PROPERTIES
27              
28             =head2 name
29              
30             =cut
31              
32             #from parent icon
33              
34             =head2 icon_set
35              
36             $icon->icon_set('fa'); #Font Awesome v4.7
37              
38             =cut
39              
40             sub icon_set {
41 0     0 1   my $self = shift;
42 0 0         $self->{'icon_set'} = shift if @_;
43 0 0         $self->{'icon_set'} = 'fa' unless defined $self->{'icon_set'};
44 0           return $self->{'icon_set'};
45             }
46              
47             =head2 icon_name
48              
49             $icon->icon_name('bicycle');
50              
51             See: https://fontawesome.com/v4/icons/
52              
53             =cut
54              
55             sub icon_name {
56 0     0 1   my $self = shift;
57 0 0         $self->{'icon_name'} = shift if @_;
58 0           return $self->{'icon_name'};
59             }
60              
61             =head2 icon_font_size
62              
63              
64             $icon->icon_name(48);
65              
66             Default: 48
67              
68             =cut
69              
70             sub icon_font_size {
71 0     0 1   my $self = shift;
72 0 0         $self->{'icon_font_size'} = shift if @_;
73 0 0         $self->{'icon_font_size'} = 48 unless defined $self->{'icon_font_size'};
74 0           return $self->{'icon_font_size'};
75             }
76              
77             =head2
78              
79             =head2 options
80              
81             =cut
82              
83             sub options {
84 0     0 1   my $self = shift;
85 0 0         $self->{'options'} = shift if @_;
86 0 0         $self->{'options'} = {} unless $self->{'options'};
87 0 0         die("Error: $PACKAGE options must be a hash") unless ref($self->{'options'}) eq 'HASH';
88              
89             #This override removes the white square background from the icon
90 0 0         $self->{'options'}->{'className'} = 'leaflet-div-icon-override' unless defined $self->{'options'}->{'className'};
91              
92             #This fa helper autobuilds html from icon_name alone
93 0 0         unless (defined $self->{'options'}->{'html'}) {
94 0 0 0       if ($self->icon_set eq 'fa' and defined($self->icon_name)) {
95 0           my $style = sprintf("font-size:%dpx", $self->icon_font_size);
96 0           my $class = sprintf("fa fa-%s", $self->icon_name); #TODO: figure out if fa-fw: fixed width is better here
97 0           my $html = qq{};
98 0           $self->{'options'}->{'html'} = $html;
99             }
100             }
101 0 0         unless (defined $self->{'options'}->{'iconAnchor'}) {
102 0           my $center = $self->icon_font_size / 2; #this assumes square icons
103 0           $self->{'options'}->{'iconAnchor'} = [$center, $center]; #this is a pain!!!
104             }
105 0 0         die("Error: Either the html property in options or the icon_name is required") unless $self->{'options'}->{'html'};
106 0           return $self->{'options'};
107             }
108              
109             =head1 METHODS
110              
111             =head2 stringify
112              
113             =cut
114              
115 0     0     sub _method_name {'divIcon'};
116              
117             #see parent icon
118              
119             =head2 JSON
120              
121             =cut
122              
123             #from parent icon
124              
125             =head1 SEE ALSO
126              
127             =head1 AUTHOR
128              
129             Michael R. Davis
130              
131             =head1 COPYRIGHT AND LICENSE
132              
133             Copyright (C) 2024 by Michael R. Davis
134              
135             MIT LICENSE
136              
137             =cut
138              
139             1;