Select to view content in your preferred language

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

2207
2
Jump to solution
06-13-2018 03:09 AM
AlessandroValra
Frequent Contributor

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).

0 Kudos
1 Solution

Accepted Solutions
BjornSvensson
Esri Regular Contributor

No, there isn't currently a way to reinitialize the viewpoint when the view changes.  However, it's something we would like to support in the future.

View solution in original post

0 Kudos
2 Replies
BjornSvensson
Esri Regular Contributor

No, there isn't currently a way to reinitialize the viewpoint when the view changes.  However, it's something we would like to support in the future.

0 Kudos
AlessandroValra
Frequent Contributor

Bjorn Svensson‌ Thanks for clarifying. I just found it strange that one can actually set the spatialReference of a view by doing (e.g.) "view.spatialReference = 4326" and the viewpoint then throws strange errors in the console because it is not recognizing the same SR anymore. However, this is certainly something I can live with.

0 Kudos