Geo-Leaflet
view release on metacpan or search on metacpan
### icon
Represents an icon to provide when creating a marker.
my $icon = $map->icon(
name => "my_icon", #must be a valid JavaScript variable name
options => {
iconUrl => "my-icon.png",
iconSize => [38, 95],
iconAnchor => [22, 94],
popupAnchor => [-3, -76],
shadowUrl => "my-icon-shadow.png",
shadowSize => [68, 95],
shadowAnchor => [22, 94],
}
);
See: [https://leafletjs.com/reference.html#icon](https://leafletjs.com/reference.html#icon)
### divIcon
## DESCRIPTION
This package constructs a Leaflet polyline object for use on a [Geo::Leaflet](https://metacpan.org/pod/Geo::Leaflet) map.
## PROPERTIES
### coordinates
### options
### popup
## METHODS
### stringify
## SEE ALSO
## AUTHOR
Michael R. Davis
## DESCRIPTION
This package constructs a Leaflet polygon object for use on a [Geo::Leaflet](https://metacpan.org/pod/Geo::Leaflet) map.
## PROPERTIES
### coordinates
### options
### popup
## METHODS
### stringify
## SEE ALSO
## AUTHOR
Michael R. Davis
### llat
### llon
### ulat
### ulon
### options
### popup
## METHODS
### stringify
## SEE ALSO
## AUTHOR
Michael R. Davis
This package constructs a Leaflet marker object for use on a [Geo::Leaflet](https://metacpan.org/pod/Geo::Leaflet) map.
## PROPERTIES
### lat
### lon
### options
### popup
## METHODS
### stringify
## SEE ALSO
## AUTHOR
Michael R. Davis
example/quick-start-example.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use Geo::Leaflet;
my $map = Geo::Leaflet->new(center=>[51.505, -0.09], zoom=>13, width=>'100%', height=>'100%');
$map->marker( lat => 51.5,
lon => -0.09,
popup => 'marker popup',
tooltip => "marker tooltip");
$map->circle( lat => 51.508,
lon => -0.11,
radius => 500,
options => {color=>'red', fillColor=>'#f03', fillOpacity=>0.5},
popup => 'circle popup',
tooltip => 'circle tooltip');
$map->polygon( coordinates => [[51.509, -0.08], [51.503, -0.06], [51.51, -0.047]],
options => {color=>"blue"},
popup => 'polygon popup',
tooltip => 'polygon tooltip');
$map->polyline(coordinates => [[51.508, -0.08], [51.502, -0.06], [51.50, -0.047]],
options => {color=>"green"},
popup => 'polyline popup',
tooltip => 'polyline tooltip');
$map->rectangle(llat => 51.496,
llon => -0.08,
ulat => 51.500,
ulon => -0.047,
options => {color=>"orange"},
popup => 'rectangle popup',
tooltip => 'rectangle tooltip');
my $icon = $map->icon(
options => {
iconUrl => 'https://maps.google.com/mapfiles/kml/paddle/1.png',
iconSize => [64, 64],
iconAnchor => [32, 64],
popupAnchor => [0, -48],
tooltipAnchor => [0,-48],
},
);
$map->marker( lat => 51.498,
lon => -0.10,
popup => 'marker icon popup',
tooltip => "marker icon tooltip",
options => {
icon => $icon->name,
},
);
my $divIcon = $map->divIcon(
icon_name => "bicycle", #defaults icon_set = fa, icon_size = 48, iconAnchor ~ [middle]
);
$map->marker( lat => 51.498,
lon => -0.12,
popup => 'marker divIcon popup',
tooltip => "marker divIcon tooltip",
options => {
icon => $divIcon->name,
},
);
my $icon_map_marker = $map->divIcon(
icon_name => "map-marker", #defaults icon_set = fa, icon_size = 48, iconAnchor ~ [middle]
icon_font_size => 48,
options => {
iconAnchor => [13,44], #bottom center (I'm not sure "why" it is not 24/48)
},
);
$map->marker( lat => 51.498,
lon => -0.105,
popup => 'icon_map_marker',
tooltip => "icon_map_marker",
options => {
icon => $icon_map_marker->name,
},
);
my $icon_dot_circle = $map->divIcon(
icon_name => "dot-circle-o",
icon_font_size => 28,
options => {
iconAnchor => [12,14], #center (I'm not sure "why" it is not half)
},
);
$map->marker( lat => 51.498,
lon => -0.11,
popup => 'icon_dot_circle',
tooltip => "icon_dot_circle",
options => {
icon => $icon_dot_circle->name,
},
);
my $icon_fa_defaults = $map->divIcon(icon_name => "bicycle");
$map->marker( lat => 51.49,
lib/Geo/Leaflet.pm view on Meta::CPAN
=head2 icon
Represents an icon to provide when creating a marker.
my $icon = $map->icon(
name => "my_icon", #must be a valid JavaScript variable name
options => {
iconUrl => "my-icon.png",
iconSize => [38, 95],
iconAnchor => [22, 94],
popupAnchor => [-3, -76],
shadowUrl => "my-icon-shadow.png",
shadowSize => [68, 95],
shadowAnchor => [22, 94],
}
);
See: L<https://leafletjs.com/reference.html#icon>
=cut
lib/Geo/Leaflet/Base.pm view on Meta::CPAN
# attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
# }).addTo(map);
#
#const circle = L.circle([51.508, -0.11], {
# color: 'red',
# fillColor: '#f03',
# fillOpacity: 0.5,
# radius: 500
# }).addTo(map);
my $addmap = '.addTo(map)';
my $popup = $self->can('popup') && $self->popup ? sprintf('.bindPopup(%s)', $self->JSON->encode($self->popup)) : '';
my $tooltip = $self->can('tooltip') && $self->tooltip ? sprintf('.bindTooltip(%s)', $self->JSON->encode($self->tooltip)) : '';
return sprintf(q{L.%s(%s, %s)%s%s%s;},
$self->_method_name,
$self->JSON->encode($value),
$self->JSON->encode($self->options),
$addmap,
$popup,
$tooltip,
);
}
=head2 JSON
=cut
sub JSON {
my $self = shift;
lib/Geo/Leaflet/Icon.pm view on Meta::CPAN
=cut
sub _method_name {'icon'};
sub stringify {
my $self = shift;
# var icon_name = L.icon({
# iconUrl: 'my-icon.png',
# iconSize: [38, 95],
# iconAnchor: [22, 94],
# popupAnchor: [-3, -76],
# shadowUrl: 'my-icon-shadow.png',
# shadowSize: [68, 95],
# shadowAnchor: [22, 94]
# });
return sprintf(q{L.%s(%s);}, $self->_method_name, $self->JSON->encode($self->options));
}
=head2 JSON
=cut
lib/Geo/Leaflet/Marker.pm view on Meta::CPAN
sub lon {
my $self = shift;
$self->{'lon'} = shift if @_;
die("Error: lon required") unless defined $self->{'lon'};
return $self->{'lon'};
}
=head2 options
=head2 popup
=head1 METHODS
=head2 stringify
=cut
sub _method_name {'marker'};
sub stringify {
my $self = shift;
my $options = $self->options;
my $value = shift;
#const object6 = L.marker([51.498,-0.09],
# {"icon":paddle_1})
# .addTo(map).bindPopup("marker icon popup").bindTooltip("marker icon tooltip");
my $class = 'marker';
my $addmap = '.addTo(map)';
my $popup = $self->popup ? sprintf('.bindPopup(%s)', $self->JSON->encode($self->popup)) : '';
my $tooltip = $self->tooltip ? sprintf('.bindTooltip(%s)', $self->JSON->encode($self->tooltip)) : '';
return sprintf(q{L.%s(%s, %s)%s%s%s;},
$class,
$self->JSON->encode([$self->lat, $self->lon]),
$self->_hash_to_json($self->options),
$addmap,
$popup,
$tooltip,
);
}
#head2 _hash_to_json
#
#Custom JSON encoder! Unfortunately, no Perl encoders support function name encoding as needed here for "icon" keys
#
#cut
lib/Geo/Leaflet/Objects.pm view on Meta::CPAN
Geo::Leaflet::Objects - Leaflet object base package
=head1 SYNOPSIS
use Geo::Leaflet;
my $map = Geo::Leaflet->new;
=head1 DESCRIPTION
This package provides a base package for L<Geo::Leaflet> map objects that supports popups and tooltips.
=head1 CONSTRUCTORS
=head2 new
=head1 PROPERTIES
=head2 options
=head2 popup
=cut
sub popup {
my $self = shift;
$self->{'popup'} = shift if @_;
return $self->{'popup'};
}
=head2 tooltip
=cut
sub tooltip {
my $self = shift;
$self->{'tooltip'} = shift if @_;
return $self->{'tooltip'};
lib/Geo/Leaflet/Polygon.pm view on Meta::CPAN
sub coordinates {
my $self = shift;
$self->{'coordinates'} = shift if @_;
die("Error: coordinates required") unless defined $self->{'coordinates'};
return $self->{'coordinates'};
}
=head2 options
=head2 popup
=head1 METHODS
=head2 stringify
=cut
sub _method_name {'polygon'};
sub stringify {
lib/Geo/Leaflet/Polyline.pm view on Meta::CPAN
=head1 DESCRIPTION
This package constructs a Leaflet polyline object for use on a L<Geo::Leaflet> map.
=head1 PROPERTIES
=head2 coordinates
=head2 options
=head2 popup
=head1 METHODS
=head2 stringify
=cut
sub _method_name {'polyline'};
=head1 SEE ALSO
lib/Geo/Leaflet/Rectangle.pm view on Meta::CPAN
sub ulon {
my $self = shift;
$self->{'ulon'} = shift if @_;
die("Error: ulon required") unless defined $self->{'ulon'};
return $self->{'ulon'};
}
=head2 options
=head2 popup
=head1 METHODS
=head2 stringify
=cut
sub _method_name {'rectangle'};
sub stringify {
t/002_html.t view on Meta::CPAN
use Data::Dumper qw{Dumper};
use Test::More tests => 9;
BEGIN { use_ok('Geo::Leaflet') };
my $map = Geo::Leaflet->new(center=>[51.505, -0.09], zoom=>13);
isa_ok($map, 'Geo::Leaflet');
my $tile = $map->tileLayer;
isa_ok($tile, 'Geo::Leaflet::TileLayer');
my $marker = $map->marker(lat=>51.5, lon=>-0.09, popup=>'marker');
diag(Dumper $marker);
isa_ok($marker, 'Geo::Leaflet::Marker');
is(scalar(@{$map->map_objects}), 1, 'sizeof objects');
my $circle = $map->circle(lat=>51.508, lon=>-0.11, radius=>500, options=>{color=>'red', fillColor=>'#f03', fillOpacity=>0.5}, popup=>'circle');
isa_ok($circle, 'Geo::Leaflet::Circle');
is(scalar(@{$map->map_objects}), 2, 'sizeof objects');
my $polygon = $map->polygon(coordinates => [[51.509, -0.08], [51.503, -0.06], [51.51, -0.047]], options=>{}, popup=>'polygon');
isa_ok($polygon, 'Geo::Leaflet::Polygon');
is(scalar(@{$map->map_objects}), 3, 'sizeof objects');
diag(Dumper($map->map_objects));
my $html = $map->html;
diag($html);
#print "\n\n####\n\n";
#print $html;
( run in 2.019 seconds using v1.01-cache-2.11-cpan-364913b4093 )