Problem centering to a polygon. Javascript api

2434
2
Jump to solution
07-21-2014 11:40 AM
alexlambson
New Contributor II

So I am pulling parcels, running a query, and trying to center the map to the parcels from the query.

 

I am getting this error:

 

Map: Geometry (wkid: 26912) cannot be converted to spatial reference of the map (wkid: 102100)

 

The coordinates I get from the query are ridiculous, an example is [4109465.94230973, 270652.7635476563]. They display fine when I enable the layer, though. It is only when I do a query that things get weird.

 

and this is all of my code dealing with the parcels

 

$(document).on('click', '#parcel_submit', function(){          parcelId = $('#parcel_input').val(); //get the parcel to search for from the text box          queryTask = new esri.tasks.QueryTask("https://mapserv.utah.gov/arcgis/rest/services/Parcels/MapServer/27");     //initialize query     query = new esri.tasks.Query();     query.returnGeometry = true;     query.outFields = ["OBJECTID", "PARCEL_ID"];     query.where = "PARCEL_ID = '" + parcelId + "';"; //only look for the desired parcel     queryTask.execute(query,showResults);      }); function showResults(featureSet){     var features = featureSet.features; //all of the parcels matching the search. There should only be one     var parcel = features[0]; //get the first parcel     var geometry = parcel.geometry.getCentroid(); //get the center of the parcel     var point = esri.geometry.Point(geometry.y, geometry.x) //create a point     map.centerAndZoom(geometry, 16); //it is centering at some crazy coordinates in the hundreds of thousands.      console.log(features, parcel, geometry, point); }; 

 

Thanks in advance.

 

Bit of honesty, I hardly know the basics since this project was assigned out of nowhere 😕 I apologize if this question is dumb

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Alex,

Try specifying the outSpatialReference property for the Query class to be the same as the map's spatial reference.  Ex:

query.outSpatialReference = map.spatialReference;

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Alex,

Try specifying the outSpatialReference property for the Query class to be the same as the map's spatial reference.  Ex:

query.outSpatialReference = map.spatialReference;

0 Kudos
alexlambson
New Contributor II

Thank you!

Thanks to people like you, I am slowly learning this api.

0 Kudos