ArcGISDynamicMapServiceLayer otherFeatBaseMapSrvc = new ArcGISDynamicMapServiceLayer();
otherFeatBaseMapSrvc.Url = currentApps.WebconfigVrbls.OtherFeaturesBaseMapSrvc;
otherFeatBaseMapSrvc.ID = "Other Features Map Service";
otherFeatBaseMapSrvc.Initialized += new EventHandler<EventArgs>(BaseMapSrvc_Initialized);
otherFeatBaseMapSrvc.InitializationFailed += new EventHandler<EventArgs>(BaseMapSrvc_InitializationFailed);
//if this map service is not initialized, then manually initialize it.
if (otherFeatBaseMapSrvc.IsInitialized == false)
{
otherFeatBaseMapSrvc.Initialize();
}void BaseMapSrvc_Initialized(object sender, EventArgs e)
{
ArcGISDynamicMapServiceLayer lyr = sender as ArcGISDynamicMapServiceLayer;
//get layer info array
LayerInfo[] lyrInfoArray = lyr.Layers;
if (lyrInfoArray != null)
{
//iterate thru each layer info and create feature service url for each of the layer by taking it's ID
for (int i = 0; i < lyrInfoArray.Length; i++)
{
LayerInfo lyrInfo = lyrInfoArray;
string featureLyrURL = lyr.Url.Replace("MapServer", "FeatureServer") + "/" + lyrInfo.ID;
//set feature layer using above url
FeatureLayer featLyr = new FeatureLayer();
featLyr.ID = lyrInfo.Name;
featLyr.Mode = FeatureLayer.QueryMode.OnDemand;
featLyr.Url = featureLyrURL;
featLyr.InitializationFailed += new EventHandler<EventArgs>(EditFeatLyr_InitializationFailed);
featLyr.Initialized += new EventHandler<EventArgs>(EditFeatLyr_Initialized);
if (featLyr.IsInitialized == false)
{
featLyr.Initialize();
}
}
}
}void EditFeatLyr_Initialized(object sender, EventArgs e)
{
//get reference to the feature layer that raised the event
FeatureLayer fl = sender as FeatureLayer;
//add this feature layer to the map.
currentApps.MapXaml.MyMap.Layers.Add(fl);
//add this feature layer to application level collection object
currentApps.AllMapServicesCollection.Add(fl);
}the data used in featureservice is getting deleted from the SDE Feature Dataset. This is driving me crazy.
<Grid x:Name="LayoutRoot" Background="White"> <esri:Map x:Name="MyMap"> <esri:Map.Extent> <esri:Envelope XMin="-118.207462406372" YMin="33.5439110882534" XMax="-117.255773795146" YMax="34.8265277847467" > <esri:Envelope.SpatialReference> <esri:SpatialReference WKID="4326"/> </esri:Envelope.SpatialReference> </esri:Envelope> </esri:Map.Extent> </esri:Map> <Button Content="add layers" VerticalAlignment="Top" HorizontalAlignment="Center" Click="Button_Click"/> </Grid>
private void Button_Click(object sender, RoutedEventArgs e)
{
ArcGISDynamicMapServiceLayer dynamicLayer = new ArcGISDynamicMapServiceLayer()
{
Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer"
};
dynamicLayer.Initialized += dynamicLayer_Initialized;
dynamicLayer.Initialize();
}
void dynamicLayer_Initialized(object sender, System.EventArgs e)
{
ArcGISDynamicMapServiceLayer layer = sender as ArcGISDynamicMapServiceLayer;
MyMap.Layers.Add(layer);
string featureService =layer.Url.Replace("MapServer", "FeatureServer");
foreach (var l in layer.Layers)
{
FeatureLayer featureLayer = new FeatureLayer()
{
ID = l.Name,
Mode = FeatureLayer.QueryMode.OnDemand,
Url = string.Format("{0}/{1}",featureService, l.ID)
};
featureLayer.UpdateCompleted += featureLayer_UpdateCompleted;
featureLayer.Initialized += featureLayer_Initialized;
featureLayer.Initialize();
}
}
void featureLayer_UpdateCompleted(object sender, System.EventArgs e)
{
FeatureLayer layer = sender as FeatureLayer;
System.Diagnostics.Debug.WriteLine("{0} Graphics Count: {1}", layer.ID, layer.Graphics.Count);
}
void featureLayer_Initialized(object sender, System.EventArgs e)
{
FeatureLayer layer = sender as FeatureLayer;
MyMap.Layers.Add(layer);
}
It might be that somewhere in your code, you call a layer.Graphics.Clear() or layer.ClearGraphics(). This local change gets pushed directly to your service unless AutoSave is false and you did not call SaveEdits() explicitly.