Hi All,
I have a Dynamic Map Service Layer and when I try to identify the layers in the service, initially I get null visible layers. Yet if I turn some of the layers on or off, and then use the identify tool, the list-update is triggered and I have a viable list for visible layers...
What am I missing on map load/start up and what am I missing otherwise?
Code Behind (C#)
void Map_MouseClick(object sender, Map.MouseEventArgs e)
{
ArcGISDynamicMapServiceLayer dsl = MapApplication.Current.Map.Layers[MapUtilities.getAppSetting("MainMapService")] as ArcGISDynamicMapServiceLayer;
int[] visibleLayerIDList = dsl.VisibleLayers; // often is null on initial map load and mouse click
ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint;
PrevMapArgs = e;
ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new ESRI.ArcGIS.Client.Tasks.IdentifyParameters()
{
Geometry = clickPoint,
MapExtent = MapApplication.Current.Map.Extent,
Width = (int)MapApplication.Current.Map.ActualWidth,
Height = (int)MapApplication.Current.Map.ActualHeight,
LayerOption = ESRI.ArcGIS.Client.Tasks.LayerOption.all,
SpatialReference = MapApplication.Current.Map.SpatialReference,
Tolerance = 10,
//LayerDefinitions = dsl.LayerDefinitions
};
GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["SelectionGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
dataviewer3.AddIns.CustomIdentify c = new CustomIdentify();
Graphic graphic = new Graphic()
{
Geometry = e.MapPoint,
Symbol = c.Resources["IdentifySearchingSymbol"] as ESRI.ArcGIS.Client.Symbols.MarkerSymbol
};
graphicsLayer.Graphics.Add(graphic);
ESRI.ArcGIS.Client.Tasks.IdentifyTask identifyTask = new ESRI.ArcGIS.Client.Tasks.IdentifyTask(dsl.Url);
identifyTask.ExecuteCompleted += new EventHandler<ESRI.ArcGIS.Client.Tasks.IdentifyEventArgs>(identifyTask_ExecuteCompleted);
identifyTask.ExecuteAsync(identifyParams, visibleLayerIDList); // often is null on initial map load
}
void identifyTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.IdentifyEventArgs e)
{
//MapUtilities.getAppSetting("DigPermitMapService")
// ArcGISDynamicMapServiceLayer dsl = ESRI.ArcGIS.Client.Extensibility.MapApplication.Current.Map.Layers["ANAD_Main"] as ArcGISDynamicMapServiceLayer;
ArcGISDynamicMapServiceLayer dsl = MapApplication.Current.Map.Layers[MapUtilities.getAppSetting("MainMapService")] as ArcGISDynamicMapServiceLayer;
int[] visibleLayerIDList = dsl.VisibleLayers;
if (dsl.VisibleLayers == null)
{
MessageBox.Show("You've selected in a area w/o visible data or your faster than the server, please try again");
}
else
{
dataviewer3.AddIns.CustomIdentify c = new CustomIdentify();
c.IdentifyComboBox.Items.Clear();
// Check for new results
if (e.IdentifyResults.Count > 0)
{
// Show ComboBox and attributes DataGrid
c.IdentifyResultsStackPanel.Visibility = Visibility.Visible;
c.LastIdentifyResult = new List<ESRI.ArcGIS.Client.Tasks.IdentifyResult>();
// Add results to ComboBox
foreach (ESRI.ArcGIS.Client.Tasks.IdentifyResult result in e.IdentifyResults)
{
int find = Array.IndexOf(visibleLayerIDList, result.LayerId);
if (find != -1)
{
string title = string.Format("{0} ({1})", result.Value.ToString(), result.LayerName);
c.IdentifyComboBox.Items.Add(title);
c.LastIdentifyResult.Add(result);
}
}
if (c.IdentifyComboBox.Items.Count > 0)
{
// Workaround for ComboBox bug
c.IdentifyComboBox.UpdateLayout();
// Initialize ComboBox and fire SelectionChanged
c.IdentifyComboBox.SelectedIndex = 0;
if (!this.Window.IsOpen)
{
this.Window.Name = "Identify";
this.Window.Content = c;
this.Window.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.Manual;
Telerik.Windows.Controls.StyleManager.SetTheme(this.Window, new Telerik.Windows.Controls.Windows7Theme());
this.Window.ResizeMode = Telerik.Windows.Controls.ResizeMode.NoResize;
double thewidth = MapApplication.Current.Map.ActualWidth;
double theheight = MapApplication.Current.Map.ActualHeight;
this.Window.Left = thewidth - 410;
this.Window.Top = 100;
this.Window.Header = "Identify Results";
this.Window.Height = theheight - 300;
this.Window.MinWidth = 400;
this.Window.MaxWidth = 400;
this.Window.Show();
}
else
{
this.Window.Content = c;
}
GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["SelectionGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
Graphic graphic = new Graphic()
{
Geometry = PrevMapArgs.MapPoint,
Symbol = c.Resources["IdentifyPointSymbol"] as ESRI.ArcGIS.Client.Symbols.MarkerSymbol
};
graphicsLayer.Graphics.Add(graphic);
}
else
{
GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["SelectionGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
MessageBox.Show("There were no features found at that point.");
}
}
else
{
// Hide ComboBox and attributes DataGrid and notify user
c.IdentifyResultsStackPanel.Visibility = Visibility.Collapsed;
GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["SelectionGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
MessageBox.Show("There were no features found at that point.");
}
}
}