Layer not visible after using the MoveLayer method of map

820
10
08-05-2012 11:27 PM
Labels (1)
martindevos
New Contributor II
After using the MoveLayer method on a map, the moved layer is not displayed anymore.  And there is no Refresh method.
You can make it reappear by zooming or panning or toggling the visibility of it.  Is there no cleaner solution to this problem ?
0 Kudos
10 Replies
AnttiKajanus1
Occasional Contributor III
What layer type you are moving?
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Following on from Antti's question - please can you post your XAML/code which shows how the layer is defined/added and how it is being moved?

Cheers

Mike
0 Kudos
martindevos
New Contributor II
What layer type you are moving?


I have tried any kind of layer (ArcGISTiledMapServiceLayer, ArcGISDynamicMapServiceLayer, FeatureLayer and GraphicsLayer) and they all have the same problem
0 Kudos
martindevos
New Contributor II
Hi,

Following on from Antti's question - please can you post your XAML/code which shows how the layer is defined/added and how it is being moved?

Cheers

Mike


Here are some layers :

<esri:ArcGISTiledMapServiceLayer
ID="Orthofoto"
Url="http://gisservices.inbo.be/ArcGIS/rest/services/Orthofoto/MapServer"
InitializationFailed="Layer_InitializationFailed"
Visible="True"
/>

<esri:ArcGISDynamicMapServiceLayer
ID="Overview"
Url="http://gisservices.inbo.be/ArcGIS/rest/services/Viewer_overview/MapServer"
InitializationFailed="Layer_InitializationFailed"
Visible="True"
/>


And here is the code of the behavior to move them :

protected override void Invoke(object parameter)
{
if (!string.IsNullOrEmpty(this.LayerID))
{
  Map map = base.Target;
  Layer layer = map.Layers[this.LayerID];
  if (layer != null)
  {
   //visibility of layer is a hack because the moved layer isn't displayed anymore
   bool visible = layer.Visible;
   //layer.Visible = false;

   int index = map.Layers.IndexOf(layer);
   if (Direction == MoveLayerDirection.Up && index > 0)
   {   
    map.MoveLayer(index, index - 1);
   }
   else if (Direction == MoveLayerDirection.Down && index < map.Layers.Count - 1)
   {
    map.MoveLayer(index, index + 1);
   }
    
   layer.Visible = visible;
  }
}
}

If I don't use the invisible/visible trick then the moved layer is not visible anymore until you zoom or pan the map or toggle the visibilty off and on

Kind regards,
Martin
0 Kudos
AnttiKajanus1
Occasional Contributor III
Hi,

You can call .Refresh() on layers to update (Tiled, Dynamic, Feature layers atleast) like this:

  <Grid>
        <Grid>
            <esri:Map x:Name="map">
                <esri:ArcGISTiledMapServiceLayer ID="TileLayer" 
                      Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
                <esri:ArcGISDynamicMapServiceLayer ID="DynamicLayer"
                 Url="http://maverick.arcgis.com/ArcGIS/rest/services/World_WGS84/MapServer" VisibleLayers="1,2" />           
            </esri:Map>
        </Grid>
        <Button Click="Button_Click" Height="20" Width="40" HorizontalAlignment="Left">Move</Button>
    </Grid>


 private void Button_Click(object sender, RoutedEventArgs e)
        {
            var layer = this.map.Layers[0];


            var index = map.Layers.IndexOf(layer);


            map.MoveLayer(index, index + 1);


            if (layer is ArcGISTiledMapServiceLayer)
            {
                (layer as ArcGISTiledMapServiceLayer).Refresh();
                
            }
            else if (layer is ArcGISDynamicMapServiceLayer)
            {
                (layer as ArcGISDynamicMapServiceLayer).Refresh();
            }
        }


The code is ugly, but you get the point.
0 Kudos
AnttiKajanus1
Occasional Contributor III
�?sh,

I tested this with

 <Grid>
        <Grid>
            <esri:Map x:Name="map">
                  <esri:ArcGISTiledMapServiceLayer ID="PhysicalTiledLayer" 
                      Url="http://gisservices.inbo.be/ArcGIS/rest/services/Orthofoto/MapServer"/>  
                <esri:ArcGISDynamicMapServiceLayer ID="MyLayer"
                 Url="http://gisservices.inbo.be/ArcGIS/rest/services/Viewer_overview/MapServer" VisibleLayers="1,2" />
            </esri:Map>
        </Grid>
        <Button Click="Button_Click" Height="20" Width="40" HorizontalAlignment="Left">Move</Button>
    </Grid>


 private void Button_Click(object sender, RoutedEventArgs e)
        {
            var layer = this.map.Layers[0];


            var index = map.Layers.IndexOf(layer);


            map.MoveLayer(index, index + 1);


            //if (layer is ArcGISTiledMapServiceLayer)
            //{
            //    (layer as ArcGISTiledMapServiceLayer).Refresh();


            //}
            //else if (layer is ArcGISDynamicMapServiceLayer)
            //{
            //    (layer as ArcGISDynamicMapServiceLayer).Refresh();
            //}
        }


And moving works fine so no need for extra refresh here.
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Likewise - I just tested with your layers and cannot reproduce the problem you're experiencing with MoveLayer.

 
        private void MovetopLayerDown_Click(object sender, RoutedEventArgs e)
        {
            _map.MoveLayer(0, 1);
        }


    <Grid>  
        <esri:Map x:Name="_map" UseAcceleratedDisplay="False">
            <esri:ArcGISTiledMapServiceLayer 
                ID="Orthofoto" 
                Url="http://gisservices.inbo.be/ArcGIS/rest/services/Orthofoto/MapServer"
                Visible="True"
                />
            <esri:ArcGISDynamicMapServiceLayer 
                ID="Overview" 
                Url="http://gisservices.inbo.be/ArcGIS/rest/services/Viewer_overview/MapServer"
                Visible="True"
                />
        </esri:Map>
        <StackPanel>
            <Button Content="Move top layer down" Name="MovetopLayerDown" Click="MovetopLayerDown_Click" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="auto" Height="auto"/>            
        </StackPanel>
    </Grid>


Cheers

Mike
0 Kudos
martindevos
New Contributor II
Hi,

Likewise - I just tested with your layers and cannot reproduce the problem you're experiencing with MoveLayer.

 
        private void MovetopLayerDown_Click(object sender, RoutedEventArgs e)
        {
            _map.MoveLayer(0, 1);
        }


    <Grid>  
        <esri:Map x:Name="_map" UseAcceleratedDisplay="False">
            <esri:ArcGISTiledMapServiceLayer 
                ID="Orthofoto" 
                Url="http://gisservices.inbo.be/ArcGIS/rest/services/Orthofoto/MapServer"
                Visible="True"
                />
            <esri:ArcGISDynamicMapServiceLayer 
                ID="Overview" 
                Url="http://gisservices.inbo.be/ArcGIS/rest/services/Viewer_overview/MapServer"
                Visible="True"
                />
        </esri:Map>
        <StackPanel>
            <Button Content="Move top layer down" Name="MovetopLayerDown" Click="MovetopLayerDown_Click" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="auto" Height="auto"/>            
        </StackPanel>
    </Grid>


Cheers

Mike


Are you also using API for WPF v 2.4 ?
0 Kudos
AnttiKajanus1
Occasional Contributor III
I tested it with 3.0
0 Kudos