Limit navigable map area

Topics: Help, Windows Forms
Dec 16, 2010 at 5:34 PM

Hi radioman,


First of all thanks for releasing this great job. You are the master.

In second place, I need to limit to the user the navigable area. To reach this point I've tryed to handle some events like OnCurrentPositionChanged and OnMapDrag but unsuccessfully.Here's a snipet:

void mapctrl1_OnCurrentPositionChanged(PointLatLng point)
{
PointLatLng boundadj = point;// mapctrl1.Position;
if (boundadj.Lat > latmax) boundadj.Lat = latmax;
else if (boundadj.Lat < latmin) boundadj.Lat = latmin;
if (boundadj.Lng > lngmax) boundadj.Lng = lngmax;
else if (boundadj.Lng < lngmin) boundadj.Lng = lngmin;
if (boundadj.Lat != point.Lat || boundadj.Lng != point.Lng) mapctrl1.Position = boundadj;
}


Is there any function, method or way to get my goal? 


Thanks,


marranxo

Dec 16, 2010 at 7:59 PM

Hi,

I'm interested in the same topic.

 

 

Thanks.

Coordinator
Dec 16, 2010 at 8:43 PM

check property BoundsOfMap

Dec 17, 2010 at 8:31 AM

Hi radioman,

I've set the bounds in BoundsOfMap as you suggested but now I can't drag the map in deeper zoom levels inside the trusted area. Is this the default behavior or it's my fault?

In the case it's the default behavior, is there any way to change it to allow map dragging inside bounds?

latcur = latmin + (latmax - latmin) / 2;
lngcur = lngmin + (lngmax - lngmin) / 2;
mapctrl1.Position = new PointLatLng(latcur, lngcur);
mapctrl1.BoundsOfMap = new RectLatLng(latmin, lngmin, latmax - latmin, lngmax - lngmin);
mapctrl1.CanDragMap = true;

Thanks,

marranxo

Dec 21, 2010 at 8:55 AM

I have checked that the BoundsOfMap work on my project

here is my code snippet

double minLat = 22.13;
double maxLat = 22.53;
double minLng = 113.80;
double maxLng = 114.42;
this.MainMap.BoundsOfMap = new RectLatLng?(new RectLatLng(maxLat, minLng, maxLng- minLng, maxLat - minLat));

You can use BoundsOfMap.Value.Contains() function in MapDrag event to check the PointLatLng inside the region you want to limit.

Dec 21, 2010 at 10:44 AM
Edited Dec 21, 2010 at 10:57 AM

Sorry It was my fault. I was coding like the area delimited by RectLatLng would be a rectangle based in the bottom left corner and it seems it's a rectangle based in the top left corner. Thanks for your time and sorry again.

Oct 23, 2013 at 11:02 AM
cyrilhl wrote:
I have checked that the BoundsOfMap work on my project here is my code snippet double minLat = 22.13; double maxLat = 22.53; double minLng = 113.80; double maxLng = 114.42; this.MainMap.BoundsOfMap = new RectLatLng?(new RectLatLng(maxLat, minLng, maxLng- minLng, maxLat - minLat)); You can use BoundsOfMap.Value.Contains() function in MapDrag event to check the PointLatLng inside the region you want to limit.
Why this dont work for me? Im going bananas...
    Public Property MapBoundsLatMin As Double = -9.1

    Public Property MapBoundsLatMax As Double = -30.1

    Public Property MapBoundsLngMin As Double = 135.8

    Public Property MapBoundsLngMax As Double = 155.9
    
    Me.Map.BoundsOfMap = New RectLatLng(Me.MapSettings.MapBoundsLatMin,
                                                Me.MapSettings.MapBoundsLngMin,
                                                Math.Abs(Me.MapSettings.MapBoundsLatMax - Me.MapSettings.MapBoundsLatMin),
                                                Math.Abs(Me.MapSettings.MapBoundsLngMax - Me.MapSettings.MapBoundsLngMin))
Using version: greatmaps-a158dfe4e6a8.zip

Any help appreciated...