Pan Doesn't Work!!!

3049
7
07-20-2010 05:01 AM
jonataspovoas
New Contributor III
Hi,

My application has two pages: the Main navigation page and a ChildWindow page with a print layout.
On my navigation page the pan function works, but when the ChildWindow pops up, the user can't Pan the map on it. I tryed to make the pan function on my own, but it didn't worked...

Here's how I create the map on the ChildWindow Page:

<esri:Map x:Name="MapaImpressao" Background="#FFC3D2E5" IsLogoVisible="False"
[INDENT][INDENT]Extent = "-183.780014728684,-124.638910568344,179.99999,124.638910568344">
[INDENT]<esri:ArcGISTiledMapServiceLayer ID="Streets World 2D"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />[/INDENT]
[/INDENT][/INDENT]</esri:Map>

Does anyone knows how to manually make the pan works, or how to fix this problem?

I made this function to try debugging the application, and the message was shown:

MapaImpressao.MouseLeftButtonDown += new MouseButtonEventHandler(MapaImpressao_MouseLeftButtonDown);

private void MapaImpressao_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
[INDENT][INDENT]MessageBox.Show("A");[/INDENT][/INDENT]
}
0 Kudos
7 Replies
dotMorten_esri
Esri Notable Contributor
Is you map inside a ScrollViewer? This is not supported, since the scrollviewer intercepts the mouse events needed for panning.
0 Kudos
ShawnKendrot
New Contributor
Are there any plans to get this to work? Or is there a work around?
0 Kudos
JenniferNery
Esri Regular Contributor
We marked this as something we will look into but it is currently not supported and I am not aware of any workaround except for - don't put your map inside the ScrollViewer 😛 (Sorry!)
0 Kudos
jonataspovoas
New Contributor III
Are there any plans to get this to work? Or is there a work around?


Hi, Once SharpGIS told me it wouldn't work on an scrollViewer, i developed a workarround (one of the most bizarre workarrounds i've ever made) to substitute the Pan function

i've made an function that simply centers the point at the map that the user clicks!

here's the code:
<!-- Xaml - button that activates the "pan" -->
<Button Style="{StaticResource MenuButtonStyle}" Click="BtnPan_click" Width="40" Height="35" Margin="5">
    <Image Source="Images/target.png" />
</Button>


string _toolMode = "";
private Draw pointToPan;

private void BtnPan_click(object sender, RoutedEventArgs e)
{
        pointToPan.IsEnabled = true;
        _toolMode = "Pan";
}

public LayoutDeImpressao()
{
        pointToPan = new Draw(targetedMap)
        {
                FillSymbol = DefaultFillSymbol,
                DrawMode = DrawMode.Point
        };
        pointToPan.DrawComplete += PointToPan_DrawComplete;
}

private void PointToPan_DrawComplete(object sender, DrawEventArgs args)
{
        if (_toolMode == "Pan")
        {
                targetedMap.PanTo(args.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint);
        }
}



Remember that this is NOT a pan function. it's just a bizarre work arround to give the user a minimum of navigation on the map.
0 Kudos
DonFreeman
New Contributor
For all who are struggling with this problem, here is a seemingly good fix which I got from Wolf Schmidt at the MS Silverlight team. See http://forums.silverlight.net/forums/p/219762/525044.aspx#525044.

The solution is to get the scrollbars out of the Silverlight app and into the html/asp portion of the project. This worked for me by setting a fixed Height and Width for the Silverlight object in the TestPage which is used to launch the Silverlight app. I didn't even need the panel he suggested.

Cheers!
0 Kudos
DanielRubinstein
New Contributor

I know this post is old,

but it seems, that even in the new releases, the silverlight control doesn't support panning inside ScrollViewer.

as our app must be all wrapped inside a scroll viewer, we have found an elegant workaround.

Just put the Esri Map control inside a Popup, and the popup make a child of the ScrollViewer, with IsOpen="True"

then make sure to define the desired Size for the Map control (cause the popup always adjust its size to the child size, and that not good for us), and walla, it's working like a charm.

0 Kudos
DanielRubinstein
New Contributor

Another way to do, without popups.

public class MapPanInsideScrollViewerBehavior : Behavior<Map>

   {

        #region overrides

       protected override void OnAttached()

       {

           base.OnAttached();

           this.AssociatedObject.MouseLeftButtonDown += AssociatedObject_MouseLeftButtonDown;

           this.AssociatedObject.Loaded += AssociatedObject_Loaded;

       }

       protected override void OnDetaching()

       {

           base.OnDetaching();

           this.AssociatedObject.MouseLeftButtonDown -= AssociatedObject_MouseLeftButtonDown;

           DetachDispatchingEvent();

       }

        #endregion

        #region callbacks

       void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

       {

           e.Handled = true;

       }

       void AssociatedObject_Loaded(object sender, RoutedEventArgs e)

       {

           this.AssociatedObject.Loaded -= AssociatedObject_Loaded;

           AttachDispatchingEvent();

       }

       void fw_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

       {

           this.Dispatcher.BeginInvoke(() => e.Handled = false);

       }

        #endregion

        #region methods

       void AttachDispatchingEvent()

       {

           FrameworkElement fw = this.AssociatedObject.FindDescended<FrameworkElement>();

           fw.MouseLeftButtonDown += fw_MouseLeftButtonDown;

       }

       void DetachDispatchingEvent()

       {

           FrameworkElement fw = this.AssociatedObject.FindDescended<FrameworkElement>();

           fw.MouseLeftButtonDown -= fw_MouseLeftButtonDown;

       }

        #endregion

   }

create & add this behavior to the Map control, this will prevent from ScrollViewer to reclaim focus on it, which causing the Map to stop panning, and than return the RoutedEventArgs.Handled = false, which also can prevent from Map to pan.

!IMPORTANT!

inside the AttachDispatchingEvent and DetachDispatchingEvent methods, I'm using our internal helper method FindDescended on the AssociatedObject. its functionality is to find the first FrameworkElement inside the ControlTemplate of Map control. please replace it with your own implementation, cause it is not part of the attached code.

The reason for that use is, cause I needed to find a away to dispatch an action marking Handled=False before Map control dispatching its own action that checking if the routed event was handled by other control.

0 Kudos