I was following the example at:
http://help.infragistics.com/Help/NetAdvantage/DV/2009.1/CLR3.5/html/SL_DV_xamWebMap_Displaying_xamWebMap_Using_Shapefiles.html
I get an "Object reference not set to an instance of an object" when I step through the code. The error occurs when the statesLayer.Reader is set to the reader.
In C#:
ShapeFileReader reader = new ShapeFileReader(); reader.Uri = "Shapefiles/usa_st"; DataMapping.Converter converter = new DataMapping.Converter(); reader.DataMapping = converter.ConvertFromString("Caption=STATE_ABBR") as DataMapping; statesLayer.Reader = reader;
new
"Shapefiles/usa_st"
"Caption=STATE_ABBR"
as
is statesLayer null?
can you provide the call stack from when that exception is thrown?
statesLayer was defined in the XAML.
I've learned through experimentation that setting the values anywhere outside of the constructor either causes errors or has no visible effect on the page. The code below works when in the constructor but not in the Page_Loaded method. When in the Page_Loaded, the map's layer is not visible.
StatesMap.Layers.Add(statesLayer);
reader.Uri =
"Shapefiles/usa_st";
statesLayer.Reader = reader;
eschmuck said:statesLayer was defined in the XAML.
if statesLayer is defined in XAML, the reference might be null if you are accessing it through the field on the parent page. try using xamWebMap1.Layers[0] instead.
eschmuck said:When in the Page_Loaded, the map's layer is not visible.
in this case, you need to call the Layer's Import() method, and then the Map control's WindowFit() method to fit the map content to the control bounds.
after the control is initially loaded, the map will no longer "auto-load and fit" the MapLayers in the Layers collection. it is designed to work that way, so layers can be added in code without causing the UI to change immediately.