package HexGrid::Pin; use Moo; use MooX::Aliases; use feature "signatures"; no warnings "experimental::signatures"; has name => (is => 'rw'); has id => (is => 'ro', required => 1); has icon => (is => 'rw', alias => [qw(img source src)], required => 1); has link => (is => 'rw', alias => 'href'); has description => (is => 'rw', alias => 'desc'); has popup => (is => 'rw', default => 1, alias => 'use_popup'); has popup_class => (is => 'rw', default => 'pin-popup'); sub render($this, $pin_container, $x, $y, $w, $h, $laters = undef) { my $group = $pin_container->g(); my $element = $group->use(href => "#$this->{icon}_symbol", x => $x, y => $y, width => $w, height => $h); $element->{id} = "$this->{id}-use"; $element->{onclick} = "clickPin('$this->{id}', '$pin_container->{id}');" if $this->popup; my $center_x = $x + $w/2; my $center_y = $y + $h/2; if(defined $laters) { push @$laters, sub ($popup_container) { $this->render_popup($popup_container, $pin_container->{transform}, $center_x, $center_y); } if $this->popup; } return $group; } sub render_popup($this, $popup_container, $transform, $x_shift, $y_shift) { my $popup_scaler = $popup_container-> g(id => "$this->{id}-popup",transform => $transform, class => $this->{popup_class})-> svg(id => "$this->{id}-scaler"); my $popup = new HexGrid::PopUp ( name => $this->{name}, description => $this->{description}, link => $this->{link} ); my $popup_element = $popup->render($popup_scaler); $popup_element->{x} = $x_shift - $popup->{origin_x}; $popup_element->{y} = $y_shift - $popup_element->{height}; } 1;