AnsweredAssumed Answered

Problems with API 4 beta running in a Windows Store application WebView

Question asked by disGolf on Aug 7, 2015
Latest reply on Aug 25, 2015 by odoe

Hi,

I was trying to get the official Create 2D Map sample running with the offline distribution of the API inside of a WebView in a Windows Store application.

 

It turned out to be a non-trivial task and I needed to make a few changes to the official API distribution to get the sample working.

Most of the problems were related to the URL scheme/protocol ms-appx-web: used by Windows Store applications’ WebViews.

 

Let’s start with the installation.

According to the official install.htm one should replace

[HOSTNAME_AND_PATH_TO_JSAPI]

with

<myserver>/arcgis_js_api/library/4.0beta1/4.0beta1/

That was not working for me at the first attempt so I decided to modify the entire baseUrl property.

I replaced

baseUrl:(location.protocol === 'file:' ? 'http:' : location.protocol) + '//' + "[HOSTNAME_AND_PATH_TO_JSAPI]dojo"

with

baseUrl:"arcgis_js_api/library/4.0beta1/4.0beta1/“

I’ve used the same trick also with the API version 3.14 a few months ago.

 

After I got the baseUrl property right the API started to load but it failed to get the basemap. The exception I was getting was “The system cannot locate the resource specified.” The problem was that the API was trying to get the basemap from an invalid URL

ms-appx-web://00000000-0000-4444-0000-000000000000/SampleApp/ms-appx-web://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer

instead of

http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer

 

I managed to trace this problem back to a getabsoluteurl(a) method in init.js file.

It is incorrectly determining the URL scheme. It recognizes http and https only.

I fixed my problem my replacing a regular expression

/^https?:\/\//i

with

(https?|ms-appx-web)

 

This changed moved me one step further to another exception. This time it was complaining about

ms-appx-web://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer?f=json&callback=dojo.io.script.jsonp_dojoIoScript1._jsonpCallback

See that it’s again using the ms-appx-web scheme instead of http. I couldn’t find the place where this URL is being built.

I helped myself by prepending

http:

to

//services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer

in init.js.

 

For some reason I had to do the same trick for

//elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer

 

Finally it all started to work and the basemap loaded and displayed correctly.

 

I know that my changes are not the best ones. I made just to move forward to get the sample running. They are not complex and I do not know what side effects they might have that I’ll run into later when I’ll start migrating our existing Windows Store application built with API 3.14.

 

It would help me a lot if there was an official support for this type of deployment in the future API 4 releases.

Outcomes