$(function () {
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5ODI4ZTYyZS1mMTg2LTQ5NGEtYjdiOS02ODg2NzVhNjc0MTAiLCJpZCI6MjkwNCwiaWF0IjoxNTM1MTA5OTAzfQ.kyDX_0ScvJBkYnvXI0DW5NfZbiaRL5ezwtAUhxYnk1Y';
var imageryViewModels = [];
imageryViewModels.push(new Cesium.ProviderViewModel({
name: 'Sentinel-2',
iconUrl: Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/sentinel-2.png'),
tooltip: 'Sentinel-2 cloudless.',
creationFunction: function () {
return new Cesium.IonImageryProvider({ assetId: 3954 });
}
}));
imageryViewModels.push(new Cesium.ProviderViewModel({
name: 'Blue Marble',
iconUrl: Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/blueMarble.png'),
tooltip: 'Blue Marble Next Generation July, 2004 imagery from NASA.',
creationFunction: function () {
return new Cesium.IonImageryProvider({ assetId: 3845 });
}
}));
// var czml = [
// {
// id: "document",
// name: "CZML Colors",
// version: "1.0",
// },
// {
// id: "rgbaf",
// name: "Rectangle using RGBAF Colors",
// rectangle: {
// coordinates: { wsenDegrees: [ 9.188757 , 48.786944 , 9.192512, 48.787771 ] },
// fill: true,
// material: {
// solidColor: {
// color: {
// rgbaf: [1, 0, 0, 0.39],
// },
// },
// },
// height: 300, // disables ground clamping, needed for outlines
// outline: true,
// outlineColor: {
// rgba: [0, 0, 0, 255],
// },
// },
// },
// ];
// var czml = [{
// "id" : "document",
// "name" : "CZML Geometries: Polygon",
// "version" : "1.0"
// }, {
// "id" : "outlinedPolygon",
// "name" : "Outlined Polygon",
// "polygon" : {
// "positions" : {
// "cartographicDegrees" : [
// 9.189091, 48.786993, 0,
// 9.190604, 48.785855, 0,
// 9.191537, 48.785565, 0,
// 9.192889, 48.787438, 0,
// 9.194659, 48.78876, 0,
// 9.193114, 48.789997, 0
// ]
// },
// "material" : {
// "solidColor" : {
// "color" : {
// "rgba" : [255, 0, 0, 70]
// }
// }
// },
// "extrudedHeight" : 325,
// "perPositionHeight" : true,
// "outline" : true,
// "outlineColor" : {
// "rgba" : [255, 255, 0, 128]
// }
// }
// }];
var viewer = new Cesium.Viewer('cesiumContainer',
{
imageryProvider: new Cesium.IonImageryProvider({ assetId: 3954 }),
terrainProvider : new Cesium.CesiumTerrainProvider({
url: Cesium.IonResource.fromAssetId(1)
}),
scene3DOnly: false,
shouldAnimate: true,
animation: true,
infoBox: true,
baseLayerPicker: true,
fullscreenButton: false,
timeline: false,
navigationHelpButton: true,
navigationInstructionsInitiallyVisible: false,
homeButton: false,
selectionIndicator: true,
geocoder: true,
// imageryProviderViewModels: imageryViewModels
});
// var layer = viewer.imageryLayers.addImageryProvider(
// new Cesium.IonImageryProvider({ assetId: 3 })
// );
var imageryLayer = viewer.imageryLayers.addImageryProvider(
new Cesium.IonImageryProvider({ assetId: 3954 })
);
var canvas = viewer.canvas;
canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas
canvas.addEventListener('click', function() {
canvas.focus();
});
canvas.focus();
var scene = viewer.scene;
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: 'buildingTiles/StoeckachLOD1/tileset.json',
show: true
}));
tileset.readyPromise.then(function (tileset) {
return zoomAll(tileset);
});
tileset.readyPromise.then(function (tileset) {
var R = 0; // roll
var P = 0; // pitch
var Yaw = 0; // yaw
var height =53;
var cartographic = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.center);
var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height);
var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
//var rotMat = new Cesium.Matrix3();
var rotation = new Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(Yaw, P, R));
tileset.modelMatrix = Cesium.Matrix4.fromRotationTranslation(rotation,translation);
return zoomAll(tileset);
});
// tileset.style = new Cesium.Cesium3DTileStyle({
// see style at bottom~!!! around Line 443
//color: "color('cyan', 0.9)" });
var cfdStreams = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: 'results/ADACStreamlines/tileset.json',
show: true
}));
var camera = viewer.camera;
var controller = scene.screenSpaceCameraController;
var r = 0;
var center = new Cesium.Cartesian3();
var hpRoll = new Cesium.HeadingPitchRoll();
var hpRange = new Cesium.HeadingPitchRange();
var speed = 0.1;
var deltaRadians = Cesium.Math.toRadians(3.0);
var position = Cesium.Cartesian3.fromDegrees(9.190471, 48.786782, 0.0);
var speedVector = new Cesium.Cartesian3();
var fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west');
cfdStreams.style = new Cesium.Cesium3DTileStyle({
pointSize: 10
});
cfdStreams.readyPromise.then(function (cfdStreams) {
var R = 0.0; // roll
var P = 0; // pitch
var Yaw = 0; // yaw
var height = 320;
var cartographic = Cesium.Cartographic.fromCartesian(cfdStreams.boundingSphere.center);
var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height);
position = offset;
var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
//var rotMat = new Cesium.Matrix3();
var rotation = new Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(Yaw, P, R));
//cfdSim.modelMatrix = Cesium.Matrix4.fromRotationTranslation(rotation,new Cesium.Cartesian3(0,0,0));
cfdStreams.modelMatrix = Cesium.Matrix4.fromRotationTranslation(rotation,translation);
Cesium.Matrix4.multiplyByPoint(cfdStreams.model.modelMatrix,Cesium.Matrix4.fromRotationTranslation(rotation,translation), center);
//cfdSim.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(position,hpRoll,Cesium.Ellipsoid.WGS84,fixedFrameTransform)
var bla = center;
return zoomAll(cfdStreams);
});
viewer.scene.globe.enableLighting = true; // set lighting to true
var zoomAll = function (tileset) {
return new Promise(function (resolve, reject) {
if (!tileset) { reject("Tileset is undifined"); }
viewer.camera.viewBoundingSphere(tileset.boundingSphere, new Cesium.HeadingPitchRange(0, -0.5, 1500));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
resolve();
});
}
// HTML overlay for showing feature name on mouseover
var nameOverlay = document.createElement('div');
viewer.container.appendChild(nameOverlay);
nameOverlay.className = 'backdrop';
nameOverlay.style.display = 'none';
nameOverlay.style.position = 'absolute';
nameOverlay.style.bottom = '0';
nameOverlay.style.left = '0';
nameOverlay.style['pointer-events'] = 'none';
nameOverlay.style.padding = '4px';
nameOverlay.style.backgroundColor = 'green';
// var dataSourcePromise = Cesium.CzmlDataSource.load(czml);
// viewer.dataSources.add(dataSourcePromise);
/*
// Information about the currently selected feature
var selected = {
feature: undefined,
originalColor: new Cesium.Color()
};
// Information about the currently highlighted feature
var highlighted = {
feature: undefined,
originalColor: new Cesium.Color()
};
var selectedEntity = new Cesium.Entity();
// Color a feature yellow on hover.
viewer.screenSpaceEventHandler.setInputAction(function onMouseMove(movement) {
// If a feature was previously highlighted, undo the highlight
if (Cesium.defined(highlighted.feature)) {
highlighted.feature.color = highlighted.originalColor;
highlighted.feature = undefined;
}
// Pick a new feature
var pickedFeature = viewer.scene.pick(movement.endPosition);
if (!Cesium.defined(pickedFeature)) {
nameOverlay.style.display = 'none';
return;
}
// A feature was picked, so show it's overlay content
nameOverlay.style.display = 'block';
nameOverlay.style.bottom = viewer.canvas.clientHeight - movement.endPosition.y + 'px';
nameOverlay.style.left = movement.endPosition.x + 'px';
var name = pickedFeature.getProperty('name');
if (!Cesium.defined(name)) {
name = pickedFeature.getProperty('id');
}
nameOverlay.textContent = name;
// Highlight the feature if it's not already selected.
if (pickedFeature !== selected.feature) {
highlighted.feature = pickedFeature;
Cesium.Color.clone(pickedFeature.color, highlighted.originalColor);
pickedFeature.color = Cesium.Color.WHITE;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
// Color a feature on selection and show metadata in the InfoBox.
var clickHandler = viewer.screenSpaceEventHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
// If a feature was previously selected, undo the highlight
if (Cesium.defined(selected.feature)) {
selected.feature.color = selected.originalColor;
selected.feature = undefined;
}
// Pick a new feature
var pickedFeature = viewer.scene.pick(movement.position);
if (!Cesium.defined(pickedFeature)) {
clickHandler(movement);
return;
}
// Select the feature if it's not already selected
if (selected.feature === pickedFeature) {
return;
}
selected.feature = pickedFeature;
// Save the selected feature's original color
if (pickedFeature === highlighted.feature) {
Cesium.Color.clone(highlighted.originalColor, selected.originalColor);
highlighted.feature = undefined;
} else {
Cesium.Color.clone(pickedFeature.color, selected.originalColor);
}
// Highlight newly selected feature
pickedFeature.color = Cesium.Color.WHITE;
// Set feature infobox description
var featureName = pickedFeature.getProperty('name');
selectedEntity.name = featureName;
selectedEntity.description = 'Loading
';
viewer.selectedEntity = selectedEntity;
selectedEntity.description = '' +
'Bld function | ' + pickedFeature.getProperty('Function') + ' |
' +
'gmlID | ' + pickedFeature.getProperty('gmlIDStr') + ' |
' +
'Dachgeschossausbau | ' + pickedFeature.getProperty('dachgeschossausbau') + ' |
' +
'Lon | ' + pickedFeature.getProperty('Longitude') + ' |
' +
'Lat | ' + pickedFeature.getProperty('Latitude') + ' |
' +
'Geschossflaeche (sqm) | ' + pickedFeature.getProperty('geschossflaeche') + ' |
' +
'YearOfConstruction | ' + pickedFeature.getProperty('YearOfConstruction') + ' |
' +
'MeasuredHeight (m): | ' + pickedFeature.getProperty('MeasuredHeight') + ' |
' +
'HoeheFirst (m) | ' + pickedFeature.getProperty('hoeheFirst') + ' |
' +
'HoeheTrauf (m) | ' + pickedFeature.getProperty('hoeheTrauf') + ' |
' +
'Grundflaeche (sqm) | ' + pickedFeature.getProperty('grundflaeche') + ' |
' +
'StoreysAboveGround: | ' + pickedFeature.getProperty('StoreysAboveGround') + ' |
' +
'StoreysBelowGround: | ' + pickedFeature.getProperty('StoreysBelowGround') + ' |
' +
'Durchfahrtsstr.: | ' + pickedFeature.getProperty('ThoroughfareName') + ' |
' +
'Hausnummer.: | ' + pickedFeature.getProperty('ThoroughfareNumber') + ' |
' +
'
';
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
*/
var scene = viewer.scene;
var longitude;
var latitude;
var fid;
var featuretype;
var gmlid;
var selID = new Array();
var cnt = 0;
var lastPickedObject;
var viewModel = {
rightClickAction: 'properties',
middleClickAction: 'hide'
};
Cesium.knockout.track(viewModel);
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (movement) {
// makes camera go to a certain position given by the coordinates below
var feature = viewer.scene.pick(movement.position);
if (!Cesium.defined(feature)) {
console.log("no feature defined")
return;
}
var propertyNames = feature.getPropertyNames();
var lat = feature.getProperty("Latitude");
var lon = feature.getProperty("Longitude");
var tmp = feature.getProperty("YearOfConstruction");
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(lon, lat, 900),
maximumHeight: 1500.0,
orientation: {
heading: Cesium.Math.toRadians(0.0),
pitch: Cesium.Math.toRadians(-90.0),
roll: Cesium.Math.toRadians(45.0)
},
duration: 2
}); }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
handler.setInputAction(function (movement) {
var feature = viewer.scene.pick(movement.position);
if (!Cesium.defined(feature)) {
return;
}
var action = viewModel.rightClickAction;
action === 'properties'
printProperties(movement, feature)
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
function printProperties(movement, feature) {
console.log('Properties:');
var propertyNames = feature.getPropertyNames();
var length = propertyNames.length;
for (var i = 0; i < length; ++i) {
var propertyName = propertyNames[i];
if (propertyName == 'gmlIdALKISLageBezeichnung_1' ||
propertyName == 'gmlIdALKISLageBezeichnung_2' ||
propertyName == 'gmlIdALKISLageBezeichnung_3' ||
propertyName == 'gmlIdALKISLageBezeichnung_4' ||
propertyName == 'gmlIdALKISLageBezeichnung_5' ||
propertyName == 'gmlIdALKISLageBezeichnung_6')
console.log(' ' + propertyName + ': ' + 'zensiert');
else
console.log(' ' + propertyName + ': ' + feature.getProperty(propertyName));
}
// Evaluate feature description
//console.log('Description : ' + tileset.style.meta.description.evaluate(scene.frameState, feature));
}
handler.setInputAction(function (movement) {
var feature = viewer.scene.pick(movement.position);
if (!Cesium.defined(feature)) {
return;
}
var action = viewModel.middleClickAction;
if (action === 'hide') {
feature.show = false;
}
else{
feature.show = true;
}
}, Cesium.ScreenSpaceEventType.MIDDLE_CLICK);
function showLegend() {
$("#legend").css("display", "block");
}
function hideLegend() {
$("#legend").css("display", "none");
}
// Legend - Colour Table
function emptyColourTable() {
$(".inner").empty();
}
function setHeightTable() {
$(".inner").append( "" +
" | > 3.5 |
" +
" | 3 |
" +
" | 2.5 |
" +
" | 2 |
" +
" | 1.5 |
" +
" | 1 |
" +
" | 0.5 |
" +
"
" );
}
return Cesium.when(tileset.readyPromise).then(function (tileset) {
tileset.style = new Cesium.Cesium3DTileStyle({
color: "color('white',1)",
});
showLegend();
setHeightTable();
});
});