Select to view content in your preferred language

Issue WAB appbuilder custom widget/Geometry/service/project function does not call.

899
4
Jump to solution
04-13-2022 12:04 PM
chunguangWayneZhang
New Contributor III

Very appreciate someone can help my question here. I just start working with WAB builder customized widget. I have a Georgia State plane coordinate as a base map. Once a user click on map to get a point, I need to project to a Geographic coordinate. The widget has no error but when goes to the geometry service project function. It does not give me any call back basically nothing. Please see where I got wrong. It bugs me for several days. Thanks lots.

define(['dojo/_base/declare',
'jimu/BaseWidget',
'dojo/_base/lang',
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
'esri/Color',
'esri/graphic',
'esri/layers/GraphicsLayer',
"esri/tasks/GeometryService",
"esri/geometry/Point",
"esri/SpatialReference",
"esri/tasks/ProjectParameters",
'esri/map'],

function(declare,
BaseWidget,
lang,
SimpleMarkerSymbol,
SimpleLineSymbol,
Color,
Graphic,
GeometryService,
Point,
SpatialReference,
ProjectParameters,
GraphicsLayer,
map)
////////////////
handler = map.on("click", function (evt) {                
                  var inSR = new SpatialReference({
                    wkid: 102667
                  });
                  //var inputpoint = new Point(evt.mapPoint.x, evt.mapPoint.y, inSR);
                  pt=evt.mapPoint;
                  inlon=pt.y;
                  inlat=pt.x;
                   var grs = new esri.tasks.GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
                  var inputpoint = new esri.geometry.Point(inlon, inlat, inSR);
                  var PrjParams = new ProjectParameters();
                  PrjParams.geometries = [inputpoint];
                  var outSR = new SpatialReference(4326);
                  PrjParams.outSR = outSR;
     
                  var y=0;
                  var x=0;
                 
                  //does not execute here below not sure why??????
                  grs.project(PrjParams, function callback(outputpoint){
                         y = outputpoint[0].y;
                         x = outputpoint[0].x;
                        console.log('Conversion completed. Input SR: 102667 '+ outputpoint[0].y);
      });
    });
 
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

There's a problem with your module/function argument agreement. The misplaced GraphicsLayer argument throws everything off

define(['dojo/_base/declare',
'jimu/BaseWidget',
'dojo/_base/lang',
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
'esri/Color',
'esri/graphic',
'esri/layers/GraphicsLayer',
"esri/tasks/GeometryService",
"esri/geometry/Point",
"esri/SpatialReference",
"esri/tasks/ProjectParameters",
'esri/map'],

function(declare,
BaseWidget,
lang,
SimpleMarkerSymbol,
SimpleLineSymbol,
Color,
Graphic,
GraphicsLayer, //moved
GeometryService,
Point,
SpatialReference,
ProjectParameters,
map)

 

View solution in original post

4 Replies
RyanDickinson1
New Contributor III

Have you tried using float for the latitude longitude? I recently had a similar process and the values I was passing were string instead of float (performed with "esri/geometry/projection" instead of Geometry service). 

var point = new Point({
    'x': parseFloat(e.Longitude),
    'y': parseFloat(e.Latitude),
    'spatialReference': in_spatialReference,
  })
  var projectedPoint = projection.project(point, out_spatialReference)

 

0 Kudos
chunguangWayneZhang
New Contributor III

Thanks you RyanDickinson. I will see whether I can try projection instead of geometry service. I used wkitID which is number I think.

 

0 Kudos
KenBuja
MVP Esteemed Contributor

There's a problem with your module/function argument agreement. The misplaced GraphicsLayer argument throws everything off

define(['dojo/_base/declare',
'jimu/BaseWidget',
'dojo/_base/lang',
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
'esri/Color',
'esri/graphic',
'esri/layers/GraphicsLayer',
"esri/tasks/GeometryService",
"esri/geometry/Point",
"esri/SpatialReference",
"esri/tasks/ProjectParameters",
'esri/map'],

function(declare,
BaseWidget,
lang,
SimpleMarkerSymbol,
SimpleLineSymbol,
Color,
Graphic,
GraphicsLayer, //moved
GeometryService,
Point,
SpatialReference,
ProjectParameters,
map)

 

chunguangWayneZhang
New Contributor III

Thanks  KenBuja  that order of graphicslayer function does cause issue. The gsv seems working. However it is really strange that if you define the projection with inputSR. The output projected point is off a bit like several degrees somehow. But when you use input point just as evt.mapPoint. It works perfectly. Looks like you cannot define again when you use your own projected layer as basemap in AGOLINE. Nowhere ESRI mentioned this.

0 Kudos