in reply to Re^4: geoTiff Application Building
in thread geoTiff Application Building

I mentioned in the previous post, that "pixel zooming" is tricky to handle....it is only a "screen illusion" where the screen pixels are magnfied. Also you must be aware of the "center point of zoom"... it will default to (0,0) ... the upper left corner(accounting for the right-downward shift when zooming). Read perldoc Gnome2::Canvas and search for zoom. Also look at window-to-world and c2w.

I don't have an example handy, and you might want to ask on the Perl/Gtk2 maillist.

Before you get too deep into the Gnome2::Canvas, you may want to switch to the Goo::Canvas because it will save better. You can save the whole canvas as svg. Also it's demo shows how to change the center-point of zooming by setting the anchor, ( I don't know if it will work on Gnome2::Canvas)


I'm not really a human, but I play one on earth CandyGram for Mongo

Replies are listed 'Best First'.
Re^6: geoTiff Application Building
by deadpickle (Pilgrim) on Jun 01, 2008 at 21:17 UTC
    I C. Its good to know for future development but right now neither saving or zooming are that important right now. Right now I have it so that the user can click and hold to pan, double click to add a waypoint, and when the waypoints are more than one they are connected by a line in sequence. But there are a few more things to do. Right now when there are three waypoints, a line connecting points 1 and 3 making it a circuit but when you add a fourth the previous line stays and then you get two circuits. Its hard to explain so you can get a screenshot here . The line from 3 to 1 should not be there. Any ideas on how to stop this from happening? Also I want the user to be able to remove the waypoints. Is it possible to drop the lines and waypoints into a hash and have canvas draw them after every event? This allows me to manipulate the objects with ease.
    sub event_handler { my ( $widget, $event ) = @_; # print $widget ,' ',$event->type,"\n"; #on 2 mouse presses, place waypoint if ( $event->type eq "2button-press" ) { print 'x->',$event->x,' ','y->',$event->y; #convert UTM to Lat and Long my $easting = $ps[0] * $event->x + 0.0 * $event->y + $mtp[3]; my $northing = (-$ps[1]) * $event->y + 0.0 * $event->x + $mtp[ +4]; my ($latitude,$longitude)=utm_to_latlon($ellipsoid,$zone,$east +ing,$northing); print " ($latitude, $longitude)\n"; #Drop icon my $tgroup = Gnome2::Canvas::Item->new ($root, 'Gnome2::Canvas +::Group', x => $event->x, y => $event->y); Gnome2::Canvas::Item->new($tgroup, 'Gnome2::Canvas::Ellipse', x1 => -7.5, y1 => -7.5, x2 => 7.5, y2 => 7.5, fill_color => 'purple', outline_color => 'black'); Gnome2::Canvas::Item->new ($tgroup, 'Gnome2::Canvas::Text', "text", "$count", "x", 0.0, "y", 0.0, "font", "Sans Bold", "anchor", 'GTK_ANCHOR_NW', "weight", 100, "fill_color", 'red', "size_points", 20); #add waypoints $waypoints{$count } = {'x' => $event->x,'y' => $event->y, 'lat +' => $latitude, 'long' => $longitude}; print "size of hash: " . keys( %waypoints ) . ".\n"; #foreach my $num (sort keys %waypoints){ # print "$num = $waypoints{$num}\n"; # foreach my $subkey (sort keys %{$waypoints{$num}}){ # print "$subkey = $waypoints{$num}{$subkey}\n"; # } #} #draw lines to the waypoints if ($count >= 2){ my @points; foreach my $key (sort keys %waypoints){ foreach my $subkey (sort keys %{$waypoints{$key}}){ if ($subkey eq 'x' || $subkey eq 'y'){ push(@points, $waypoints{$key}{$subkey}); print "$key $subkey = $waypoints{$key}{$subkey +}\n"; } } } if ($count >= 3){ push(@points, $waypoints{1}{'x'}); push(@points, $waypoints{1}{'y'}); } my $lgroup = Gnome2::Canvas::Item->new ($root, 'Gnome2::Ca +nvas::Group'); Gnome2::Canvas::Item->new ($lgroup, 'Gnome2::Canvas::Line', points => [@points], fill_color => 'black', width_units => 4.0); foreach (@points){ print $_, "\n"; } } #print $count, "\n"; $tgroup->raise_to_top(); $count++; } }
      UPDATE 6/3/2008 ..... I found the mouse position error, It was caused by the scrollregion being made smaller than the default canvas size!! See fixed code below.

      I'm not sure on the best way to filter out the extra line segment, it seems like a college level math problem, but the first thing that comes to mind is to just make a single line with multiple points. That way you just push the new waypoint onto the points for the line. Each waypath is just a single line with multiple points. This is just a simple example, but should show the idea. Like you, I can't get the mouse coordinates to line up. I'm totally confused on it and will ask on the maillist. It has something to do with groups and centering.

      #!/usr/bin/perl use warnings; use strict; use Gtk2 -init; use Gnome2::Canvas; my $window = Gtk2::Window->new; $window->signal_connect( destroy => sub { exit } ); my $scroller = Gtk2::ScrolledWindow->new; my $canvas = Gnome2::Canvas->new(); $scroller->add( $canvas ); $window->add( $scroller ); $window->set_default_size( 500, 500 ); # if scrollregion is smaller than default_size, a weird # coordinate transform occurs # $canvas->set_scroll_region( 0, 0, 400, 400 ); # bad $canvas->set_scroll_region( 0, 0, 700, 700 ); # works good $window->show_all; my $root = $canvas->root; # a stupid hack to try and compensate for bad scrollregion ;-( #$root->move(-50,-50); # dumb my $text = Gnome2::Canvas::Item->new( $root, 'Gnome2::Canvas::Text', x => 20, y => 15, fill_color => 'black', font => 'Sans 14', anchor => 'GTK_ANCHOR_NW', text => 'Click to add waypoint' ); $canvas->signal_connect (event => \&event_handler); my $points = [0,0,100,100]; my $line2= Gnome2::Canvas::Item->new ($root, 'Gnome2::Canvas::Line', points => $points, fill_color => "red", width_units => 3.0, cap_style => 'projecting', join_style => 'miter', ); my $p = $line2->get('points'); print "@$p\n"; my ($x,$y) = @$p; Gtk2->main; ############################## sub event_handler{ my ( $widget, $event ) = @_; # print $widget ,' ',$event->type,"\n"; if ( $event->type eq "button-press" ) { print 'x->',$event->x,' ','y->',$event->y,"\n"; push @$points,$event->x , $event->y; $line2->set(points=>$points); my $p = $line2->get('points'); print "@$p\n"; } } __END__

      I'm not really a human, but I play one on earth CandyGram for Mongo
        UPDATE.... see fix above.....it just goes to show how one stupid sizing error can lead to multiple corrective hacks :-)

        It has something to do with groups and centering.

        It seems to be more than that, it also has something to do with the scrollregion. If I adjust the scrollregion, it seems to work, but as to why? I'm still experimenting. :-) Moving the canvas -50 -50 still is a complete mystery. It must be something so obvious, that I'm completely missing it.

        $canvas->set_scroll_region( -20, -20, 400, 400 );

        I'm not really a human, but I play one on earth CandyGram for Mongo