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++;
}
}
|