AnsweredAssumed Answered

Esri JS API 4.7 - Changing the view spatial reference in place

Question asked by valraa on Jun 13, 2018
Latest reply on Jun 20, 2018 by valraa

Hi,

 

I'd like to change the view.spatialReference property in place to be able to switch between basemaps with different spatial reference.

All the basemaps I use should be of type TileLayer.

I can actually do what I want if initialize a new view with the spatial reference I want and then add the new basemap.

However, I'd like to do it witout recreating the view from scratch if possible.

Something like doing "view.spatialReference: 32632" or similar with the extent property.

The problem is, when I do it, the console raises an viewpoint error and I don't know how to handle it.

The error is:

[esri.views.MapView] #viewpoint incompatible spatialReference {"latestWkid":3857,"wkid":102100} with view's spatialReference {"wkid":32632}

 

Is there a way to reinizialize the viewpoint when the view changes? I don't see in the docs any reference to setting the spatialreference for the viewpoint, I guess this is set internally when the view is inizialized and this gets the app confused when changing the spatial reference of the view, while its viewpoint "remembers" it as the old one...

I am aware that the viewpoint overrides the extent property in the view class.

Here is the codepen example to hopefully make you understand better my problematic.

Just, be aware that the above example may work or not depending on your browser (I am using FireFox and it works for instance).

Outcomes