diff --git a/.vscode/settings.json b/.vscode/settings.json index 8d4c982c..7107b6ac 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ "*.vs": "cpp", "*.fs": "cpp" }, + "files.trimTrailingWhitespace": false, "editor.fontSize": 16, "editor.autoIndent": false, "editor.detectIndentation": false, diff --git a/src/PointCloudGreyhoundGeometryNode.js b/src/PointCloudGreyhoundGeometryNode.js index cb5769d0..5644d3d0 100644 --- a/src/PointCloudGreyhoundGeometryNode.js +++ b/src/PointCloudGreyhoundGeometryNode.js @@ -261,7 +261,7 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = funct hurl += '&offset=[' + offset.x + ',' + offset.y + ',' + offset.z + ']'; } - var xhr = new XMLHttpRequest(); + var xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', hurl, true); var that = this; diff --git a/src/PointCloudOctreeGeometry.js b/src/PointCloudOctreeGeometry.js index 73e0fa6d..694ac722 100644 --- a/src/PointCloudOctreeGeometry.js +++ b/src/PointCloudOctreeGeometry.js @@ -203,7 +203,7 @@ Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints = function // var hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc"; var hurl = node.pcoGeometry.octreeDir + '/' + node.getHierarchyPath() + '/' + node.name + '.hrc'; - var xhr = new XMLHttpRequest(); + var xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', hurl, true); xhr.responseType = 'arraybuffer'; xhr.overrideMimeType('text/plain; charset=x-user-defined'); diff --git a/src/Potree.js b/src/Potree.js index c0342bf4..ee4589e7 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -615,7 +615,35 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){ }; }; +Potree.XHRFactory = { + config: { + withCredentials: false, + customHeaders: [ + { header: null, value: null } + ] + }, + createXMLHttpRequest: function () { + let xhr = new XMLHttpRequest(); + + if (this.config.customHeaders && + Array.isArray(this.config.customHeaders) && + this.config.customHeaders.length > 0) { + let baseOpen = xhr.open; + let customHeaders = this.config.customHeaders; + xhr.open = function () { + baseOpen.apply(this, [].slice.call(arguments)); + customHeaders.forEach(function (customHeader) { + if (!!customHeader.header && !!customHeader.value) { + xhr.setRequestHeader(customHeader.header, customHeader.value); + } + }); + }; + } + + return xhr; + } +}; diff --git a/src/arena4d/PointCloudArena4DGeometry.js b/src/arena4d/PointCloudArena4DGeometry.js index 37d2e3b0..c13017b4 100644 --- a/src/arena4d/PointCloudArena4DGeometry.js +++ b/src/arena4d/PointCloudArena4DGeometry.js @@ -70,7 +70,7 @@ Potree.PointCloudArena4DGeometryNode.prototype.load = function () { Potree.PointCloudArena4DGeometryNode.nodesLoading++; let url = this.pcoGeometry.url + '?node=' + this.number; - let xhr = new XMLHttpRequest(); + let xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'arraybuffer'; @@ -183,7 +183,7 @@ Potree.PointCloudArena4DGeometry = function () { Potree.PointCloudArena4DGeometry.prototype = Object.create(THREE.EventDispatcher.prototype); Potree.PointCloudArena4DGeometry.load = function (url, callback) { - let xhr = new XMLHttpRequest(); + let xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url + '?info', true); xhr.onreadystatechange = function () { @@ -233,7 +233,7 @@ Potree.PointCloudArena4DGeometry.load = function (url, callback) { Potree.PointCloudArena4DGeometry.prototype.loadHierarchy = function () { let url = this.url + '?tree'; - let xhr = new XMLHttpRequest(); + let xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'arraybuffer'; diff --git a/src/loader/BinaryLoader.js b/src/loader/BinaryLoader.js index 314ade5e..747b40a2 100644 --- a/src/loader/BinaryLoader.js +++ b/src/loader/BinaryLoader.js @@ -23,7 +23,7 @@ Potree.BinaryLoader.prototype.load = function (node) { url += '.bin'; } - let xhr = new XMLHttpRequest(); + let xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'arraybuffer'; xhr.overrideMimeType('text/plain; charset=x-user-defined'); diff --git a/src/loader/GreyhoundBinaryLoader.js b/src/loader/GreyhoundBinaryLoader.js index 00109dfd..012c40c8 100644 --- a/src/loader/GreyhoundBinaryLoader.js +++ b/src/loader/GreyhoundBinaryLoader.js @@ -22,7 +22,7 @@ Potree.GreyhoundBinaryLoader = class{ let scope = this; let url = node.getURL(); - let xhr = new XMLHttpRequest(); + let xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'arraybuffer'; xhr.overrideMimeType('text/plain; charset=x-user-defined'); diff --git a/src/loader/GreyhoundLoader.js b/src/loader/GreyhoundLoader.js index c4f54bfc..0b007190 100644 --- a/src/loader/GreyhoundLoader.js +++ b/src/loader/GreyhoundLoader.js @@ -46,7 +46,7 @@ class GreyhoundUtils { } static fetch (url, cb) { - var xhr = new XMLHttpRequest(); + var xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { @@ -61,7 +61,7 @@ class GreyhoundUtils { }; static fetchBinary (url, cb) { - var xhr = new XMLHttpRequest(); + var xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'arraybuffer'; xhr.onreadystatechange = function () { diff --git a/src/loader/LasLazLoader.js b/src/loader/LasLazLoader.js index 2a50e1c4..87e9a414 100644 --- a/src/loader/LasLazLoader.js +++ b/src/loader/LasLazLoader.js @@ -35,7 +35,7 @@ Potree.LasLazLoader = class LasLazLoader { let scope = this; - let xhr = new XMLHttpRequest(); + let xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'arraybuffer'; xhr.overrideMimeType('text/plain; charset=x-user-defined'); diff --git a/src/loader/POCLoader.js b/src/loader/POCLoader.js index 7e7d1297..fc1f1efd 100644 --- a/src/loader/POCLoader.js +++ b/src/loader/POCLoader.js @@ -20,7 +20,7 @@ Potree.POCLoader.load = function load (url, callback) { try { let pco = new Potree.PointCloudOctreeGeometry(); pco.url = url; - let xhr = new XMLHttpRequest(); + let xhr = Potree.XHRFactory.createXMLHttpRequest(); xhr.open('GET', url, true); xhr.onreadystatechange = function () { diff --git a/src/utils.js b/src/utils.js index 3ae8b7a6..743823b8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -42,7 +42,7 @@ Potree.utils = class { }; static pathExists (url) { - let req = new XMLHttpRequest(); + let req = Potree.XHRFactory.createXMLHttpRequest(); req.open('GET', url, false); req.send(null); if (req.status !== 200) {