Hi,
trying to get mapview centered around a changing set of coordinates, in other words the mapview moves and the (changing) coordinate pair stays centered.
I start by building the map and center it around an initial coordinate pair. Immediately after that I launch a periodical GET request (intervals of 200ms) to a server who responds with updated coordinate pairs, which I then assign to mapview.center . When I console.log(view.center) I can see the values in the center object changing over time. So far , everything seems to be working as intended. But the mapview does not change. It stays centered around the initial pair of coordinates and , curious thing, when I manually drag the mapview to another location, one that movement is finished, the mapview jumps back to the initial coordinates. can someone point out to me what I am misunderstanding about how to approach this?
Thank you very much
Koen
Koen,
The best approach is to use the view.goTo method.
Hi Robert, thank you for your swift reply. I had tried goTo. Have now tried it again. Didn't work. In the browser console every variable I send out reflects the changes, but the mapview stays where it is...
Koen,
Sounds like you may be trying to set the map to coordinates that are not the same as the views spatial Reference then. Can you share some code?
Robert,
about the spatial reference and sharing some code:
This is where I initially set up the map and thereafter the periodical GETrequest and goTo
cheers,
Koen
Koen,
If you are still having issues then the better approach to this is to create an actual Point class with a specified spatial reference to give to the view.goTo target or center property.
var centerPnt = new Point(newcoords, new SpatialReference({ wkid:4326 }));
view.goTo({center: centerPnt});