Select to view content in your preferred language

Problem with Map.ZoomTo

1034
8
07-01-2010 01:03 PM
TeranceEmory
Deactivated User
Hi,

I am still pretty new to ESRI and Silverlight so please be gentle.

I have a map <esri:Map/> with two layers, the ESRI_StreetMap_World_2D Tiled Map and a local Dynamic map layer.  The Tiled map is on top of the Dynamic map.

Initially everything is fine, and all built-in functionality appears to work, zoom, pan etc via the map controls.

The problem arises the first time I attempt to Query a layer and zoom to the returned extent.

I am using the ESRI.ArcGIS.Client.Tasks.Query class and it appears I am getting back a featureset however once I attempt to ZoomTo it the display goes white.

If I remove the ESRI Street Map the zoom works correctly.

I thought it had something to do with maybe the tiled map not supporting the extent that I was trying to zoom to (Not sure how to tell), but even turning on the SnapToLevels had no effect.

Any help would be greatly appreciated.
0 Kudos
8 Replies
dotMorten_esri
Esri Notable Contributor
If everything turns white, its usually because an unhandled exception was thrown. Look in the lower left corner of IE for an indication of an error (and dbl click the error icon to get the problem description)
0 Kudos
BrentStevener
Deactivated User
I have ran into this problem, and not sure what the issue is. I am trying to zoom to a county (through a tool), and when I call Map.ZoomTo with the extent of the feature that I want, I get a blank map, and no errors show up (In IE, Firefox, etc). I can zoom back to the map full extent (through a zoom to full extent tool), and the map displays again. However, whenever I try to zoom again (using our zoom tool), the same issue occurs. We have several types of layers in our map (Dynamic, Tiled, ImageService, Graphics), and the Map.ZoomTo function just doesn't work. Any ideas?

I have a reference to the Map in our tool (_Map), and am calling it with the below code:

_Map.ZoomTo(fs.Features(0).Geometry.Extent)

I have verified that there is a feature being returned, and I am trying to zoom to the extent of that feature. This is a polygon feature of a county.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
It might be a spatial reference issue.
'ZoomTo' method is expecting a geometry in the same spatial reference than the map.

What is the spatial reference of your feature?

You might also find  some infos in this thread:
http://forums.arcgis.com/threads/15209-How-to-zoom-in-a-selected-feature
0 Kudos
BrentStevener
Deactivated User
First, I was calling Geometry.Extent instead of just using the Geometry object in the Map.ZoomTo method. The reason for this was that when trying to use the normal Geometry object, nothing was done, because of an error that only displayed in IE.

The error is because of the spatial reference of the geometry of the returned feature is different than the spatial reference of the map. I believe the Map spatial reference is set to the first layer that has a valid spatial reference, in this case, an ESRI tiled service layer, and I want to zoom into a feature in our layer, which is a dynamic service layer.

How do I fix this so that the zoom will work?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Try by setting the spatial reference of the geometry:

fs.Features[0].Geometry.SpatialReference = _Map.SpatialReference;
_Map.ZoomTo(fs.Features(0).Geometry)
0 Kudos
BrentStevener
Deactivated User
Doesn't seem to be that easy. Whenever I try to set the geometry spatial reference, it hangs the browser and no execution happens after that (I tried displaying a simple messagebox right after the line, but it never shows). I can see that the spatial references are different (WKID 4326 is map, 26914 is geometry) before I try to set the feature's spatial reference to the map spatial reference.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I don't know where are coming your feature from, but if it's coming from a Query you can set the parameter 'OutSpatialReference' in order to get geometries in geographical coordinates (WKID=4326).
If this is not possible, you might have to project the geometry, the easiest way being by a geometry service.


0 Kudos
BrentStevener
Deactivated User
That's actually what I was trying, and it looks like that worked. I set the query's OutSpatialReference property to the Map's spatial reference, and then the returned geometry had the same spatial reference, and it worked (after clearing out the pesky browser cache!)
 Dim q As New Query
 ...
 q.ReturnGeometry = True
 q.OutSpatialReference = _Map.SpatialReference
 ...


Thanks for the quick responses, looks like it is all working beautifully now!
0 Kudos