Geo-Leaflet

 view release on metacpan or  search on metacpan

lib/Geo/Leaflet.pm  view on Meta::CPAN

  $self->{'height'} = '100%' unless defined $self->{'height'};
  return $self->{'height'};
}

=head1 HTML PROPERTIES

=head2 title

Sets and returns the HTML title.

Default: "Leaflet Map"

=cut

sub title {
  my $self         = shift;
  $self->{'title'} = shift if @_;
  $self->{'title'} = 'Leaflet Map' unless defined $self->{'title'};
  return $self->{'title'};
}

=head1 TILE LAYER CONSTRUCTOR

=head2 tileLayer

Creates and returns a TileLayer object which is added to the map.

  $map->tileLayer(
                  url     => 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
                  options => {
                    maxZoom     => 19,
                    attribution => '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
                  },
                 );

  Default: OpenStreetMaps

See: L<https://leafletjs.com/reference.html#tilelayer>

=cut

sub tileLayer {
  my $self             = shift;
  $self->{'tileLayer'} = Geo::Leaflet::TileLayer->new(@_, JSON=>$self->JSON) if @_;
  $self->{'tileLayer'} = Geo::Leaflet::TileLayer->osm((), JSON=>$self->JSON) unless defined $self->{'tileLayer'};
  return $self->{'tileLayer'};
}

=head1 ICON CONSTRUCTORS

=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

sub icon {
  my $self = shift;
  my $icon = Geo::Leaflet::Icon->new(@_, JSON=>$self->JSON);
  $self->icon_objects($icon);
  return $icon;
}

=head2 divIcon

Represents a lightweight icon for markers that uses a simple `div` element instead of an image. 

Font Awesome with defaults

  my $icon = $map->divIcon(icon_name => "bicycle");

Font Awesome with tweaks

  my $icon = $map->divIcon(
                           icon_name      => "bicycle",
                           icon_font_size => 22,
                           options => {
                                       iconAnchor => [11,11],
                                      },
                          );

Other CSS options

  my $icon = $map->divIcon(
                        options => {
                                    html  => '<i class="fa fa-map-marker", style="font-size:48px"></i>',
                                    iconAnchor => [13, 44],
                                   }
                       );


See: https://leafletjs.com/reference.html#divicon

=cut

sub divIcon {
  my $self     = shift;
  my %param    = @_;
  my $icon_set = $param{'icon_set'} || 'fa'; #fa is default
  my $icon     = Geo::Leaflet::DivIcon->new(%param, JSON=>$self->JSON);
  $self->icon_sets($icon_set);
  $self->icon_objects($icon);
  return $icon;
}

=head1 MAP OBJECT CONSTRUCTORS



( run in 0.943 second using v1.01-cache-2.11-cpan-364913b4093 )