Can't use MeasureAction with a GraphicLayer anymore? It's a bug?

2935
4
01-18-2012 06:36 AM
Labels (1)
AndreMachado
New Contributor
Hello,

I'm having a problem to make the MeasureAction work with a GraphicsLayer when using version 2.2 (final) or greater. The MeasureAction was working without any problems with my GraphicsLayer while I was using the ArcGIS WPF API 2.2 BETA (v 2.2.0.525). But when I migrated to the final version (2.2.0.629) the code simple does not work anymore. That's not the only problem that I have with this new version... I'm still waiting for a response on the problem about Tiles from a custom TiledMapServiceLayer class don't load anymore after migration

But for this one, I've tested with versions v2.3 and v2.4 but the problem persists. With the exact same come, if I add a REST based layer (like the ArcGISTiledMapServiceLayer), event if it's invisible, the MeasureAction will work correctly. But if I remove this layer I've an exception:

Exception details:
System.NullReferenceException: Object reference not set to an instance of an object.
   at ESRI.ArcGIS.Client.Behaviors.Utilities.Measure.map_MouseMove(Object sender, MouseEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)


Why I can't use a MeasureAction with a GraphicLayer anymore? This is the expected beahvior or a bug?

If you need, I can attach a sample. But it's very simple to reproduce. Just put a map with one GraphicsLayer and a MeasureAction and it will fail. Change for an ArcGISTiledMapServiceLayer and it'll work. Both can be added to the same map... and the ArcGISTiledMapServiceLayer  can be even invisible. But I think that the GraphicsLayer can't be alone...

Thank you,

Andre
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
Can you attach a sample? I tried to add a GraphicsLayer to this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#UtilityActions but was not able to get the error even with the ArcGISTiledMapServiceLayer Visible=True.
0 Kudos
AndreMachado
New Contributor
Hello Jeniffer,

Thanks for answering. In fact if you have both layers in the same map it will work. But if you have just the GraphicsLayer, it won't. I'm attaching a sample. It has two layers (a GraphicsLayer and one ArcGISTiledMapServiceLayer). The ArcGISTiledMapServiceLayer is commented. It references the API version 2.4. If you run and use the measure tool, it'll fail.

Now, uncomment the ArcGISTiledMapServiceLayer and it will work. Even if you set this layer as invisible. And if you change the references (use the API version 2.2 BETA or 2.0, par exemple), it will work even if the ArcGISTiledMapServiceLayer is commented.

Thank you,

André
0 Kudos
JenniferNery
Esri Regular Contributor
Thank you for sharing the sample. Since v2.3 introduced Auto-Projection, we cannot use GraphicsLayer.SpatialReference.

You must set Map.SpatialReference by setting its Extent.SpatialReference:
<esri:Map WrapAround="True" x:Name="MyMap" Grid.Column="0" Grid.Row="1" >
   <esri:Map.Extent>
     <esri:Envelope>
      <esri:Envelope.SpatialReference>
       <esri:SpatialReference WKID="4326"/>
      </esri:Envelope.SpatialReference>
     </esri:Envelope>
   </esri:Map.Extent>
    <esri:GraphicsLayer >
                <esri:GraphicsLayer.Renderer>
                    <esri:SimpleRenderer Symbol="{StaticResource DefaultLineSymbol}"/>
                </esri:GraphicsLayer.Renderer>

                <esri:GraphicsLayer.Graphics >
                    <esri:Graphic>
                        <Geometry:Polyline >
                            <Geometry:Polyline.Paths>
                                <Geometry:PointCollection>
                                    <Geometry:MapPoint X="0" Y="51.399" />
                                    <Geometry:MapPoint X="2.637" Y="48.865" />
                                    <Geometry:MapPoint X="12.568" Y="41.706" />
                                    <Geometry:MapPoint X="13.447" Y="52.483" />
                                    <Geometry:MapPoint X="21.357" Y="52.160" />
                                    <Geometry:MapPoint X="30.322" Y="59.845" />
                                </Geometry:PointCollection>       
                            </Geometry:Polyline.Paths>
       <esri:Polyline.SpatialReference>
        <esri:SpatialReference WKID="4326"/>
       </esri:Polyline.SpatialReference>
                        </Geometry:Polyline>
                    </esri:Graphic>
                </esri:GraphicsLayer.Graphics>
            </esri:GraphicsLayer>

            <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />-->
        </esri:Map>


In addition, I've added this in code-behind so you can zoom to GraphicsLayer.FullExtent
   MyMap.Layers.LayersInitialized += (s, e) =>
    {
     MyMap.ZoomTo(MyMap.Layers[0].FullExtent);
    };
0 Kudos
AndreMachado
New Contributor
It worked! Thank you Jennifer!

Andre
0 Kudos