toMap no longer works on view

559
7
Jump to solution
04-23-2019 12:52 PM
JeffSauder
Occasional Contributor

I have been having issues with the tools that I created for my javascript application, such as zoom in, measure, etc.  I narrowed it down to the code that converts the screen point to x,y map point.  This works in the 4.10 version, but not in the 4.11 version.  The strange thing is that I have been using the 4.11 version since April 9 and this just broke 2 days ago.  Switching back to 4.10 works fine.

So for instance drawing the box polygon, I did a console.log for the variable values at the mouse points.  The POINT = is the screen x,y and the second line is the x,y of the 2 envelope points (NW and SE).

4.11 version:

POINT = 954,313
NaN,0,NaN,0
POINT = 958,317
NaN,0,NaN,0

...

In 4.10 I get these values:

POINT = 976,312
746618.9368489848,850462.2705078744,746727.4440104435,850353.7633464157
POINT = 989,326
746618.9368489848,850462.2705078744,748138.0371094076,848834.6630859929

...

The code that converts screen point to map point is pretty straightforward:

if(event.action=="update") {
   var sPoint = {
   x: event.x,
   y: event.y
}
ptUpdate=view.toMap(sPoint.x, sPoint.y);
console.log("POINT = " + sPoint.x + "," + sPoint.y);

//where view is the mapView and ptUpdate is the point to be calculated to map coordinates and passed to the boxpolygon function.

I haven't seen any notices that this toMap function has changed.  If there is something I am missing with the 4.11 upgrade and the ability to convert screen coordinates to map coordinates I haven't been able to find it.

Thanks in advance for any assistance or guidance provided.

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II

So ya, the signature of view.toMap(x, y) did work (I think undoc'd), along with view.toMap({ x, y }) in 4.10 and below, but we changed that to only accept a single argument as Robert showed, toMap({ x, y });

Looks like this change didn't make it into the release notes for 4.11, sorry about that oversight.

Thanks!

View solution in original post

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Jeff,

  If you look at the documentation for toMap it is expecting one object a screenPoint. So though your code worked in the past it is incorrect.

The code should look like:

if(event.action=="update") {
   var sPoint = {
   x: event.x,
   y: event.y
}
ptUpdate=view.toMap(sPoint);
console.log("POINT = " + ptUpdate.x + "," + ptUpdate.y);
0 Kudos
JeffSauder
Occasional Contributor

Hi Robert,

Thanks for the reply. The code you show is exactly what I have. Not sure if I’m missing something…

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Jeff,

  Strange. Are you sure sPoint is Not null when you attempt toMap?

0 Kudos
JeffSauder
Occasional Contributor

Hi Robert,

I tested that and sPoint is not null, it’s passing back the screen coordinates (I tested in both 4.10 and 4.11 and it’s the same).

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Jeff,

  It would help if you can provide a full sample that could be tested that shows this issue.

0 Kudos
JeffSauder
Occasional Contributor

Hi Robert,

Rene commented about using one parameter instead of passing the x,y to the toMap function, I changed that and all works now.

I hadn’t noticed that change in the code you sent me, which was correct, I apologize for overlooking that.

Thanks Robert and Rene

0 Kudos
ReneRubalcava
Frequent Contributor II

So ya, the signature of view.toMap(x, y) did work (I think undoc'd), along with view.toMap({ x, y }) in 4.10 and below, but we changed that to only accept a single argument as Robert showed, toMap({ x, y });

Looks like this change didn't make it into the release notes for 4.11, sorry about that oversight.

Thanks!

0 Kudos