Zooming Using Trackbar

Jun 10, 2013 at 6:17 AM
Edited Jun 10, 2013 at 6:18 AM
I want zoomin and zoomout map using trackbar, But its keep zooming with random scale.
Can you guys help me with this?
thankyou very much.

I set trackbar value 0 to 10

Here is my code :


Dim newScale As Double = TrackBar1.Value
Dim defz As Integer

If newScale = zoomScale Then
        MainMap.ZoomToMaxExtents()
        defz = MainMap.ZoomPercent
        ' MsgBox(defz)
        ScaleCombobox.Text = "1 : " & SetMapScale() & " Km"
        scaleLabel.Text = "1 : " & SetMapScale() & " Km"
    ElseIf newScale < zoomScale Then
        'MainMap.ZoomOut(TrackBar1.Value * 0.05)
        MainMap.ZoomOut((TrackBar1.Value / 10) * 0.3)
        zoomScale = 5
        ScaleCombobox.Text = "1 : " & SetMapScale() & " Km"
        scaleLabel.Text = "1 : " & SetMapScale() & " Km"
    ElseIf newScale > zoomScale Then
        'MainMap.ZoomIn(TrackBar1.Value * 0.05)
        MainMap.ZoomIn((TrackBar1.Value / 10) * 0.3)
        zoomScale = 5
        ScaleCombobox.Text = "1 : " & SetMapScale() & " Km"
        scaleLabel.Text = "1 : " & SetMapScale() & " Km"
    End If
Jun 10, 2013 at 5:39 PM
This works great for me, sorry not VB. Zooming in, then out, or vice-versa, will take you back to where you started.
    private void trackZoom_ValueChanged(object sender, EventArgs e) {
        // If we are not showing jpegs/rasters we can update the zoom for each
        //click of track bar. This code is duplicated in the mouseup event
        //where we handle zooming if jpegs are being displayed.
        //if (!Globals.Globals.ShowJPGs) {
            int trackMovedAmount = trackZoom.Value - trackZoomPreviousValue;

            if (trackMovedAmount != 0) {
                // Get existing extents
                Extents extOld = new Extents();
                extOld = (Extents)map.Extents;
                Extents extNew = new Extents();

                // Save new value
                trackZoomPreviousValue = trackZoom.Value;

                if (trackMovedAmount > 0) { //zoom in
                    double zoomFactor = 0.2;
                    for (int i = 0; i < trackMovedAmount; i++) {
                        extNew.SetBounds(extOld.xMin + (double)zoomFactor * (extOld.xMax - extOld.xMin), extOld.yMin + (double)zoomFactor * (extOld.yMax - extOld.yMin), 0, extOld.xMax - (double)zoomFactor * (extOld.xMax - extOld.xMin), extOld.yMax - (double)zoomFactor * (extOld.yMax - extOld.yMin), 0);
                        extOld = extNew;
                    }

                }
                else { //zoom out
                    double zoomFactor = 0 - 0.3333333; 
                    for (int i = 0; i < (0 - trackMovedAmount); i++) {
                        extNew.SetBounds(extOld.xMin + (double)zoomFactor * (extOld.xMax - extOld.xMin), extOld.yMin + (double)zoomFactor * (extOld.yMax - extOld.yMin), 0, extOld.xMax - (double)zoomFactor * (extOld.xMax - extOld.xMin), extOld.yMax - (double)zoomFactor * (extOld.yMax - extOld.yMin), 0);
                        extOld = extNew;
                    }
                }
                map.Extents = extNew; //Required to have new extents take effect
                mapWidth = DistanceAcrossMap();
        }
  }
Don
Readfield, ME US
Jun 24, 2013 at 7:29 AM
thank you very much Don,

but maybe we can use this for the easy solution. :D
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
    Select Case TrackBar1.Value
        Case 5
            MainMap.ZoomToMaxExtents()

        Case Is > 5
            MainMap.ZoomToMaxExtents()
            MainMap.ZoomIn(TrackBar1.Value / 5 * MainMap.ZoomPercent)

        Case Is < 5
            MainMap.ZoomToMaxExtents()
            MainMap.ZoomOut(5 / TrackBar1.Value * MainMap.ZoomPercent)

            'MainMap.ZoomOut((1 - (TrackBar1.Value / 5)) * MainMap.ZoomPercent)
    End Select
End Sub
Jun 24, 2013 at 12:43 PM
Hi Ulz--Very nice, definitely a much easier approach!

Don