0

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);
        }
    }

map of Berlin, panned too far to the left

1
  • 1
    As the owner of CartoType I'm happy to answer this question. It raises a genuine problem that deserves a fix. Oct 22, 2019 at 14:10

1 Answer 1

1

You can now use the function SetViewLimits:

Result CartoType.Framework.SetViewLimits(double aMinScaleDenominator,double aMaxScaleDenominator,Geometry aPanArea)

Zooming is restricted to the range between aMinScaleDenominator and aMaxScaleDenominator, and panning is restricted so that the edges of the display always touch the bounds of aPanArea.

Use the value zero to remove either or both of the two zoom limits. Use an empty (not null) geometry object to remove panning limits. Use a null geometry object to limit panning to the extent of the map.

To solve the problem given here, use the C# statement:

SetViewLimits(0,0,null);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.