Drag map and set map bounds

Topics: Windows Forms
Sep 20, 2011 at 4:01 AM

Hi.

I use local cache.

& the cache file caches

from tile { X = 3369, Y = 1549 } to tile { X = 3375,Y = 1553 }

at zoom level 12.

 

I also calculated

topleft pointlatlng ( Lat = 40.0443061698567, Lng = 116.147632598877)

bottonright pointlatlng ( Lat = 39.8424178240922, Lng = 116.630687713623).

 

I use the code snippet in the following discussion

http://greatmaps.codeplex.com/discussions/238654

 

My code snippet.

_mainMap.BoundsOfMap = new RectLatLng?(new RectLatLng(

mapInfo.PointTopLeft.Lat,

mapInfo.PointTopLeft.Lng,

mapInfo.PointBottomRight.Lng - mapInfo.PointTopLeft.Lng,

mapInfo.PointTopLeft.Lat - mapInfo.PointBottomRight.Lat));



But when I drag the map

I got tiles which were not cached to local file shown in the map.

 

Is there a method that I can use tile to set my map's bounds?

Such as: _mainMap.SetBounds( topLeftTile( X = 3369, Y = 1549 ), bottonRightTile( X = 3375,Y = 1553 ))

Thx.

^_^

Sep 20, 2011 at 7:16 AM

whats the point?

Sep 20, 2011 at 8:36 AM
radioman wrote:

whats the point?

Thx.

Set map bounds.

 

Here is my solution code .

/// <summary>
/// BoundsOfMap
/// <param name="tileTopLeft"></param>
/// <param name="tileBottomRight"></param>
/// <param name="zoom"></param>
/// </summary>
private void SetMapBounds(GPoint tileTopLeft, GPoint tileBottomRight, int zoom)
{

    //tileTopLeft
    var gpointTopLeft = new GPoint
    {
        X = tileTopLeft.X + 2,
        Y = tileTopLeft.Y +1
    };
    var pixelTopLeft = _mainMap.MapProvider.Projection.FromTileXYToPixel(gpointTopLeft);
    pixelTopLeft.X += 128;
    pixelTopLeft.Y += 128;
    var pointTopLeft = _mainMap.MapProvider.Projection.FromPixelToLatLng(pixelTopLeft, zoom);
    //tileBottomRight
    var gpointBottomRight = new GPoint
    {
        X = tileBottomRight.X - 2,
        Y = tileBottomRight.Y - 1
    };
    var pixelBottomRight = _mainMap.MapProvider.Projection.FromTileXYToPixel(gpointBottomRight);
    pixelBottomRight.X += 128;
    pixelBottomRight.Y += 128;
    var pointBottomRight = _mainMap.MapProvider.Projection.FromPixelToLatLng(pixelBottomRight, zoom);
    //BoundsOfMap
    _mainMap.BoundsOfMap = new RectLatLng?
        (new RectLatLng(
            pointTopLeft.Lat,
            pointTopLeft.Lng,
            pointBottomRight.Lng - pointTopLeft.Lng,
            pointTopLeft.Lat - pointBottomRight.Lat));
}

^_^

Sep 20, 2011 at 8:41 AM

..i mean why do you use raw tile numbers?

Sep 20, 2011 at 8:52 AM
radioman wrote:

..i mean why do you use raw tile numbers?

Because I know I cached some data in local file

form tile { X = 3369, Y = 1549 } to tile { X = 3375,Y = 1553 }.

But I don't know location's latlng & size. 

so I can't write code like this:

_mainMap.BoundsOfMap = new RectLatLng?(new RectLatLng( ?, ?, ?));

 

I want to write like this:

var tileTopLeft = new GPoint
    {
        X = 3369,
        Y = 1549
    };
	
var tileBottomRight = new GPoint
    {
        X = 3375,
        Y = 1553
    };
	
SetMapBounds(tileTopLeft, tileBottomRight, 12)

Thx radioman.