parent 1804bf04f4
commit f6d0afa029
  1. 25
      HexGrid.pm
  2. 7
      HexGrid/Pin.pm
  3. 4
      HexGrid/Tile.pm
  4. 19
      wiki-map.pl

@ -65,6 +65,30 @@ sub get_tile_at($this, $nw, $sw)
croak "No tile at $nw,$sw"; croak "No tile at $nw,$sw";
} }
# Clones basic settings
# Grid defaults and regions (and by extension tiles) are tied to $this
sub subgrid_for_regions($this, @region_names)
{
my $subgrid = HexGrid->new
(
sideLength => $this->{sideLength},
width => $this->{width},
height => $this->{height},
defaults => $this->{defaults},
make_popups => $this->{make_popups},
popup_class => $this->{popup_class},
hidden_popups => $this->{hidden_popups},
embed_images => $this->{embed_images}
);
$subgrid->add_region($this->{regions}{$_}) for @region_names;
say STDERR Dumper($subgrid) if $DEBUG;
return $subgrid;
}
sub subgrid_for_tiles($this, @coords)
{
}
sub render($this) sub render($this)
{ {
my ($min_x,$min_y,$max_x,$max_y) = qw(Inf Inf -Inf -Inf); my ($min_x,$min_y,$max_x,$max_y) = qw(Inf Inf -Inf -Inf);
@ -120,4 +144,5 @@ sub translate_coords($this, $nw, $sw)
sub to_id($string) { $string =~ s/\W/-/g && return $string; } sub to_id($string) { $string =~ s/\W/-/g && return $string; }
sub DEBUG { $DEBUG = 1; }
1; 1;

@ -16,9 +16,10 @@ has popup_class => (is => 'rw', default => 'pin-popup');
sub render($this, $pin_container, $x, $y, $w, $h, $laters = undef) sub render($this, $pin_container, $x, $y, $w, $h, $laters = undef)
{ {
my $element = $pin_container->image(href => $this->{icon}, my $group = $pin_container->g();
my $element = $group->use(href => "#$this->{icon}_symbol",
x => $x, y => $y, width => $w, height => $h); x => $x, y => $y, width => $w, height => $h);
$element->{id} = "$this->{id}-img"; $element->{id} = "$this->{id}-use";
$element->{onclick} = "clickPin('$this->{id}', '$pin_container->{id}');"; $element->{onclick} = "clickPin('$this->{id}', '$pin_container->{id}');";
my $center_x = $x + $w/2; my $center_x = $x + $w/2;
my $center_y = $y + $h/2; my $center_y = $y + $h/2;
@ -28,7 +29,7 @@ sub render($this, $pin_container, $x, $y, $w, $h, $laters = undef)
push @$laters, sub ($popup_container) { $this->render_popup($popup_container, push @$laters, sub ($popup_container) { $this->render_popup($popup_container,
$pin_container->{transform}, $center_x, $center_y); }; $pin_container->{transform}, $center_x, $center_y); };
} }
return $element; return $group;
} }
sub render_popup($this, $popup_container, $transform, $x_shift, $y_shift) sub render_popup($this, $popup_container, $transform, $x_shift, $y_shift)

@ -140,8 +140,8 @@ sub render($this, $container, $width, $height, $laters = undef)
my $y = $height * $docks{$key}->{y}; my $y = $height * $docks{$key}->{y};
my $h = $height * $docks{$key}->{h}; my $h = $height * $docks{$key}->{h};
my $image_element = $this->{pins}{$key}->render($g, $x, $y, $w, $h, $laters); my $pin_element = $this->{pins}{$key}->render($g, $x, $y, $w, $h, $laters);
$image_element->{"clip-path"} = "url(#$clipPath->{id})"; $pin_element->{"clip-path"} = "url(#$clipPath->{id})";
} }
} }
return $g; return $g;

@ -291,12 +291,13 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
}) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details}; }) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details};
my %image_pages = %{$imageinfo_query_results->{query}{pages}}; my %image_pages = %{$imageinfo_query_results->{query}{pages}};
my $image_url = (values %image_pages)[0]{imageinfo}[0]{url}; my $image_url = (values %image_pages)[0]{imageinfo}[0]{url};
$grid->add_image(HexGrid::to_id($parsed_template->{named_params}{icon}), $image_url);
my $pin = HexGrid::Pin->new my $pin = HexGrid::Pin->new
( (
name => $site_name, name => $site_name,
id => "${site_name}_pin", id => HexGrid::to_id($site_name),
icon => $image_url, icon => HexGrid::to_id($parsed_template->{named_params}{icon}),
link => $site_url, link => $site_url,
description => $parsed_template->{named_params}{abstract} description => $parsed_template->{named_params}{abstract}
); );
@ -321,6 +322,20 @@ if($regiondir)
} }
} }
### Subgrid testing
HexGrid::DEBUG();
my $subgrid = $grid->subgrid_for_regions("Midhills", "Minev's Forest", "Naurardhon");
my $svg = $subgrid->render;
open SUBGRID, ">subgrid_test.svg";
say SUBGRID $svg;
close SUBGRID;
###
sub wrap_in_html($grid) sub wrap_in_html($grid)
{ {
my $html_builder = "<!DOCTYPE html>"; my $html_builder = "<!DOCTYPE html>";

Loading…
Cancel
Save