Graphics Layer with custom markers not showing....

1529
3
06-16-2011 07:35 AM
KevinKing
New Contributor
Hey,

I'm just starting with ESRI, and have been using Silverlight with Bing Maps for some time now. I'm trying to add MapPoint elements to a graphics layer within the ESRI map, and at one point I was successful with this.

I haven't been able to get the dots to show up ever since I tried setting the Extent of my map based on an area defined in an Envelope. Here are some code segments of what I'm doing, and perhaps someone will see what I am not.

Here is the XAML markup:

            <esri:Map Name="MyMap" Width="800" Height="600" >
                <esri:Map.Layers>
                    <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" x:Name="BaseLayer" 
              Url="http://server.arcgisonline.com/arcgis/services/World_Street_Map/MapServer" />
                    <esri:GraphicsLayer ID="DataLayer" />
                </esri:Map.Layers>                
            </esri:Map>


Here is where I add the graphics and set the extents. The "data" object is what i'm receiving back from my web service call, so pretend that looks like a real data collection with each item having a Latitude and Longitude. Also, the "center" map point is where I want to center the map, which comes back from the web service as well.

            GraphicsLayer dataLayer = DUMap.Layers["DataLayer"] as GraphicsLayer;
            dataLayer.Graphics.Clear();
            if (dataLayer != null)
            {
                List<object> data = new List<object>();
                foreach (object o in data)
                {
                    MapPoint point = new MapPoint(o.Longitude, o.Latitude);
                    Graphic graphic = new Graphic();
                    graphic.Symbol = new SimpleMarkerSymbol();
                    graphic.Geometry = ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(point);
                    dataLayer.Graphics.Add(graphic);
 
                }
                MapPoint center = new MapPoint(data.center_long, data.center_lat);
                ESRI.ArcGIS.Client.Geometry.Geometry g = ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(center);
                g.SpatialReference = DUMap.SpatialReference;
                double width = 4;
                Envelope envelope = new Envelope()
                {
                    XMin = center.X - width,
                    YMin = center.Y - width,
                    XMax = center.X + width,
                    YMax = center.Y + width,
                    SpatialReference = MyMap.SpatialReference
                };
                MyMap.Extent = envelope;
                dataLayer.Refresh();
            }  



If I've left anything out that is important, please let me know.  I had the dots showing on the map before I tried messing with the extent by adding a custom envelope, so that's where I'm guessing I'm going wrong.

Thanks so much!

Kevin
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
You are setting the map's extent to zoom to the layer's extent? Without these lines of code, do you see any features on your map at all?

   MapPoint center = new MapPoint(data.center_long, data.center_lat);
                ESRI.ArcGIS.Client.Geometry.Geometry g = ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(center);
                g.SpatialReference = DUMap.SpatialReference;
                double width = 4;
                Envelope envelope = new Envelope()
                {
                    XMin = center.X - width,
                    YMin = center.Y - width,
                    XMax = center.X + width,
                    YMax = center.Y + width,
                    SpatialReference = MyMap.SpatialReference
                };
                MyMap.Extent = envelope;


Are the graphics' geometry in the same spatial reference as the map? If not, you might need to call project: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Project
0 Kudos
KevinKing
New Contributor
No, the markers do not show up at all. I added this line:

graphic.Geometry.SpatialReference = MyMap.SpatialReference;

However, that didn't help anything. 

At one point I was able to add the markers to the map... ahhh!

Thanks for your reply!
0 Kudos
KevinKing
New Contributor
I do notice that the Spatial Reference for my DataLayer (which is a graphics layer) is null.

I cannot set it in code, but I'm reading that it should use the spacial reference of the layers added before it (Tiled layer)?

Is this a problem with my tiled layer?

Does anyone have an example of using projection to set the spacial reference of a graphics layer?

Thanks!
0 Kudos