Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I m using the following c# code to add my layer dynamically on a arcgis silverlight application:

ArcGISDynamicMapServiceLayer mylayer = new ArcGISDynamicMapServiceLayer()
{
   ID = layerName,
   Url = mapServiceUrl,
 };
 mylayer.Initialize();
 mylayer.Initialized += mylayer _Initialized;
 mylayer.InitializationFailed += mylayer _Failed;
 myMap.Layers.Add(mylayer );

But when I try to get the spatial reference of the layer using:

SpatialReference sp = mylayer.SpatialReference;
int testww = sp.WKID;

I get an error "Object reference not set to an instance of an object." because mylayer.SpatialReference is Null.

Where m I wrong?

Thanks in advance!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

To get the spatial reference of the layer ,Initialized event is useful, i.e. your "mylayer _Initialized" event.Have you tried that?

private void MyService_Initialized(object sender, EventArgs e)
{
Layer layer = sender as Layer;

//get spatial reference here...
}
share|improve this answer
    
I use mylayer_Initialized only for populating some comboboxes... How can I add to get spatia reference? –  voimak Jun 14 '13 at 9:34
    
it works! thanks!!! –  voimak Jun 14 '13 at 10:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.