<esri:Map x:Name="Map" Background="White"> .... .... <esri:Map.Layers> <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> </esri:Map.Layers> </esri:Map>
public GraphicsLayer CreatePointGraphicLayer(string ID, SpatialReference spatial_reference, List<double> x_list, List<double> y_list, List<string> fields, List<string[]> other_fields_values) { GraphicsLayer graphics_layer = new GraphicsLayer(); graphics_layer.ID = ID; SimpleMarkerSymbol simple_marker_symbol = new SimpleMarkerSymbol(); simple_marker_symbol.Color = new SolidColorBrush(Colors.Red); for (int i = 0; i < x_list.Count; i++) { Graphic graphic = new Graphic() { Symbol = simple_marker_symbol, Geometry = new MapPoint(x_list, y_list, spatial_reference) }; for (int j = 0; j < fields.Count; j++) { graphic.Attributes[fields] = other_fields_values ; } graphics_layer.Graphics.Add(graphic); } return graphics_layer; }
GraphicsLayer g_layer = CreatePointGraphicLayer(....) //I omit this part Map.Layers.Add(g_layer);
So, the orig problem described in the first post is not solved, but the export problem I was seeing (which I thought was related) is solved.
If that is the case, then the GraphicsLayer definition should not include a SpatialReference property at all. I am encountering a similar problem to this where adding points - which their SR set correctly - to a GraphicLayer is hanging the application. The map is fully loaded with it's SR set and the layers initialized, yet the problem persists.
The workaround for my issue is to set the GraphicsLayer.SpatialReference via reflection (since it's private), and the issue is solved.
Mark,
Just to note ... the information in the following thread provided insights that may be helpful:
https://community.esri.com/thread/117206
Following that example, the fragment below shows a class derived from GraphicsLayer that overrides the OnInitializeGraphicsLayerRequestedAsync() method.
---------------------
public class MyGraphicsLayer : GraphicsLayer
{
private SpatialReference _layerSpatialReference = null;
public MyGraphicsLayer(SpatialReference layerSpatialReference)
{
// Capture the specified spatial reference so it is available
// for use in the OnInitializeGraphicsLayerRequestedAsync() override.
_layerSpatialReference = layerSpatialReference;
}
protected override Task<GraphicsLayerInitializationInfo> OnInitializeGraphicsLayerRequestedAsync()
{
return Task.FromResult(
new GraphicsLayerInitializationInfo() { PreferredSpatialReference = _layerSpatialReference }
);
}
}
-------------------
The fragment below demonstrates using the derived class (plus .InitializeAsynch) to assign the Spatial Reference:
--------------------
// Source of the graphic data is a FeatureSet loaded from the content of a *.json file.
// The returned FeatureSet has its SpatialReference property set.
// The intent is to assign that SpatialReference to the graphics layer prior to populating the layer.
string jsonFileContent = (... previously read from a *.json file ...)
FeatureSet featureSet = FeatureSet.FromJson(jsonFileContent);
MyGraphicsLayer graphicsLayer = new MyGraphicsLayer(featureSet.SpatialReference);
// Execution of the .InitializeAsync() call does transfer control into
// the OnInitializeGraphicsLayerRequestedAsync() override above.
// The effect is to assign the spatial reference to the graphics layer.
await graphicsLayer.InitializeAsync();
---------------------
While the above approach seems to achieve the objective, it does require more code than one might expect (at least, in my opinion, it seems there could be a more straightforward technique for assigning a Spatial Reference to a graphics layer).
Scott