How to Load a local KML from browser url ?

339 views
Skip to first unread message

robertoa...@gmail.com

unread,
Oct 14, 2015, 8:46:16 AM10/14/15
to cesium-dev
Hello,

I am modifiying my QGIS GEarthView plugin, calling Cesium, (together) instead of GoogleEarth.

Now, my question is: how is the correct syntax to load a KML, from the browser URL (that is, without an html page) ?

I noticed that Dragging (& Dropping) the KML file on the CesiumVIewer web page, it works, but with:

http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/index.html?source=file:///c:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml_Lines.kml

it answers an error:

An error occurred while loading the file: file:///c:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml_Lines.kml
An error occurred while loading the file, which may indicate that it is invalid. A detailed error report is below:

NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml_Lines.kml'.
Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml_Lines.kml'.
at Error (native)
at Function.u.load (http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:29100)
at http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:28401
at Object.then (http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:23643)
at e (http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:23356)
at u (http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:28356)
at t (http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:424:17323)
at ui.load (http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:426:2784)
at Function.ui.load (http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:426:2290)
at http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:466:17690


Surely you have already dealt with this issue, you can you please send me a link about it?

Thank you

Roberto

Matthew Amato

unread,
Oct 14, 2015, 9:22:54 AM10/14/15
to cesiu...@googlegroups.com
In most use cases, what you want to do isn't possible.  For security reasons, browsers are heavily sandboxed and reading a file uri directly from disk is impossible without having the browser bringing up a file selection dialog itself for the user to choose which file to read.

That being said, there is one way to do what you want.  You need to read the contents of the file you want to pass to the browser and convert it to a data uris  You can then pass the data uri as part of the URL the same way you pass normal urls.  The one caveat here is that if the file you are loading hasother file url references in it, those won't be readable either.  For that you can either make them embedded data uris as well or in the case of a kml file, you can use a kmz instead.

If you are using an embedded browser control rather than just popping up an external browser, then you might have other options, but that depends on the control being used.

Hope that helps,

Matt



--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roberto Angeletti

unread,
Oct 14, 2015, 10:26:26 AM10/14/15
to cesiu...@googlegroups.com
2015-10-14 15:22 GMT+02:00 Matthew Amato <matt....@gmail.com>:
In most use cases, what you want to do isn't possible.  For security reasons, browsers are heavily sandboxed and reading a file uri directly from disk is impossible without having the browser bringing up a file selection dialog itself for the user to choose which file to read.

OK.  But, I do not understand  why the same problem do not happens with the drag & drop of the KML file.

 

That being said, there is one way to do what you want.  You need to read the contents of the file you want to pass to the browser and convert it to a data uris  You can then pass the data uri as part of the URL the same way you pass normal urls.  The one caveat here is that if the file you are loading hasother file url references in it, those won't be readable either.  For that you can either make them embedded data uris as well or in the case of a kml file, you can use a kmz instead.

MMmmm.  It seems complex.

I have to go to Cesium a KML file created by my plugin for QGIS. Which method do you suggest?


I can call a page of Cesium viewer that already includes' a KML, then I'm going to rewrite dynamically?
 


 

--
You received this message because you are subscribed to a topic in the Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cesium-dev/Esc6kt8Lyoc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cesium-dev+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages