Select to view content in your preferred language

ZoomTo: Invalid spatial reference. Spatial reference must match map'sl...

1001
5
06-17-2010 07:09 PM
RyanCoodey
Frequent Contributor
So at first I was using Map.ZoomTo() to zoom to a feature... but I found that depending on the feature, i would get the error "Invalid spatial reference. Spatial reference must match map's spatial reference"...  So I figured the Map.ZoomTo() did not project the geometry on the fly.  So I programatically invoked a ZoomToAction and it was then working... i thought... so it now works on the feature that didnt work before, but other features are throwing the error "Invalid spatial reference. Spatial reference must match map's spatial reference".  The map I am attaching to should be the same as I am using for Map.ZoomTo()...

Any ideas?  Do I need to use a Geometry service to project the feature first?  Hate to make a trip to the server for that!

Thanks a lot!
0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor
The client doesn't have any reprojection built in, so yes you will have to do a roundtrip first. I'm wondering why your data is in the wrong projection in the first place? Where did this data come from, since it's not in the right projection?
0 Kudos
RyanCoodey
Frequent Contributor
It is our own data and ESRIs.  Our company uses two coordinate systems depending on the situation, either GCS_North_American_1983 or NAD_1927_StatePlane_California_X_FIPS_040X... and the ESRI imagery layers are all WGS_84 I believe... so any one of our maps might have a mixture of these three.  I know its not ideal, but its how our data was setup years ago :(.

Thanks Morten!
0 Kudos
RyanCoodey
Frequent Contributor
Oh, and also, if you mean by "where did the data come from"  it came from either a FindTask or an IdentifyTask, and now I am trying to do a ZoomTo on one of the returned features...
0 Kudos
dotMorten_esri
Esri Notable Contributor
Sounds more like you are not making the correct request 🙂 That's why I asked where the data comes from.
Did you set the SpatialReference property in the FindParameters/IdentifyParameters to that of the map? You should then get data back in the map's spatial reference, and don't have to worry about it at all.
If you dont set it, it will default to the service's spatial reference, which in this case is wrong.
0 Kudos
RyanCoodey
Frequent Contributor
Oh cool, I feel so dumb, thats an easy fix.  Thank you much!!!

For whatever reason:
FindParameters.SpatialReference = Map.SpatialReference;
The find task will fail, no error message but if you dig in the object it gives a 400 status and says the sr is invalid.

FindParameters.SpatialReferenceWKID = Map.SpatialReference.WKID;
This works though, but warns that it is obsolete.

*EDIT* FYI, this does NOT work either: FindParameters.SpatialReference = new SpatialReference(Map.SpatialReference.WKID);
Kinda odd... IdentifyTask does not have this problem though, SpatialReference = Map.SpatialReference works!
0 Kudos