Compare commits

...

2 Commits

  1. 28
      HexGrid.pm
  2. 27
      HexGrid/Image.pm
  3. 7
      HexGrid/PopUp.pm
  4. 4
      HexGrid/Tile.pm
  5. 3
      wiki-map.pl

@ -9,6 +9,7 @@ use Hash::Merge qw(merge);
use HexGrid::Tile;
use HexGrid::Region;
use HexGrid::PopUp;
use HexGrid::Image;
use Carp;
use Data::Dumper;
@ -16,6 +17,8 @@ use feature "signatures";
no warnings "experimental::signatures";
has regions => (is => 'rw', default => sub { {} });
has images => (is => 'rw', default => sub{ {} });
has sideLength => (is => 'rw', default => 100);
has width => (is => 'rw', default => 1000);
has height => (is => 'rw', default => 1000);
@ -36,6 +39,19 @@ sub make_region($this, $name, %defaults)
$this->add_region(HexGrid::Region->new(name => $name, defaults => $tile_defaults));
}
sub add_image($this, $name, $source)
{
# Height/width of the image within the symbol doesn't matter
# it will be scaled on use by matching the symbol viewbox to the declared image dimensions
$this->{images}{$name} = HexGrid::Image->new
(
source => $source,
id => "${name}_img",
width => 1,
height => 1
);
}
sub get_tile_at($this, $nw, $sw)
{
foreach my $region (keys $this->{regions}->%*)
@ -54,6 +70,18 @@ sub render($this)
$style_text .= ".$this->{popup_class} { visibility: hidden; }" if $this->{hidden_popups};
$root_style->cdata($style_text);
my $defs = $svg->defs();
while (my ($key, $image) = each %{$this->{images}})
{
my $symbol = $defs->symbol
(
id => "${key}_symbol",
viewBox => "0 0 $image->{width} $image->{height}",
width => $image->{width},
height => $image->{height});
$image->render($symbol);
}
my $laters = [];
foreach my $region (keys %{$this->{regions}})
{

@ -0,0 +1,27 @@
package HexGrid::Image;
use v5.30;
use Moo;
use MooX::Aliases;
use feature "signatures";
no warnings "experimental::signatures";
has source => (is => 'rw', required => 1, alias => [qw(src url source_url)]);
has fetch => (is => 'rw', default => 0);
has id => (is => 'rw', required => 1);
has width => (is => 'rw', required => 1);
has height => (is => 'rw', required => 1);
sub render($this, $container)
{
# hard coded into external URL mode
my $image_element = $container->image(id => $this->{id}, href => $this->{source});
$image_element->{width} = $this->{width} if defined($this->{width});
$image_element->{height} = $this->{height} if defined($this->{height});
return $image_element;
}
1;

@ -19,6 +19,7 @@ has gap_width => (is => 'rw', default => 40);
has name => (is => 'rw');
has link => (is => 'rw', alias => 'href');
has description => (is => 'rw', alias => 'desc');
has 'font-size' => (is => 'rw', default => '2.5em');
has margin => (is => 'rw', default => 20);
has 'stroke-width' => (is => 'rw', default => 2);
@ -47,7 +48,7 @@ sub render($this, $scaler)
my $path = $scaler->path(d => $path_string, stroke => 'black', fill => 'white', 'stroke-width' => $t{'stroke-width'});
my $content_container = $scaler->g(transform => "translate($t{margin},$t{margin})");
my $obj = $content_container->foreignObject(width => ($t{width} - 2*$t{margin}), height => $box_height - 2*$t{margin});
basic_popup($obj, $t{name}, $t{description}, $t{link});
basic_popup($obj, $t{name}, $t{description}, $t{link}, $t{'font-size'});
return $scaler;
}
@ -59,9 +60,9 @@ sub _a { " a $_[0],$_[1] $_[2] $_[3] $_[4] $_[5],$_[6]"; }
# Split this out
sub basic_popup($obj, $name, $description, $link)
sub basic_popup($obj, $name, $description, $link, $font_size)
{
my $div = $obj->tag('div', xmlns => "http://www.w3.org/1999/xhtml");
my $div = $obj->tag('div', style => "font-size: $font_size;", xmlns => "http://www.w3.org/1999/xhtml");
$div->tag('h3', style => 'margin-top: 0; margin-left: 0;')->tag('a', href => $link)->cdata($name);
foreach (split /\n/, $description)
{

@ -116,8 +116,8 @@ sub render($this, $container, $width, $height, $laters = undef)
$this->{images} = [$this->{images}] if ref($this->{images}) ne 'ARRAY';
foreach my $image ($this->{images}->@*)
{
my $image_element = $g->image(id => "$this->{nw}_$this->{sw}_${image}_img",
href => $image, width => $width, height => $height,
my $use_element = $g->use(id => "$this->{nw}_$this->{sw}_${image}_use",
href => "#${image}_symbol", width => $width, height => $height,
"clip-path" => "url(#$clipPath->{id})");
}
}

@ -203,9 +203,10 @@ foreach my $page (values %{$background_query_results->{query}{pages}})
if($page->{imageinfo})
{
say STDERR "Processing image: $page->{title}";
$grid->add_image(HexGrid::to_id($page->{title}), $page->{imageinfo}[0]{url});
foreach my $region (@{$background_pages{$page->{title}}})
{
$region->{defaults}{image} = $page->{imageinfo}[0]{url};
$region->{defaults}{image} = HexGrid::to_id($page->{title});
}
}
}

Loading…
Cancel
Save