IdentifyTask not working

705
6
02-03-2011 06:45 AM
SangamLama
New Contributor
Hi,

I tweaked my application a bit and now I get a problem.

My base map layer came off a mapserver for a town. It draws all the layers and forms a map. I carry out various tasks on this layer. But this map didn't look very impressive so I decided to add a world map layer first (now the base layer), and added the town layer on the top of that as a secondary layer. Doing this affected a major functionality -- when I apply IdentifyTask on the secondary layer, it doesn't identify anything. Why?

Here's my implementation

private void LayerDetailLink_Click(object sender, RoutedEventArgs e)
        {
            Point _point = _currentMouseoffset;
            MapPoint _mapPoint = MyMap.ScreenToMap(_point);          

            IdentifyParameters identifyParams = new IdentifyParameters()
            {
                Geometry = _mapPoint,
                MapExtent = MyMap.Extent,
                Width = (int)MyMap.ActualWidth,
                Height = (int)MyMap.ActualHeight,
                LayerOption = LayerOption.all

            };

            IdentifyTask identifyTask = new IdentifyTask(NewMapLayer.Url);
            identifyTask.ExecuteCompleted += new EventHandler<IdentifyEventArgs>(identifyTask_ExecuteCompleted);
            identifyTask.Failed +=new EventHandler<TaskFailedEventArgs>(identifyTask_Failed);
            identifyTask.ExecuteAsync(identifyParams);

            GraphicsLayer graphicsLayer = MyMap.Layers["NewMapLayer"] as GraphicsLayer;
           
            Graphic graphic = new Graphic()
            {
                Geometry = _mapPoint,
                Symbol = DefaultPictureSymbol
            };
        }

Any help would be appreciated,
thanks 🙂
0 Kudos
6 Replies
AliMirzabeigi
New Contributor
The issue could be related to having different spatial references in your map service and the base map layer. Here you can find more information on how to resolve this problem.
0 Kudos
SangamLama
New Contributor
The issue could be related to having different spatial references in your map service and the base map layer. Here you can find more information on how to resolve this problem.


Hi,
I'm almost certain that I have the same problem going on. But I didn't understand "stating the spatial reference of the esri map service in code, i.e., SpatialReferenceWKID=4326".

Where exactly do I state that?
0 Kudos
AliMirzabeigi
New Contributor
To define an explicit spatial reference for the map, create an Envelope and assign your SpatialReference:
<esri:Map x:Name="MyMap">
       <esri:Map.Extent>
          <esriGeometry:Envelope XMin="661140" YMin="-1420246" XMax="3015668" YMax="1594451" >
            <esriGeometry:Envelope.SpatialReference>
                <esriGeometry:SpatialReference WKID="26777" />
            </esriGeometry:Envelope.SpatialReference>
          </esriGeometry:Envelope>
       </esri:Map.Extent>
 
       <!-- Layer Definitions Here -->
</esri:Map>


Here you can find a live SDK sample too:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#DefineMapProjection
0 Kudos
SangamLama
New Contributor
Hi,

The example you gave partially worked. And I'm sure it'll work fully, if I clear out couple of confusions I have regarding spatialreference. It's about time I understood them too, so please bear with me here.

1. I don't understand what spatialReference really is? I'm guessing it is the unit that defines how a map is scaled?
2. And I also dont understand why the town's map has web mercator measurement, while the world map has the geographic measurement?

My goal is to add the world map first, then add that town's layer. and for example, if a dog died on the street in that town, even if you dont have the address of the incident, you still have the latitude longitude (ranged +/-180, not the long digits like 2495285.485458, 4485828285.84248). So a town officer dude can send his employee to that lat/long to pick up the dog.

Now the problem is that I either have to get rid of the world map to keep the IdentifyTask functionality, or lose IdentifyTask to keep the town map layer properly aligned to the world map.

But what I did after your example is that I provided my map with certain extent and spatial reference WKID values as follows:

<esri2:Map.Extent>
                                    <esri2:Envelope XMin="1314056.88433054"
                                                    YMin="280204.702031145"
                                                    XMax="1320163.0024767"
                                                    YMax="283631.910500433" >
                                        <esri2:Envelope.SpatialReference>
                                            <esri2:SpatialReference WKID="2285"/>
                                        </esri2:Envelope.SpatialReference>
                                    </esri2:Envelope>                                  
                                </esri2:Map.Extent>
The values you can see above, I copied them from the town map's web service. I ran the application, and it showed me the town's map. Now IdentifyTask works. But, the world map (base layer) is gone!  

So how can I keep everything without losing something? Also, if my guess about spatialreference is correct, the WKID value for every town's map might be different? So I'll need to give it to the map dynamically. How can I do so?

Again, I appreciate all the help 🙂


To define an explicit spatial reference for the map, create an Envelope and assign your SpatialReference:
<esri:Map x:Name="MyMap">
       <esri:Map.Extent>
          <esriGeometry:Envelope XMin="661140" YMin="-1420246" XMax="3015668" YMax="1594451" >
            <esriGeometry:Envelope.SpatialReference>
                <esriGeometry:SpatialReference WKID="26777" />
            </esriGeometry:Envelope.SpatialReference>
          </esriGeometry:Envelope>
       </esri:Map.Extent>
 
       <!-- Layer Definitions Here -->
</esri:Map>


Here you can find a live SDK sample too:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#DefineMapProjection
0 Kudos
AliMirzabeigi
New Contributor
To have a short answer for your question please look at the API reference here to get to know about the map spatial reference. Navigate to ESRI.ArcGIS.Client --> Classes --> Map and you'll see the following:


The Map's spatial reference is determined by the first layer in the map that has this property set. However, it can be overridden by explicitly setting the Extent property with an envelope that has a SpatialReference defined. This has to be done before any layers will be initalized by the map. Once the spatial reference of a map has been set and the layers has loaded, the spatial reference can no longer be changed. If you need to change spatial reference on the fly, you can instead create a new map instance, move the layers to this map, and replace the previous map instance. Also note that tiled layers does not support reprojection, and will not be displayed if the Map's SpatialReference does not match the spatial reference of the tiled layer.


Hope this helps.
0 Kudos
SangamLama
New Contributor
ok I got it to working!

thanks,
0 Kudos