I am working with the .NET CartoType SDK on Windows.
How can I restrict panning?
In the "Windows Maps" app I am able to pan outside of the map boundaries. I would like to prevent this.
The C# demo program supplied with CartoType contains this code to pan the map in response to a mouse drag event, and I've added the code starting with the comment "clamp view to extent of map", but the map is still panned too far. The aim is to prevent any edge of the display going beyond the edge of the map.
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
m_map_drag_offset_x = e.X - m_map_drag_anchor_x;
m_map_drag_offset_y = e.Y - m_map_drag_anchor_y;
if (m_graphics_acceleration)
{
m_framework.Pan(-m_map_drag_offset_x, -m_map_drag_offset_y);
m_map_drag_offset_x = 0;
m_map_drag_offset_y = 0;
m_map_drag_anchor_x = e.X;
m_map_drag_anchor_y = e.Y;
// clamp view to extent of map
var state = m_framework.GetViewState();
var map_extent = new CartoType.Rect();
m_framework.GetMapExtent(map_extent, CartoType.CoordType.Degree);
var x = state.m_view_center_degrees_x;
var y = state.m_view_center_degrees_y;
if (x < map_extent.MinX)
x = map_extent.MinX;
else if (x > map_extent.MaxX)
x = map_extent.MaxX;
if (y < map_extent.MinY)
y = map_extent.MinY;
else if (y > map_extent.MaxY)
y = map_extent.MaxY;
m_framework.SetViewCenter(x, y, CartoType.CoordType.Degree);
}
else
Draw(m_map_drag_graphics);
}
}