JS 3.x
Code running in a custom widget from WAB
We're just trying to determine how to work with geometry from a feature service that has a spatial reference of wkid 2881 but our existing code was failing trying to load a graphics layer with the geometry throwing the error,
Geometry (wkid: 2881) cannot be converted to spatial reference of the map (wkid: 102100)
So we identified where this was happening and thought to just try and do a reprojection but I keep getting undefined geometry when I attempt to implement,
Maybe it's a simple scope issue?
getGraphicFromQueryResults: function(queryResults){
if (queryResults && queryResults.features.length > 0){
var theGraphic = this.createGraphicFromGeometry(queryResults.features[0].geometry);
//theGraphic always returns undefined
console.log(theGraphic)
return theGraphic //this.createGraphicFromGeometry(queryResults.features[0].geometry);
}
},
createGraphicFromGeometry: function(geometry){
projection.load().then(lang.hitch(this, function () {
const inSpatialReference = new SpatialReference({ wkid: 2881 });
const spSpatialReference = new SpatialReference({ wkid: 4326 });
const poly = new Polygon(geometry, inSpatialReference);
var geoT = projection.getTransformation(inSpatialReference, spSpatialReference)
const projectedPoly = projection.project(poly, spSpatialReference);
var attributes = {};
attributes[this.config.applicationIdField] = this.appId;
var graphic = new Graphic(projectedPoly,null,attributes);
console.log(graphic)
return graphic;
}).bind(this))
}Or any comment on how to deal with with services with other spatial references than what ESRI basemaps seems to require?