6 images in tile format(google maps)

Discussion in 'Perl Misc' started by Dwayne Triffitt, Oct 21, 2009.

  1. I want to know if there is a quicker way to add a Image into a frame
    and tile it with others

    eg perl.tk can add an image and i can set frames one by one, but the
    code for the program is getting WAY!!!! to big (150 x 150 eg 5 km
    square - i need 9 km square),

    And with my code added to it, the program is all over the place and i
    have over 1000 lines of code, i cant keep trace of......

    Also on a foot note, can Serial be added to perl? can i read/write to
    serial in perl and display its data in a label/text in perl.tk ??????
     
    Dwayne Triffitt, Oct 21, 2009
    #1
    1. Advertising

  2. Dwayne Triffitt

    smallpond Guest

    On Oct 21, 4:26 pm, Dwayne Triffitt <> wrote:
    > I want to know if there is a quicker way to add a Image into a frame
    > and tile it with others
    >


    Might be easier to tile multiple images on a canvas.


    > eg perl.tk can add an image and i can set frames one by one, but the
    > code for the program is getting WAY!!!! to big (150 x 150 eg 5 km
    > square  - i need 9 km square),
    >
    > And with my code added to it, the program is all over the place and i
    > have over 1000 lines of code, i cant keep trace of......
    >


    The number of images should not affect the code size. Why
    do you need 1000 lines of code? You just loop through all
    of your (visible) images adding them to the display.


    > Also on a foot note, can Serial be added to perl? can i read/write to
    > serial in perl and display its data in a label/text in perl.tk ??????


    It's bad form to put two unrelated questions in one usenet post.
    Maybe this is why your code is undisciplined, too?
    The answer is "Sure. Why not?"
     
    smallpond, Oct 21, 2009
    #2
    1. Advertising

  3. just a small recap on the progress i have made,
    If anyones looking for the code that is

    #!/usr/local/bin/perl -w
    use Tk; #<< NEED THIS
    use Tk::widgets qw/JPEG PNG/; #<< NEED THIS FOR PNG IMAGES
    use strict;
    use warnings;

    ##start with a new window##

    my $mw = MainWindow->new();
    $mw->geometry("768x640");
    $mw->title(" Tasdawg Window Tk v0.01");

    ##add icon(marker) and first tile(map)

    my $icon = $mw->Photo(-file=>'marker.png');
    my $tile1 = $mw->Photo(-file=>'1/1.png');

    ##Create the canvas to draw these too.

    my $c1 = $mw->Canvas(-width => 768, -height => 768,
    #-tile => $tile, # tile one image to the background(maybe
    add all images togeather?)
    -relief => 'sunken',
    );
    $c1->pack(-side => 'left');

    ##now create the image on the canvas

    $c1->createImage(128, 128, -image => $tile1);

    ## using button 1 to add marker to the image canvas

    $mw->Tk::bind("<ButtonPress-1>", [\&pimg, Ev('x'), Ev('y') ]);

    ##the sub function for the button being pressed

    MainLoop;

    sub pimg {

    my ($canv, $x, $y) = @_;
    my $x1 = $canv->canvasx($x);
    my $y1 = $canv->canvasx($y);
    # print "$x1 $y1\n";

    #$c1->pack(-side => 'left');
    $c1->createImage($x1, $y1, -image => $icon, -tags =>
    ['move']);

    $current = $c1;
    }

    ##p.s This code wont work - it is only a snippet from my code, that
    has a lot more in it.

    But thats the basic's

    Now to tile an image see this line

    $c1->createImage(128, 128, -image => $tile1);

    for every 128,128 is the pixal Y axis and X axis
    adding a second image u go like this

    $c1->createImage(128, 384, -image => $tile2);

    b-cos my images are 256x256 i have to come down 128 pixals at first
    and then plus the image and get 384
    here is a "768x640" tile'd map - all images displayed the same 3x3
    map.

    $c1->createImage(128, 128, -image => $tile1);
    $c1->createImage(128, 384, -image => $tile2);
    $c1->createImage(128, 640, -image => $tile3);

    $c1->createImage(384, 128, -image => $tile4);
    $c1->createImage(384, 384, -image => $tile5);
    $c1->createImage(384, 640, -image => $tile6);

    $c1->createImage(640, 128, -image => $tile4);
    $c1->createImage(640, 384, -image => $tile5);
    $c1->createImage(640, 640, -image => $tile6);

    Easy as that - will post again on the improvement of not defining
    images and getting them from the directory as and making each 3 images
    go down in column's moving to next 3 images and then again for last 3
    images. making total of 9 images in the canvas. also going to add a
    pixal to LAT LON if anyone is interested in that.
     
    Dwayne Triffitt, Oct 25, 2009
    #3
  4. Tad McClellan -
    Before 2 weeks ago - i did not know one line about perl.
    I am starting off and learning line by line... i add something, check
    it, read warning/error...
    fix error .....
    Move on .....
    So on .....
    Thanks for the insight's

    Onto the code....

    When adding multi images to the widget i have to assign them a -tag,
    every 'marker' is called more, no hick-up
    But i plan to make them as way-points, so each 'marker' needs its own
    name/number. so here it is to add a name and to get the name.

    my $name = 1;

    ##On button-2 - create 'marker'
    sub create_item {
    my ($c1, $x, $y, $name) = @_;

    my $ev = $c1->XEvent;
    ($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
    \&pimg, Ev('x'), Ev('y');
    }

    ##On button-1 - Get name then move to 'Moving'
    sub get_name {
    my ($c1) = @_;
    my $item = $c1->find('withtag', 'current');
    my @taglist = $c1->gettags($item);
    my $name;
    foreach (@taglist) {
    next if ($_ eq 'current');
    $name = $_;
    last;
    }
    return $name;
    }

    sub mobileStart {
    my $ev = $c1->XEvent;
    ($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
    $c1->raise('move');
    $listbox->insert('end', "Start $dx $dy");
    $xworldst = $dx;
    $yworldst = $dy;

    }

    sub mobileMove {
    my $ev = $c1->XEvent;
    $c1->move('current', $ev->x + $dx, $ev-> y + $dy);
    ($dx, $dy) = (0 - $ev-> x, 0 - $ev-> y);
    $listbox->insert('end', "");
    $listbox->delete('end');

    $listbox->insert('end', "Moving $dx $dy");
    $listbox->delete('end');

    }

    sub pimg {

    my ($canv, $x, $y) = @_;
    my $x1 = $canv->canvasx($x);
    my $y1 = $canv->canvasx($y);
    # print "$x1 $y1\n";

    #$c1->pack(-side => 'left');
    $c1->createImage($x1, $y1, -image => $icon, -tags =>
    ['move']);

    $listbox->insert('end', " Input $x1 $y1");
    $pre->insert('end', "$x1 $y1");

    $current = $c1;
    }

    More to come.
     
    Dwayne Triffitt, Oct 27, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    2,037
    Jeffrey Schwab
    Nov 28, 2005
  2. Simon Elliott
    Replies:
    4
    Views:
    1,168
    Simon Elliott
    Mar 10, 2005
  3. Marcus
    Replies:
    2
    Views:
    592
    Marcus
    Dec 9, 2005
  4. Replies:
    0
    Views:
    493
  5. How Google Maps loads images

    , Feb 22, 2006, in forum: Javascript
    Replies:
    5
    Views:
    96
    Jonas Raoni
    Feb 24, 2006
Loading...

Share This Page