parent 7fa72aef52
commit a6f22d3b25
  1. 15
      HexGrid/Image.pm
  2. 17
      wiki-map.pl

@ -20,11 +20,19 @@ has id => (is => 'rw', required => 1);
has width => (is => 'rw', required => 1);
has height => (is => 'rw', required => 1);
has _cached_data => (is => 'rw', default => undef);
sub render($this, $container)
{
# hard coded into external URL mode
say STDERR $this->{_cached_data} if $DEBUG;
my $image_element = $container->image(id => $this->{id});
$image_element->{href} = $this->{fetch} ? $this->_fetch_base64() : $this->{source};
my $href = $this->{source};
if ($this->{fetch})
{
$this->_fetch_base64 unless defined($this->{_cached_data});
$href = $this->{_cached_data};
}
$image_element->{href} = $href;
$image_element->{width} = $this->{width} if defined($this->{width});
$image_element->{height} = $this->{height} if defined($this->{height});
return $image_element;
@ -37,7 +45,8 @@ sub _fetch_base64($this)
my $response = $USER_AGENT->get($this->{source});
my $content_type = $response->headers->content_type;
my $encoded_content = encode_base64($response->content);
return "data:$content_type;base64, $encoded_content";
$this->{_cached_data} = "data:$content_type;base64, $encoded_content";
return $this->{_cached_data};
}
sub DEBUG { $DEBUG = 1; }

@ -172,14 +172,24 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
# $location_with_context->add_tile($grid->get_tile_at($1, $2));
push @coords_list, { nw => $1, sw => $2 };
}
$location_grids{$location->{name}} = $grid->subgrid_for_tiles(@coords_list);
my $location_grid = $grid->subgrid_for_tiles(@coords_list);
$location_grid->iter_tile(
sub($tile)
{
# if haven't added image to grid yet, do so
if($tile->image && !(exists $location_grid->{images}{$tile->image}))
{
$location_grid->{images}{$tile->image} = $grid->{images}{$tile->image};
}
});
$location_grids{$location->{name}} = $location_grid;
}
};
}
HexGrid::Image::DEBUG();
# HexGrid::Image::DEBUG();
say STDERR "Getting Background image pages";
my $background_query_results = $mw->api({ action => 'query',
@ -314,7 +324,8 @@ if($regiondir)
foreach my $image (@{$images_for_region_grids{$region}})
{
# say STDERR Dumper($image);
$region_grid->add_image($image->{name}, $image->{source});
$region_grid->{images}{$image->{name}} = $grid->{images}{$image->{name}};
# $region_grid->add_image($image->{name}, $image->{source});
}
}

Loading…
Cancel
Save