Gtk2-Ex-Geo
view release on metacpan or search on metacpan
lib/Gtk2/Ex/Geo/Overlay.pm view on Meta::CPAN
(Gtk2::Adjustment->new($self->{offset}[1], 0, $self->{canvas_size}[1], $size->[1]/20,
$size->[1], $size->[1]));
$self->signal_emit ('map-updated');
}
## @method render_geometry($gc, $geom)
# @brief Render a geometry on the overlay.
#
# @note this should be called annotate or made detect the context (gdk vs cairo)
# Call update_image after you are finished with drawing on the pixmap.
# @param gc A gdk graphics context (Gtk2::Gdk::GC object)
# @param geom A Geo::OGC::Geometry object.
sub render_geometry {
my($self, $gc, $geom, %param) = @_;
if ($geom->isa('Geo::OGC::GeometryCollection'))
{
for my $g ($geom->NumGeometries) {
$self->render_geometry($gc, $g, %param);
}
return;
}
elsif ($geom->isa('Geo::OGC::Point'))
{
my @p = $self->point2pixmap_pixel($geom->X, $geom->Y);
$self->{pixmap}->draw_line($gc, $p[0]-4, $p[1], $p[0]+4, $p[1]);
$self->{pixmap}->draw_line($gc, $p[0], $p[1]-4, $p[0], $p[1]+4);
}
elsif ($geom->isa('Geo::OGC::LineString'))
{
my @points;
for my $p ($geom->NumPoints) {
push @points, $self->point2pixmap_pixel($p->X, $p->Y);
}
$self->{pixmap}->draw_lines($gc, @points);
if ($param{enhance_vertices}) {
my $pm = $self->{pixmap};
for (my $i = 0; $i < $#points; $i+=2) {
my $x = $points[$i];
my $y = $points[$i+1];
$pm->draw_line($gc, $x-4, $y, $x+4, $y);
$pm->draw_line($gc, $x, $y-4, $x, $y+4);
}
}
}
elsif ($geom->isa('Geo::OGC::Polygon'))
{
$self->render_geometry($gc, $geom->ExteriorRing, %param);
for my $i (0..$geom->NumInteriorRing-1) {
$self->render_geometry($gc, $geom->InteriorRingN($i), %param);
}
}
}
## @method update_image($annotations, $user_param)
# @param annotations A subroutine for user annotations. Called like
# this: $annotations->($overlay, $pixmap, $gc, $user_param).
# @param user_param User parameter for the annotations.
# @brief Updates the image on the screen to show the changes in pixmap.
sub update_image {
my($self, $annotations, $user_param) = @_;
return unless $self->{pixbuf};
$self->{image}->set_from_pixbuf(undef);
$self->{pixmap} = $self->{pixbuf}->render_pixmap_and_mask(0);
my $gc = Gtk2::Gdk::GC->new($self->{pixmap});
$self->{pixmap}->draw_line($gc, 0, 0, 0, 0); # strange bug, the first line is not drawn
$self->signal_emit('pixmap_ready');
my $first = 1;
if ($self->{drawing}) {
$gc->set_rgb_fg_color(Gtk2::Gdk::Color->new(@{$self->{drawing_color}}));
my $style = 'GDK_LINE_SOLID';
$gc->set_line_attributes(2, $style, 'GDK_CAP_NOT_LAST', 'GDK_JOIN_MITER');
$self->render_geometry($gc, $self->{drawing}, enhance_vertices => 1);
}
if ($self->{selection} and $self->{show_selection}) {
$gc->set_rgb_fg_color(Gtk2::Gdk::Color->new(@{$self->{selection_color}}));
my $style = $self->{selection_style};
$style = 'GDK_LINE_SOLID';
$gc->set_line_attributes(2, $style, 'GDK_CAP_NOT_LAST', 'GDK_JOIN_MITER');
$self->render_geometry($gc, $self->{selection});
}
$annotations->($self, $self->{pixmap}, $gc, $user_param) if $annotations;
$self->{image}->set_from_pixmap($self->{pixmap}, undef);
}
## @method zoom($w_offset, $h_offset, $pixel_size)
# @brief Select a part of the world into the visible area.
sub zoom {
my($self, $w_offset, $h_offset, $pixel_size, $zoomed_in, $not_to_stack) = @_;
push @{$self->{zoom_stack}}, [@{$self->{offset}}, $self->{pixel_size}] unless $not_to_stack;
$self->{offset} = [$w_offset, $h_offset];
# sanity check
$pixel_size = 1 if $pixel_size <= 0;
$self->{pixel_size} = $pixel_size;
my $w = ($self->{maxX}-$self->{minX})/$self->{pixel_size};
my $h = ($self->{maxY}-$self->{minY})/$self->{pixel_size};
$self->{canvas_size} = [$w, $h];
$self->render();
if ($zoomed_in) {
$self->signal_emit('zoomed-in');
} else {
$self->signal_emit('extent-changed');
}
}
## @ignore
sub _zoom {
my($self, $in, $event, $center_x, $center_y, $zoomed_in) = @_;
return unless $self->{layers} and @{$self->{layers}};
my @old_offset = @{$self->{offset}};
# the center point should stay where it is unless center is defined
( run in 0.741 second using v1.01-cache-2.11-cpan-39bf76dae61 )