Creating map application

mad_schatz

Member
Joined
Jan 1, 2009
Messages
15
Programming Experience
1-3
Help in Drawing

Hi Gents,

I need to draw a world map. I got necessary coordinates.
I can draw it on a picturebox. To zoom in/out, I multiply the coordinates by a scale and draw them on the picturebox. At the same time I change the size of the picturebox according to scale.

Now my problem is, it seems that the picturebox has limitations in size. I can't make it bigger than 32767.

Can anyone give me some ideas, is there any way to get around this limitation ?

Thanks
 
1. Why are you drawing on a picturebox? Why not just draw it directly onto the form?

2. Use ScaleTransform instead of multiplying the coordinates all the time.
 
Hi

For my end of year project I need create a world map which I can zoom in/out, scroll from one end to another.

Fortunately I found necessary coordinates in order to draw the map. From the samples I found on the web, I put a "picturebox" in a "Panel". To zoom in/out I'm drawing my world scaling the coordinates by multiplying them. At the same time I change the size of the picture control so that I can pan it in panel control.


Until here everything was working well. My problem is after certain size, picturebox throws exception. So I can't enlarge picturebox and I can't zoom more.

May someone show me a direction :
1. How may I draw my world map and zoom as much as I can ?
2. How may I pan around when I zoom in in order to see other parts which are out of view port ?

thanks in advance
 
Hi Intertiam,

Sorry to create another thread. I did a search yesterday night in the forum but I couldn't find my last thread. Anyway :

1. Why are you drawing on a picturebox? Why not just draw it directly onto the form?

I'm drawing on a picturebox cause it is easy to pan around. In Mouse Move events, I just move the map left or top. this gives me panning effect. If I draw the map on the form, I don't think that I can do the same manipulation to have pan effect.

2. Use ScaleTransform instead of multiplying the coordinates all the time.

I'll search for tutor's or samples for ScaleTransform.

Any other ideas welcome.

Thanks,
 
I need source code this project!

You can share for me, source code your project? Beacause. I need it! Thank's. [*******].
 
Last edited by a moderator:
Dear Minhducpcvncorp

In the world and the way that grew it is not polite to ask a developer his source code.

You can ask ideas, you can share your pieces of code so that we can help you to figure out the bug but never source code.

Here you can find the link where you can have ideas how to start...
 
Thank's. Help I zoom a range on map.

I see source code from your link. This source code when zoom then zoom form. I want zoom a range on map chose by user! Help me! thank's.
 
I see source code from your link. This source code when zoom then zoom form. I want zoom a range on map chose by user! Help me! thank's.

In that example zooming done by multiplying every coordinate by the same zooming scalefactor.

X1,Y1,X2,Y2 are coordinates, pnZoom is zoomfactor :

pnZoom=10

X1=X1*pnZoom
Y1=Y1*pnZoom
X2=X2*pnZoom
Y2=Y2*pnZoom

This is not the best method,but the easiest and quick solution.
 
pnZoom=10

X1=X1*pnZoom
Y1=Y1*pnZoom
X2=X2*pnZoom
Y2=Y2*pnZoom

This is not the best method,but the easiest and quick solution.

I disagree. The easiest solution is :-

VB.NET:
With e.Graphics
  .ScaleTransform (pnZoom, pnZoom)
  .DrawLine (X1, Y1, X2, Y2)
End With

That way, you dont need to keep multiplying all your coordinates :D
 
Ok.Thank's! Howerver....

Thank you answered my question. But. If I want question about code snip in this source code. Now, I will description this source code bellow:
--// variable viewport
Private viewport As RectangleF = RectangleF.FromLTRB(-11583104.0F, -4787050.0F, -10609638.0F, -4452767.5F)
--// sub OnPaint
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
e.Graphics.Clear(Color.White)
Dim pixelAspectRatio As Single = Me.Width / Me.Height
Dim projectedAspectRatio As Single = viewport.Width / viewport.Height
Dim adjustedViewport As RectangleF = viewport
If pixelAspectRatio > projectedAspectRatio Then
adjustedViewport.Inflate((pixelAspectRatio * adjustedViewport.Height - adjustedViewport.Width) / 2, 0)
ElseIf pixelAspectRatio < projectedAspectRatio Then
adjustedViewport.Inflate(0, (adjustedViewport.Width / pixelAspectRatio - adjustedViewport.Height) / 2)
End If
transform.Reset()
transform.Translate(-adjustedViewport.X, adjustedViewport.Y, MatrixOrder.Append)
transform.Scale(Me.Width / adjustedViewport.Width, Me.Height / -adjustedViewport.Height, MatrixOrder.Append)
e.Graphics.Transform = transform
e.Graphics.FillPolygon(brush, projectedCoordinates)
e.Graphics.DrawPolygon(pen, projectedCoordinates)

End Sub
--// sub Zoom In//
Public Sub ZoomIn()
Dim zoomWidthAmount As Single = -viewport.Width * 0.1F
Dim zoomHeightAmount As String = -viewport.Height * 0.1F
viewport.Inflate(zoomWidthAmount, zoomHeightAmount)
Refresh()
End Sub
--// sub Zoom out//
Public Sub ZoomOut()
Dim zoomWidthAmount As Single = viewport.Width * 0.1F
Dim zoomHeightAmount As String = viewport.Height * 0.1F
viewport.Inflate(zoomWidthAmount, zoomHeightAmount)
Refresh()
End Sub
--// this code get from CodeProject: Writing GIS and Mapping Software for .NET. Free source code and programming help
Now, I want use mouse choose a range on this map and zoom in/out this range! Help me. :confused:
 
An Idea for You (And Thanks)

I am writing a mapping application right now, and this post helped me figure some things out, so thanks! I was using vb5 for all of my code, and am now updating to visual studio 2008. Anyway, I will be adding the same functionality that you are looking for to my code... I am just not finished yet. Conceptually (if I am understanding what you want to do correctly), you will have to use the mousedown/drag event. Next use the beginning and ending x,y coordinate pairs to create a rectangle object. Next, use a "graphics.transform(translateMatrix)" to move the center of the selected area to the center of the viewing port. Next, use a "graphics.transform(scaleMatrix)" to zoom into the map's area of interest. To determine the scale to use in the scale matrix method, compare the width and height characteristics of the rectangle object you created with the mousedown/drag event to the width and height characteristics of your viewport. I use public variables for my scale factor, my viewport center(for resize events), my global map center, and my xoffset and yoffset for panning purposes. I also create my map as a graphicspath object. I keep one unaltered copy, and one clone that I use for panning and zooming manipulation. I hope that this helped and was not confusing.
 
Back
Top