Page 1 of 1
How to prevent mouse wheel over zooming?
Posted: Tue Apr 23, 2013 9:14 am
by jhyap
Hi all,
I have a world map in lightingChart, and need to interact with the map with some user control like zooming and dragging.
Since it is a world map, I set the X and Y axis value type as map coordinate as shown below:
Code: Select all
m_chartMap.ViewXY.XAxes[0].ValueType = AxisValueType.MapCoordsDegNESW;
m_chartMap.ViewXY.YAxes[0].ValueType = AxisValueType.MapCoordsDegNESW;
Since I want the map to be able to zoom in and out using mouse wheel, I do the following:
Code: Select all
m_chartMap.ViewXY.ZoomPanOptions.MouseWheelZooming = MouseWheelZooming.HorizontalAndVertical;
But, there is an over zooming issue when I tried to zoom out the map at very large scale using the mouse scroll, the map is stretched and not seen.
- map not seen at very large scale
- map.JPG (30.03 KiB) Viewed 12886 times
So, I am thinking to stop the the mouse scroll zoom function when the zoom out range reach X axis minimum at 0 and maximum at 200 ; Y axis minimum at 0 and maximum at 90.
But how to do this?
Regards,
JH
Re: How to prevent mouse wheel over zooming?
Posted: Tue Apr 23, 2013 1:57 pm
by ArctionPasi
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
Re: How to prevent mouse wheel over zooming?
Posted: Wed Apr 24, 2013 2:02 am
by jhyap
Wow, impressive idea on using m_chart.MouseWheel for manual control on mouse wheel, I didn't even realized that I can actually access the mouse wheel control in this way.
And also, thanks for recommending the feature of ViewXY.ZoomByFactor. This is really helpful information.
Great work. Thank you very much!