Skip to content

Commit

Permalink
Add options load via proxy and clamp to ground
Browse files Browse the repository at this point in the history
  • Loading branch information
Son-HNguyen committed Apr 30, 2020
1 parent b8694d0 commit c736ba7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
8 changes: 8 additions & 0 deletions 3dwebclient/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@
</select>
</td>
</tr>
<tr id="layerProxyAndClampToGround" style="display: none;">
<td>
<label><input type="checkbox" id="layerProxyCheckbox" style="width:auto;" data-bind="checked: layerProxy"/> Load via proxy</label>
</td>
<td>
<label><input type="checkbox" id="layerClampToGroundCheckbox" style="width:auto;" data-bind="checked: layerClampToGround"/> KML clamp to ground</label>
</td>
</tr>
<tr id="gltfVersionDropdownRow" style="display: none;">
<td>glTF version</td>
<td>
Expand Down
14 changes: 14 additions & 0 deletions 3dwebclient/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ var addLayerViewModel = {
url: "",
name: "",
layerDataType: "",
layerProxy: false,
layerClampToGround: true,
gltfVersion: "",
thematicDataUrl: "",
thematicDataSource: "",
Expand Down Expand Up @@ -287,6 +289,8 @@ function observeActiveLayer() {
addLayerViewModel.url = selectedLayer.url;
addLayerViewModel.name = selectedLayer.name;
addLayerViewModel.layerDataType = selectedLayer.layerDataType;
addLayerViewModel.layerProxy = selectedLayer.layerProxy;
addLayerViewModel.layerClampToGround = selectedLayer.layerClampToGround;
addLayerViewModel.gltfVersion = selectedLayer.gltfVersion;
addLayerViewModel.thematicDataUrl = selectedLayer.thematicDataUrl;
addLayerViewModel.thematicDataSource = selectedLayer.thematicDataSource;
Expand Down Expand Up @@ -391,6 +395,8 @@ function getLayersFromUrl() {
url: layerConfig.url,
name: layerConfig.name,
layerDataType: Cesium.defaultValue(layerConfig.layerDataType, "COLLADA/KML/glTF"),
layerProxy: Cesium.defined(layerConfig.layerProxy) ? layerConfig.layerProxy === "true" : false,
layerClampToGround: Cesium.defined(layerConfig.layerProxy) ? layerConfig.layerClampToGround === "true" : true,
gltfVersion: Cesium.defaultValue(layerConfig.gltfVersion, "2.0"),
thematicDataUrl: Cesium.defaultValue(layerConfig.spreadsheetUrl, ""),
thematicDataSource: Cesium.defaultValue(layerConfig.thematicDataSource, "GoogleSheets"),
Expand Down Expand Up @@ -476,6 +482,8 @@ function saveLayerSettings() {
applySaving('url', activeLayer);
applySaving('name', activeLayer);
applySaving('layerDataType', activeLayer);
applySaving('layerProxy', activeLayer);
applySaving('layerClampToGround', activeLayer);
applySaving('gltfVersion', activeLayer);
applySaving('thematicDataUrl', activeLayer);
applySaving('thematicDataSource', activeLayer);
Expand Down Expand Up @@ -824,6 +832,8 @@ function layersToQuery() {
url: layer.url,
name: layer.name,
layerDataType: layer.layerDataType,
layerProxy: layer.layerProxy,
layerClampToGround: layer.layerClampToGround,
gltfVersion: layer.gltfVersion,
active: layer.active,
spreadsheetUrl: layer.thematicDataUrl,
Expand Down Expand Up @@ -1014,6 +1024,8 @@ function addNewLayer() {
url: addLayerViewModel.url.trim(),
name: addLayerViewModel.name.trim(),
layerDataType: addLayerViewModel.layerDataType.trim(),
layerProxy: (addLayerViewModel.layerProxy.trim() === "true"),
layerClampToGround: (addLayerViewModel.layerClampToGround.trim() === "true"),
gltfVersion: addLayerViewModel.gltfVersion.trim(),
thematicDataUrl: addLayerViewModel.thematicDataUrl.trim(),
thematicDataSource: addLayerViewModel.thematicDataSource.trim(),
Expand Down Expand Up @@ -1321,8 +1333,10 @@ function layerDataTypeDropdownOnchange() {
var layerDataTypeDropdown = document.getElementById("layerDataTypeDropdown");
if (layerDataTypeDropdown.options[layerDataTypeDropdown.selectedIndex].value !== "COLLADA/KML/glTF") {
document.getElementById("gltfVersionDropdownRow").style.display = "none";
document.getElementById("layerProxyAndClampToGround").style.display = "none";
} else {
document.getElementById("gltfVersionDropdownRow").style.display = "";
document.getElementById("layerProxyAndClampToGround").style.display = "";
}
addLayerViewModel["layerDataType"] = layerDataTypeDropdown.options[layerDataTypeDropdown.selectedIndex].value;
}
Expand Down
41 changes: 36 additions & 5 deletions js/CitydbKmlLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@
this._mouseOverhighlightColor = new Cesium.Color(0.0, 0.3, 0.0, 1.0);

this._layerDataType = options.layerDataType;
this._layerProxy = options.layerProxy;
this._layerClampToGround = options.layerClampToGround;
this._gltfVersion = options.gltfVersion;

this._configParameters = {
"id": this.id,
"url": this.url,
"name": this.name,
"layerDataType": this.layerDataType,
"layerProxy": this.layerProxy,
"layerClampToGround": this.layerClampToGround,
"gltfVersion": this.gltfVersion,
"thematicDataUrl": this.thematicDataUrl,
"thematicDataSource": this.thematicDataSource,
Expand Down Expand Up @@ -319,6 +323,24 @@
}
},

layerProxy: {
get: function () {
return this._layerProxy;
},
set: function (value) {
this._layerProxy = value;
}
},

layerClampToGround: {
get: function () {
return this._layerClampToGround;
},
set: function (value) {
this._layerClampToGround = value;
}
},

gltfVersion: {
get: function () {
return this._gltfVersion;
Expand Down Expand Up @@ -346,7 +368,7 @@

function loadMasterJSON(that, isFirstLoad) {
var deferred = Cesium.when.defer();
var jsonUrl = that._url;
var jsonUrl = checkProxyUrl(that, that._url);
new Cesium.Resource({url: jsonUrl}).fetch({responseType: 'json'}).then(function (json) {
that._jsonLayerInfo = json;
that._layerType = json.displayform;
Expand Down Expand Up @@ -431,6 +453,15 @@
}
}

function checkProxyUrl(obj, url) {
if (obj._layerProxy === true || obj._layerProxy === "true") {
return (url.substring(0, 5) === "https" ? "https" : "http")
+ "://www.3dcitydb.net/proxy/?" + url;
}

return url;
}

/**
* adds this layer to the given Cesium viewer
* @param {CesiumViewer} cesiumViewer
Expand All @@ -455,7 +486,7 @@
canvas: cesiumViewer.scene.canvas
});

this._citydbKmlDataSource.load(this._url).then(function (dataSource) {
this._citydbKmlDataSource.load(checkProxyUrl(this, this._url)).then(function (dataSource) {
assignLayerIdToDataSourceEntites(dataSource.entities, that._id);
if (that._active) {
cesiumViewer.dataSources.add(dataSource);
Expand All @@ -467,7 +498,7 @@
} else if (this._urlSuffix == 'czml') {
this._citydbKmlDataSource = new Cesium.CzmlDataSource();

this._citydbKmlDataSource.load(this._url).then(function (dataSource) {
this._citydbKmlDataSource.load(checkProxyUrl(this, this._url)).then(function (dataSource) {
assignLayerIdToDataSourceEntites(dataSource.entities, that._id);
if (that._active) {
cesiumViewer.dataSources.add(dataSource);
Expand Down Expand Up @@ -849,7 +880,7 @@
canvas: this._cesiumViewer.scene.canvas
});

this._citydbKmlDataSource.load(this._url).then(function (dataSource) {
this._citydbKmlDataSource.load(checkProxyUrl(this, this._url)).then(function (dataSource) {
assignLayerIdToDataSourceEntites(dataSource.entities, that._id);
that._cesiumViewer.dataSources.add(dataSource);
deferred.resolve(that);
Expand All @@ -859,7 +890,7 @@
} else if (this._urlSuffix == 'czml') {
this._citydbKmlDataSource = new Cesium.CzmlDataSource();

this._citydbKmlDataSource.load(this._url).then(function (dataSource) {
this._citydbKmlDataSource.load(checkProxyUrl(this, this._url)).then(function (dataSource) {
assignLayerIdToDataSourceEntites(dataSource.entities, that._id);
cesiumViewer.dataSources.add(dataSource);
deferred.resolve(that);
Expand Down

0 comments on commit c736ba7

Please sign in to comment.