Hi jhyap,
map zooming is a little bit more difficult to limit than regular XY chart.
Do it like this:
Disable built-in mouse wheel zooming feature:
Code: Select all
m_chart.ViewXY.ZoomPanOptions.MouseWheelZooming = MouseWheelZooming.Off;
Create event handler for chart.MouseWheel:
Code: Select all
m_chart.MouseWheel += new MouseEventHandler(m_chart_MouseWheel);
And the event handler itself, here I've set X axis limit of -180 ... 180, or 360 in total in panned view.
Code: Select all
void m_chart_MouseWheel(object sender, MouseEventArgs e)
{
if(m_chart.ViewXY.XAxes[0].Maximum - m_chart.ViewXY.XAxes[0].Minimum < 360 || e.Delta > 0)
{
m_chart.BeginUpdate();
if (e.Delta > 0)
{
//Zoom in, factor over 1
//double dFactor = 1.0 /(m_zoomPanOptions.m_dZoomFactor * (double)eventArguments.Delta / 1000.0);
double dFactor = 1.0 + m_chart.ViewXY.ZoomPanOptions.ZoomFactor * (double)e.Delta / 1000.0;
if (dFactor > 8)
dFactor = 8;
m_chart.ViewXY.ZoomByFactor(new PointInt(e.Location.X, e.Location.Y), dFactor, true, true);
}
else if (e.Delta < 0)
{
//Zoom out, factor 0...1
double dFactor = 1.0 - m_chart.ViewXY.ZoomPanOptions.ZoomFactor * (double)-e.Delta / 1000.0;
if (dFactor < 0.2)
dFactor = 0.2;
m_chart.ViewXY.ZoomByFactor(new PointInt(e.Location.X, e.Location.Y), dFactor, true, true);
}
m_chart.EndUpdate();
}
}
Then it'll limit the zooming. You may want to improve it to handle cases where the mouse wheel is scrolled fast, thus e.Delta comes large. Because the check is before the zooming, it may result into too large zoom out.
I hope this helps