MapWindow 4 - ActiveX Control Programming : MapWindow Discussion Forum
Hi,I like to draw a object moving on the map,My code is like this: private void button1_Click(object sender, EventArgs e) {
how to draw a moving object ?
Posted by: zsanhong ()
Date: August 23, 2009 06:06AM

Hi,I like to draw a object moving on the map,My code is like this:
  private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled =true;
            movePoint.x = 112.00;
            movePoint.y = 25.00;

             string shpfileName = Application.StartupPath + @"\myPoint.shp";

             MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile();
             sf.Open(shpfileName, null);


             axMap1.AddLayer(sf,false  );
          
         
           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            movePoint.x += 0.5;
            movePoint.y += 0.3;
           

            axMap1.DrawCircle(movePoint.x, movePoint.y, 4, (uint)RndColor(), true);
        }

but I can't see any thing on the map,what's wrong with my code? thanks a lot

Options: ReplyQuote
Re: how to draw a moving object ?
Posted by: geofran80 ()
Date: August 23, 2009 07:06AM

Friend, maybe you need use LayerDrawing using custom coordinate or spatialreference coordinates if you don't change the exact coordinates of points in your shapefile.

Francisco J.

Options: ReplyQuote
Re: how to draw a moving object ?
Posted by: zsanhong ()
Date: August 23, 2009 09:30PM

I change my code like this:
  private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled =true;
            movePoint.x = 112.00;
            movePoint.y = 25.00;

             string shpfileName = Application.StartupPath + @"\myPoint.shp";

             MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile();
             sf.Open(shpfileName, null);


             axMap1.AddLayer(sf,false  );
             axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);
          
         
           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            movePoint.x += 0.5;
            movePoint.y += 0.3;
           

            axMap1.DrawCircle(movePoint.x, movePoint.y, 4, (uint)RndColor(), true);
        }


then I see the move circle,but I want to see only one circle,how can I do?

Options: ReplyQuote
Re: how to draw a moving object ?
Posted by: bmarch ()
Date: August 23, 2009 10:20PM

Hi zsanhong,

when you draw to a drawing layer, it does not clear the previous items you draw to it. In order to do what you are want to, you need to clear the old images. Just like regular layers, drawing layers have handles.

When you call NewDrawing you must store the drawing layer handle somewhere

int drawHandle = axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);

then when your timer ticks call

axMap1.ClearDrawing(drawHandle);

first.

Brian

Options: ReplyQuote
Re: how to draw a moving object ?
Posted by: geofran80 ()
Date: August 24, 2009 12:10AM

Friend,

As comment you Brian, you need to delete the preview point.

I would make one Collection<Drawings> with actualPoint Item and PreviousPoint item, by this you can delete the previous point or drawing item using the Handle of this.

Hope it serves you.

Francisco J.

Options: ReplyQuote


Sorry, only registered users may post in this forum.





Banner Exchange




GISCP.com




Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

Just paste this text in your page: