Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file:/// protocol when using Cesium off the web #3935

Closed
TomPed opened this issue May 19, 2016 · 16 comments
Closed

file:/// protocol when using Cesium off the web #3935

TomPed opened this issue May 19, 2016 · 16 comments

Comments

@TomPed
Copy link
Contributor

TomPed commented May 19, 2016

This issue has to do with Cesium being used off the web, i.e., Electron and Cordova trying to load the Natural Earth II imagery.

When you try loading the offline imagery you get this error: net::ERR_FILE_NOT_FOUND. One of the files not found are: file://users/tpedbereznak/Cesium-Editor/node_modules/cesium/Build/CesiumUnminified/Assets/Textures/NaturalEarthII/tilemapresource.xml. If you change file:// to file:/// then the file is found. Knowing this I made a hacky fix.

In loadXML.js I change line line 37: url : url, to url : url.slice(0, 7) + "/" + url.slice(7),.

In UrlTemplateImageryProvider.prototype.reinitialize I changed line line 504: that._url = properties.url; to that._url = properties.url.slice(0, 7) + "/" + properties.url.slice(7);

Now url's with file:// with be changed to file:/// and load the Natural Imagery II. How can this be fixed without this hacky solution?

@mramato
Copy link
Contributor

mramato commented May 19, 2016

What does the code you are using to load the imagery look like? I suspect this is a problem at the app level.

@TomPed
Copy link
Contributor Author

TomPed commented May 19, 2016

I just select Natural Earth II from the imagery picker. No code for that.

@mramato
Copy link
Contributor

mramato commented May 19, 2016

Are you setting CESIUM_BASE_URL in your app?

@TomPed
Copy link
Contributor Author

TomPed commented May 19, 2016

No, I'm not. Where should I be setting this?

@mramato
Copy link
Contributor

mramato commented May 19, 2016

I'm not sure that's the problem; I'm just trying to figure out what the issue could be.

@TomPed
Copy link
Contributor Author

TomPed commented May 19, 2016

I just tried Cesium.buildModuleUrl.setBaseUrl('./node_modules/cesium/Build/CesiumUnminified');. I think we can rule this out.

@mramato
Copy link
Contributor

mramato commented May 19, 2016

If you wanted to try setting it, I would use the absolute path with the 3 slashes.

@TomPed
Copy link
Contributor Author

TomPed commented May 19, 2016

I tried: Cesium.buildModuleUrl.setBaseUrl('file:///Users/tpedbereznak/Electron-Cesium-Starter-Kit/node_modules/cesium/Build/Cesium');. Did not work either.

@hpinkos
Copy link
Contributor

hpinkos commented Jun 3, 2016

@TomPed is this still a problem or did you find a solution?

@TomPed
Copy link
Contributor Author

TomPed commented Jun 3, 2016

Yes, this is still a problem, I have that hacky fix that I mentioned, but that's it.

@hpinkos
Copy link
Contributor

hpinkos commented Jun 3, 2016

Okay thanks, just checking =)

@twpayne
Copy link
Contributor

twpayne commented Oct 21, 2016

I think the problem here that file:// URLs can only use absolute paths. See the Wikipedia article on the file URI scheme for more information, but the tl;dr is that file://users/tpedbereznak/Cesium-Editor/node_modules/... URI does not work because it interprets users as a hostname and /tpedbereznak/Cesium-Editor/node_modules/... as an absolute path on that host, which obviously fails (neither the host nor the path exists).

By hacking in an extra /, you change this to an absolute path that only works on your machine.

Instead, I suggest that you use a relative URL, without specifying the protocol (i.e. without file://) and make sure that you're not calling require.toUrl or similar function. You will need to find the correct relative URL.

I don't think this is a bug in Cesium.

@emackey emackey closed this as completed Oct 21, 2016
@emackey
Copy link
Contributor

emackey commented Oct 21, 2016

Cesium depends too heavily on XHR. It will never work from the file protocol.

@mramato
Copy link
Contributor

mramato commented Oct 21, 2016

@emackey Just to clarify, XHR and Cesium works great with the file protocol, obviously it won't work when running in the browser Sandbox, but for offline web-based containers, like Electron, the whole point is to read off of the file system.

I think @twpayne is correct here and it was simply an error in the electron app itself.

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 21, 2016

@twpayne can you open a PR to fix the demo app? https://github.com/TomPed/Electron-Cesium-Starter-Kit

@Enoooch
Copy link

Enoooch commented Nov 7, 2022

Using three slashes file:/// works on Windows, two slashes file:// works on Mac.

Tested in cesium 1.87 new Cesium.Cesium3DTileset().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants