// update cesium Container Width to fit the Web Frame after document ready
$(document).ready(function () {
// $("#cesiumContainer").css("width", "auto");
$('#loading').hide();
// $( window ).resize(function() {
// $("#cesiumContainer").css("width", "auto");
// });
});
var PVPotential_legend_context = `
PV Potential MWh/year
> 30
25 - 30
20 - 25
15 - 20
10 - 15
5 - 10
0 - 5
`
// var PVPotential_legend_context = `
// PV Potential MW⋅hel
// >= 8
// 7 - 8
// 6 - 7
// 5 - 6
// 4 - 5
// 3 - 4
// 2 - 3
// 1 - 2
// 0 - 1
//
// `
if ($("#PVPotential-legend").length > 0) {
$("#PVPotential-legend").html(PVPotential_legend_context) // Add Bioenergy menu if the "#id" exist
}
var PVSpecificYield_legend_context = `
PV Specific Yield (kWh/kWp.year)
> 1100
1050 - 1100
1000 - 1050
950 - 1000
900 - 950
850 - 900
< 850
`
if ($("#PVSpecificYield-legend").length > 0) {
$("#PVSpecificYield-legend").html(PVSpecificYield_legend_context) // Add Bioenergy menu if the "#id" exist
}
// set the Cesium ION token
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkZTkyOTcyNC0yMGFkLTQ2ZjktODA5YS0xYjY1N2QwM2Y2ZmMiLCJpZCI6NDM2NDUsImlhdCI6MTYxMjkyNDgwNX0.12Xvbhtt_c2Y2RGA6J_J906Vdn1iOKZKPur0SASh-gk';
var viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider: Cesium.createWorldTerrain(),
baseLayerPicker: false,
vrButton: false,
geocoder: true,
navigationHelpButton: false,
selectionIndicator: true,
shadows: false,
timeline: false,
sceneModePicker: false,
homeButton: false,
fullscreenButton: true,
infoBox: true,
imageryProvider: new Cesium.MapboxStyleImageryProvider({
// check style ID at https://docs.mapbox.com/api/maps/styles/
// styleId: 'dark-v10',
styleId: 'light-v10',
// styleId: 'navigation-day-v1',
accessToken: 'pk.eyJ1IjoidGh1bnlhdGhlcCIsImEiOiJjamFpOWV4a2gxd21vMndxdXd2M3VoY3hmIn0.jLlCscei0yH-ZHwcfxF_ug'
})
// terrainExaggeration: 1.5,
});
var tileset = viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(75343),
})
);
viewer.camera.setView({
"destination": {
"x": 4123560.966179314,
"y": 707228.713304919,
"z": 4798899.985567952
},
"orientation": {
"direction": {
"x": -0.9622773420432754,
"y": 0.19744630073107838,
"z": 0.18718246530522495
},
"up": {
"x": 0.23048908682520655,
"y": 0.22606307618215207,
"z": 0.946451407332434
}
}
})
// binding full screen button
$("#full-screen-button").click(function () {
Cesium.Fullscreen.requestFullscreen(document.body)
})
Cesium.GeoJsonDataSource.clampToGround = true;
// Adding the Utility Line to the Cesium Viewer
var utility_line;
var load_utility_line_already = false;
var utiltiy_line_entity;
var load_utility_line = function () {
$("#util_nw_line_loading").show()
if (!load_utility_line_already) {
GeoJSONpromise = Cesium.GeoJsonDataSource.load(
"../utility_data/Katharinenvorst.geojson"
);
GeoJSONpromise.then(function (dataSource) {
utiltiy_line_entity = dataSource.entities;
viewer.dataSources.add(dataSource);
//Get the array of entities
utility_line = dataSource.entities.values;
load_utility_line_already = true;
for (let i = 0; i < utility_line.length; i++) {
const entity = utility_line[i];
entity.polyline.clampToGround = true
entity.polyline.classificationType = Cesium.ClassificationType.TERRAIN;
entity.polyline.material = Cesium.Color.HOTPINK;
}
$("#util_nw_line_loading").hide()
})
} else {
utiltiy_line_entity.show = true;
}
}
var hide_utiltiy_line = function () {
try {
utiltiy_line_entity.show = false;
load_utility_line_already = false;
} catch (error) {
console.log("error on hiding utiltiy_line_entity")
}
}
viewer.camera.setView({
"destination": {
"x": -3447610.163256134,
"y": 4035558.08021155,
"z": 3526721.814467922
},
"orientation": {
"direction": {
"x": -0.3228353906545565,
"y": -0.9232459949887203,
"z": 0.2083126095036207
},
"up": {
"x": -0.663817634371156,
"y": 0.3777599007354034,
"z": 0.6454793611683185
}
}
})
var building_style = []
var addBuilding = function () {
try {
tileset_3Dbuildings = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
// url: 'https://steinbeis-3dps.eu/3DGeoVolumes/collections/schwabisch_hall_city/tileset.json',
url: 'assets/data/japan/tileset.json',
maximumScreenSpaceError: 8 // default value
}));
} catch (err) {
console.log('-> add 3DTiles failed!\n' + err);
}
tileset_3Dbuildings.readyPromise.then(function () {
// var boundingSphere = tileset_3Dbuildings.boundingSphere;
// var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
// var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
// var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 50);
// var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
// tileset_3Dbuildings.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
// viewer.flyTo(tileset_3Dbuildings)
});
// Styling the 3d model
building_style["AllWhite"] = new Cesium.Cesium3DTileStyle({
pointSize: '3.0',
show: true,
// color: "color('#ffffff')"
"color": {
"conditions": [
["true", "color('#ffffff')"]
]
}
});
building_style["transparent"] = new Cesium.Cesium3DTileStyle({
show: true,
// color: "color('#ffffff',0.25)"
"color": {
"conditions": [
["true", "color('#ffffff', 0.75)"]
]
}
});
building_style["PVPotential"] = new Cesium.Cesium3DTileStyle({
show: true,
color: {
"conditions": [
['Number(${PV_potential_yield}) < 5', `color("#FFFFD4")`],
['Number(${PV_potential_yield}) < 10', `color("#FEE391")`],
['Number(${PV_potential_yield}) < 15', `color("#FEC44F")`],
['Number(${PV_potential_yield}) < 20', `color("#FE9929")`],
['Number(${PV_potential_yield}) < 25', `color("#EC7014")`],
['Number(${PV_potential_yield}) < 30', `color("#CC4C02")`],
['Number(${PV_potential_yield}) >= 30', `color("#8C2D04")`],
["true", "color('#ffffff')"] //no data
]
}
});
building_style["PVSpecificYield"] = new Cesium.Cesium3DTileStyle({
show: true,
color: {
"conditions": [
['Number(${PV_specific_yield}) < 850', `color("#FFFFD4")`],
['Number(${PV_specific_yield}) < 900', `color("#FEE391")`],
['Number(${PV_specific_yield}) < 950', `color("#FEC44F")`],
['Number(${PV_specific_yield}) < 1000', `color("#FE9929")`],
['Number(${PV_specific_yield}) < 1050', `color("#EC7014")`],
['Number(${PV_specific_yield}) < 1100', `color("#CC4C02")`],
['Number(${PV_specific_yield}) >= 1100 ', `color("#8C2D04")`],
["true", "color('#ffffff')"] //no data
]
}
});
building_style["ElecDemand"] = new Cesium.Cesium3DTileStyle({
show: true,
color: {
"conditions": [
["${Electric_Demand} === 0", "color('#ffffff')"],
["${Electric_Demand} < 3229", "color('#feedde')"],
["${Electric_Demand} < 4229", "color('#fdd0a2')"],
["${Electric_Demand} < 5229", "color('#fdae6b')"],
["${Electric_Demand} < 6229", "color('#fd8d3c')"],
["${Electric_Demand} < 7229", "color('#e6550d')"],
["true", "color('#a63603', 0.5)"]
]
}
});
building_style["height"] = new Cesium.Cesium3DTileStyle({
show: true,
color: {
"conditions": [
["Number(${計測高さ}) < 5", "color('#ffffcc')"],
["Number(${計測高さ}) < 10", "color('#a1dab4')"],
["Number(${計測高さ}) < 20", "color('#41b6c4')"],
["Number(${計測高さ}) < 30", "color('#2c7fb8')"],
["Number(${計測高さ}) >= 30", "color('#253494')"],
["true", "color('#E8F1F2', 0.5)"]
]
}
});
// tileset_3Dbuildings.style = building_style["AllWhite"];
tileset_3Dbuildings.style = building_style["height"];
};
addBuilding();
// adding input to the menu
var layerIsLoaded = []
var layerIsLoadedFirstTime = []
var promise = []
var datasources = []
var datasource = []
// for (i = 0; i < geoJSONLayer.length; i++) {
// var layerName = geoJSONLayer[i]
// var htmlInput = `
//
//
//
// `
// layerIsLoadedFirstTime[layerName] = false
// $("#inputContainer").append(htmlInput);
// }
// $(`.GeoJSONlayerCheckbox`).click(function () {
// var layerName = $(this).attr('id')
// if (!layerIsLoadedFirstTime[layerName]) {
// var pathName = `../data/geojson/${layerName}.geojson`
// if (geoJSONLayerStyle.hasOwnProperty(layerName)) {
// promise[layerName] = Cesium.GeoJsonDataSource.load(pathName, geoJSONLayerStyle[layerName]);
// } else {
// promise[layerName] = Cesium.GeoJsonDataSource.load(pathName);
// }
// // if
// promise[layerName]
// .then(function (dataSource) {
// datasource[layerName] = dataSource
// layerIsLoadedFirstTime[layerName] = true
// datasources[layerName] = viewer.dataSources.add(dataSource);
// var layerEntities = datasource[layerName].entities.values;
// for (var i = 0; i < layerEntities.length; i++) {
// var entity = layerEntities[i];
// entity.name = layerName
// }
// viewer.flyTo(dataSource) // fly to dataSource after loading
// // more info https://sandcastle.cesium.com/index.html?src=GeoJSON%2520and%2520TopoJSON.html
// // more info https://cesium.com/docs/tutorials/cesium-workshop/
// })
// .otherwise(function (error) {
// //Display any errrors encountered while loading.
// window.alert(error);
// });
// } else if (this.checked && layerIsLoadedFirstTime[layerName]) {
// viewer.dataSources.add(datasource[layerName]);
// } else {
// viewer.dataSources.remove(datasource[layerName]);
// }
// });
//time management
Date.prototype.toIsoString_Start = function () {
var tzo = -this.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-',
pad = function (num) {
var norm = Math.floor(Math.abs(num));
return (norm < 10 ? '0' : '') + norm;
};
return this.getFullYear() +
'-' + pad(this.getMonth() + 1) +
'-' + pad(this.getDate()) +
'T' + '08:00:00Z'
}
Date.prototype.toIsoString_Stop = function () {
var tzo = -this.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-',
pad = function (num) {
var norm = Math.floor(Math.abs(num));
return (norm < 10 ? '0' : '') + norm;
};
return this.getFullYear() +
'-' + pad(this.getMonth() + 1) +
'-' + pad(this.getDate()) +
'T' + '23:00:00Z'
}
var dateEvent = new Date()
var startTime = dateEvent.toIsoString_Start();
var stopTime = dateEvent.toIsoString_Stop();
viewer.clock.currentTime = Cesium.JulianDate.fromIso8601(startTime);
$('#BuildingStyleSelector').on('change', function () {
// alert(this.value);
tileset_3Dbuildings.style = building_style[this.value];
$('.cesiumLegend').hide()
try {
$(`#${this.value}-legend`).show()
// draw Chart
activateChart(this.value);
} catch (error) {
console.log(`No ${this.value} Style in the html`)
}
});
$("#shadow_check").change(function () {
if (this.checked) {
viewer.shadows = true
} else {
viewer.shadows = false
}
});
// $("#util_nw_line").change(function () {
// if (this.checked) {
// load_utility_line()
// } else {
// hide_utiltiy_line()
// }
// });
// $("#util_nw_point").change(function () {
// if (this.checked) {
// for (let i = 0; i < utility_point.length; i++) {
// utility_Point_Entities[i].point.show = true;
// utility_Point_Entities[i].label.show = true;
// }
// } else {
// for (let i = 0; i < utility_point.length; i++) {
// utility_Point_Entities[i].point.show = false;
// utility_Point_Entities[i].label.show = false;
// }
// }
// });