| 1 | package Geo::Leaflet::DivIcon; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base qw{Geo::Leaflet::Icon}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 7 | 2 | 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<Geo::Leaflet::Marker> 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 | 0 | ▶ | sub icon_set { | ||||||||||||||||||||||||||
|
Subroutine
icon_set: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | $self->{'icon_set'} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | $self->{'icon_set'} = 'fa' unless defined $self->{'icon_set'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub icon_name { | ||||||||||||||||||||||||||
|
Subroutine
icon_name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | $self->{'icon_name'} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub icon_font_size { | ||||||||||||||||||||||||||
|
Subroutine
icon_font_size: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | $self->{'icon_font_size'} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $self->{'icon_font_size'} = 48 unless defined $self->{'icon_font_size'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | return $self->{'icon_font_size'}; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head2 | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head2 options | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub options { | ||||||||||||||||||||||||||
|
Subroutine
options: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | $self->{'options'} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $self->{'options'} = {} unless $self->{'options'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | die("Error: $PACKAGE options must be a hash") unless ref($self->{'options'}) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | #This override removes the white square background from the icon | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $self->{'options'}->{'className'} = 'leaflet-div-icon-override' unless defined $self->{'options'}->{'className'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | #This fa helper autobuilds html from icon_name alone | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | unless (defined $self->{'options'}->{'html'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($self->icon_set eq 'fa' and defined($self->icon_name)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->icon_set eq "fa" and defined $self->icon_name
MC/DC0%0/2
$self->icon_set eq "fa" and defined $self->icon_name
$self->icon_set eq "fa"
defined $self->icon_name
Truth table0%0/3
A and B
A= $self->icon_set eq "fa"B= 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{<i class=\"$class\" style=\"$style\"></i>}; | |||||||||||||||||||||||||||
| 98 | 0 | $self->{'options'}->{'html'} = $html; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | unless (defined $self->{'options'}->{'iconAnchor'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | die("Error: Either the html property in options or the icon_name is required") unless $self->{'options'}->{'html'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | return $self->{'options'}; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 METHODS | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head2 stringify | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub _method_name {'divIcon'}; | ||||||||||||||||||||||||||
|
Subroutine
_method_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 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 | 2 | 1; | |||||||||||||||||||||||||||