Invalid Coordinates captured from Sketch widget event

297
3
Jump to solution
04-15-2019 12:29 PM
DeanMcDonald
New Contributor

I'm trying to capture the lat/long points of the geometry object belonging to a graphic drawn using the Sketch widget. This is saved along with the various other attributes needed so I can recreate a graphic later that was drawn by one of my users.

However I seem to be getting invalid coordinate values from all the graphics objects created using Sketch.

Below is an example of the 'paths' attribute of a polyline geometry object belonging to a graphic created by Sketch when I log it in console:

path: [[3705938.9073652048, 7757323.750164009], [6425874.121864194, 5957078.859992016]]

Those values don't look right to me since afaik coordinate values can only be a maximum of +/-180 for lat and +/-90 for long. Sure enough when I save those in the database and try to recreate the Graphics later using those values they don't appear, but entering something more sane as coordinates does work such as

path: [60.44300476667183, 62.70164927848015], [48.604437825842, 72.97478588000511]

I've tried simply moving the decimal point down 5 or so spaces but then I get completely inaccurate placement and it doesn't seem like the right thing to do anyway. The coordinate seem like something more than just incorrect decimal placement has happened

Below is a snippet of the code I have where the graphic is captured from the event

sketch.on("create", event => {

   if (event.state === "complete") {
      let graphic = event.graphic
      console.log(graphic) // 

   }

}

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Dean,

   Those coordinates are in WKID 102100, webmercator, not geographic. The sketch will use the WKID of the basemap that is used and if you are using a standard esri basemap then it will always be webmercator. You can easily convert those to geographic using the WebmercatorUtils class though.

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Dean,

   Those coordinates are in WKID 102100, webmercator, not geographic. The sketch will use the WKID of the basemap that is used and if you are using a standard esri basemap then it will always be webmercator. You can easily convert those to geographic using the WebmercatorUtils class though.

DeanMcDonald
New Contributor

Thank you! That makes sense and I'm sure I'll have no problems with it now.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos