It turns out that MapCenterChanged not being called was because I handle the OnMouseUp event as well in my code and change the ActiveTool to DrawPoint in this. The OnMouseUp event is fired by the MapBox before handling the map move and firing the MapCenterChanged
event, which only fires if the ActiveTool is Pan.
I changed my code to not use the DrawPoint tool and just keep Pan as the ActiveTool and now I get the MapCenterChanged event.
So the resulting code to stop the MapBox being scrolled beyond the maximum extents of the map is below. I also had to specify the maximum and minimum zoom levels of the map based on the available resolutions from the tile schema.
Coordinate m_lastMapCenter = null;
private void mapBox1_MapCenterChanged(Coordinate center)
Envelope mapExtents = mapBox1.Map.GetExtents();
Rectangle bounds = mapBox1.Bounds;
Coordinate tl = mapBox1.Map.ImageToWorld(new PointF(bounds.Left, bounds.Top), true);
Coordinate br = mapBox1.Map.ImageToWorld(new PointF(bounds.Right, bounds.Bottom), true);
// If the visible area is off the end of the map then revert to the previous position.
tl.X < mapExtents.Left() ||
br.X > mapExtents.Right() ||
tl.Y > mapExtents.Top() ||
br.Y < mapExtents.Bottom()
if (tl.X < mapExtents.Left() && br.X > mapExtents.Right())
// Centre the map if we are fully zoomed out.
mapBox1.Map.Center = mapExtents.Centre;
center = mapExtents.Centre;
else if (m_lastMapCenter != null)
mapBox1.Map.Center = m_lastMapCenter;
center = m_lastMapCenter;
m_lastMapCenter = center;