AnsweredAssumed Answered

Why is Geometry Server Project failing with toJson is not a function?

Question asked by codymc77 on Feb 2, 2020
Latest reply on Feb 3, 2020 by codymc77

I've inherited a mapviewer which provides a function that accepts latitude and longitude values, and should then move to that point on the map and place a pin. However, the input x and y come from Google Maps wkid 4326 and I need to convert them to wkid 2357. The function formerly relied on projectionPromise which was throwing web assembly errors in both IE and Chrome. I tried coding around this to use the Geometry Server Project function. Now I receive Uncaught TypeError: a.toJson is not a function.

 

Can somebody save me?

 

 

dropPin: function(e){
var latY = ""
var lonX = ""
var alertMessage = "Both Latttitude and Longitude must be entered"
if(!this.labelLayer){
this.labelLayer = new GraphicsLayer({id: "labelLayer"})
}
if(!this.resultsLayer){
this.resultsLayer = new GraphicsLayer({id: "resultsLayer"})
}
if(e.srcElement.dataset.dojoAttachPoint == "DropPinBtn"){
if(this.LatTxt.value == "" || this.LongTxt.value == ""){
alert(alertMessage)
return
} else {
lonX = this.LongTxt.value
latY = this.LatTxt.value
}
}

if(parseFloat(latY) && parseFloat(lonX)){
latY = parseFloat(latY)
lonX = parseFloat(lonX)
if(latY>-90 && latY<90){
if(lonX>-180 && lonX<180){
//Main Body
//Create new graphic and symbolize
var newPin = {"geometry":{"x":lonX,"y":latY, "spatialReference":{"wkid":4326}} }
//var rePin = Projection.project(newPin, this.map.spatialReference)
var symbol = this.defaultSymbol;
var graphic = new Graphic(newPin);
graphic.setSymbol(symbol);
console.log(graphic);
var featureSet = jimuUtils.toFeatureSet(graphic);
jimuUtils.zoomToFeatureSet(this.map, featureSet);

//the above successfully re-centers the map, but does not draw the graphic
var geoService = new GeometryService(this.geometryService);
var outSpatialReference = new SpatialReference(this.map.spatialReference);
var coordParams = new ProjectParameters();
coordParams.inSR = newPin.geometry.spatialReference;
coordParams.outSR = outSpatialReference;
coordParams.geometries = [newPin.geometry.x, newPin.geometry.y];
console.log(coordParams);
var newCoords = geoService.project(coordParams);
//function fails at the above line of code
this.resultsLayer.add(graphic);
//this.map.graphics.add(graphic);
} else{
alert("Longitude is not within accpetable range of values")
}
} else{
alert("Lattitude is not within accpetable range of values")
}
} else {
alert("Either lattitude or logitude is not a valid number")
}
}

Outcomes