HTML-GoogleMaps-V3

 view release on metacpan or  search on metacpan

lib/HTML/GoogleMaps/V3.pm  view on Meta::CPAN

=item $map->zoom($level)

Set the new zoom level (0 is corsest)

=cut

=item $map->dragging($enable)

Enable or disable dragging.

=cut

=item $map->info_window($enable)

Enable or disable info windows.

=cut

=item $map->map_id($id)

Set the id of the map div

=cut

sub add_icon    { 1; }
sub controls    { 1; }
sub dragging    { $_[0]->{dragging}    = $_[1]; }
sub info_window { $_[0]->{info_window} = $_[1]; }
sub map_id      { $_[0]->{id}          = $_[1]; }
sub zoom        { $_[0]->{zoom}        = $_[1]; }
sub v2_zoom     { $_[0]->{zoom}        = $_[1]; }

=item $map->map_type($type)

Set the map type. Either B<normal>, B<satellite>, B<road>, or B<hybrid>.

=cut

sub map_type {
    my ( $self,$type ) = @_;

    $type = {
        normal         => 'NORMAL',
        map_type       => 'NORMAL',
        satellite_type => 'SATELLITE',
        satellite      => 'SATELLITE',
        hybrid         => 'HYBRID',
        road           => 'ROADMAP',
    }->{ $type } || return 0;

    $self->{type} = $type;
}

=item $map->add_marker(point => $point, html => $info_window_html)

Add a marker to the map at the given point. A point can be a unique
place name, like an address, or a pair of coordinates passed in as
an arrayref: [ longitude, latitude ]. Will return 0 if the point
is not found and 1 on success.

If B<html> is specified, add a popup info window as well.

=cut

sub add_marker {
    my ( $self,%opts ) = @_;

    my $point = $self->_text_to_point($opts{point})
        || return 0;

    push( @{$self->{points}}, {
        point  => $point,
        html   => $opts{html},
        format => !$opts{noformat}
    } );
}

=item $map->add_polyline(points => [ $point1, $point2 ])

Add a polyline that connects the list of points. Other options
include B<color> (any valid HTML color), B<weight> (line width in
pixels) and B<opacity> (between 0 and 1). Will return 0 if the points
are not found and 1 on success.

=cut

sub add_polyline {
    my ( $self,%opts ) = @_;

    my @points = map { $self->_text_to_point($_) } @{$opts{points}};
        return 0 if grep { !$_ } @points;

    push( @{$self->{poly_lines}}, {
        points  => \@points,
        color   => $opts{color} || "\#0000ff",
        weight  => $opts{weight} || 5,
        opacity => $opts{opacity} || .5 }
    );
}

sub _js_template {

    my $template =<<"EndOfTemplate";

function html_googlemaps_initialize() {

    [% # Github issue 22 %]
    [% IF center %]
	myCenterLatLng = new google.maps.LatLng({lat: [% center.0 %], lng: [% center.1 %]});
    [% END %]

    // key map controls
    var map = new google.maps.Map(document.getElementById('[% id %]'), {
        mapTypeId: google.maps.MapTypeId.[% type %],
        [% IF center %]center: myCenterLatLng,[% END %]
        scrollwheel: false,
        zoom: [% zoom %],
        draggable: [% dragging ? 'true' : 'false' %]
    });

    [% FOREACH point IN points %]



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