<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version. -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Hello World!</title>
<script src="../Build/Cesium/Cesium.js"></script>
<style>
@import url(../Build/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
}
#toolbar {
background: rgba(42, 42, 42, 0.8);
padding: 4px;
border-radius: 4px;
}
#toolbar input {
vertical-align: middle;
padding-top: 2px;
padding-bottom: 2px;
}
#toolbar .header {
font-weight: bold;
}
h2 {
color: black;
}
p {
color: black;
}
</style>
</head>
<body>
<div id="toolbar">
<input type="checkbox" value="false" data-bind="checked: debugBoundingVolumesEnabled, valueUpdate: 'input'" id="showCheckbox"> Àmbit
<input type="checkbox" value="true" data-bind="checked: edgeStylingEnabled, valueUpdate: 'input'" id="showCheckbox1"> 3dBuildings
</div>
<div id="cesiumContainer"></div>
<script>
var extent = Cesium.Rectangle.fromDegrees(2.200423178619758, 41.427599, 2.210423178619758, 41.417599);
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = extent;
Cesium.Camera.DEFAULT_VIEW_FACTOR = 0;
var terrain = Cesium.createDefaultTerrainProviderViewModels();
var viewer = new Cesium.Viewer('cesiumContainer', {
mapProjection : new Cesium.WebMercatorProjection(),
timeline: false,
animation: false,
baseLayerPicker: true,
scene3DOnly: true,
terrainProviderViewModels: terrain,
selectedTerrainProviderViewModel: terrain[1]
//shadows:true
});
var initialPosition = Cesium.Cartesian3.fromDegrees (2.200423178619758, 41.417599, 1000);
var initialOrientation = new Cesium.HeadingPitchRoll.fromDegrees(21.27879878293835, -21.34390550872461, 0.0716951918898415);
viewer.scene.camera.setView({
destination: initialPosition,
orientation: initialOrientation,
endTransform: Cesium.Matrix4.IDENTITY
});
Cesium.GeoJsonDataSource.clampToGround = true;
var ambit = new Cesium.GeoJsonDataSource(); ambit.load('SampleData/ambit5.json',{
stroke: Cesium.Color.BLACK,
fill:Cesium.Color.RED.withAlpha(0.1),
strokeWidth: 50,
markerSymbol: '?'
});
var botoambit = document.getElementById('showCheckbox');
botoambit.addEventListener('change', function() {
if (botoambit.checked) {
// Show if not shown.
if (!viewer.dataSources.contains(ambit)) {
viewer.dataSources.add(ambit);
}
} else {
if (viewer.dataSources.contains(ambit)) {
viewer.dataSources.remove(ambit);
}
}
}, false);
var edificis = new Cesium.Cesium3DTileset({ url: 'SampleData/model_bo/tileset.json' });
tileset = viewer.scene.primitives.add(edificis);
edificis.show=false;
var botoedificis = document.getElementById('showCheckbox1');
botoedificis.addEventListener('change', function() {
if (botoedificis.checked) {
// Show if not shown.
if (!viewer.dataSources.contains(edificis)) {
edificis.show=true;
}
} else {
edificis.show=false;
}
}, false);
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 = 'white';
// 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()
};
// An entity object which will hold info about the currently selected feature for infobox display
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('REFCAT');
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.YELLOW;
}
}, 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.LIME;
// Set feature infobox description
var featureName = pickedFeature.getProperty('REFCAT');
selectedEntity.name = featureName;
selectedEntity.description = 'Loading <div class="cesium-infoBox-loading"></div>';
viewer.selectedEntity = selectedEntity;
selectedEntity.description = '<table class="cesium-infoBox-defaultTable"><tbody>' +
'<tr><th>PLAN</th><td>' + pickedFeature.getProperty('PLAN_') + '</td></tr>' +
'<tr><th>DESCRIPCIO</th><td>' + pickedFeature.getProperty('DESCRIP_12') + '</td></tr>' +
'<tr><th>PARCELA</th><td>' + pickedFeature.getProperty('PARCELA') + '</td></tr>' +
'<tr><th>AREA</th><td>' + pickedFeature.getProperty('AREA') + '</td></tr>' +
'<tr><th>CODI INE</th><td>' + pickedFeature.getProperty('CODI_INE') + '</td></tr>' +
'<tr><th>COORX</th><td>' + pickedFeature.getProperty('COORX') + '</td></tr>' +
'<tr><th>COORY</th><td>' + pickedFeature.getProperty('COORY') + '</td></tr>' +
'<tr><th>DELEGACIO</th><td>' + pickedFeature.getProperty('DELEGACIO') + '</td></tr>' +
'<tr><th>DATAALTA</th><td>' + pickedFeature.getProperty('FECHAALTA') + '</td></tr>' +
'<tr><th>MASSA</th><td>' + pickedFeature.getProperty('MASA') + '</td></tr>' +
'<tr><th>NOM_MUNICIPI</th><td>' + pickedFeature.getProperty('NOMMUNI_1') + '</td></tr>' +
'<tr><th>NORMATIVA</th><td>' + pickedFeature.getProperty('NORMATIV') + '</td></tr>' +
'<tr><th>NUMERO</th><td>' + pickedFeature.getProperty('NUMERO') + '</td></tr>' +
'<tr><th>PGM</th><td>' + pickedFeature.getProperty('PGM') + '</td></tr>' +
'<tr><th>VIA</th><td>' + pickedFeature.getProperty('VIA') + '</td></tr>' +
'<tr><th>ZMAX</th><td>' + pickedFeature.getProperty('Z_Max') + '</td></tr>' +
'<tr><th>ZMIN</th><td>' + pickedFeature.getProperty('Z_Min') + '</td></tr>' +
'</tbody></table>';
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
tileset.style = new Cesium.Cesium3DTileStyle({
color : {
conditions : [
["(${DESCRIP_12}) === 'Zona industrial'","rgb(250,0,0)"] ,
["String(${DESCRIP_12}) === 'Densificacio Urbana Semiintensiva'","rgb(250, 100, 0)"] ,
["String(${DESCRIP_12}) === 'Equipaments comunitaris i dotacions'","rgb(66, 8, 181)"] ,
["String(${DESCRIP_12}) === 'Equipaments en Ordenacio en volumetria especifica'","rgb(66, 135, 181)"] ,
["String(${DESCRIP_12}) === 'Ordenacio'","rgb(155, 135, 181)"] ,
["String(${DESCRIP_12}) === 'Ordenacio en volumetria especifica'","rgb(155, 100, 118)"] ,
["String(${DESCRIP_12}) === 'Ordenacio en volumetria especifica en centre direccional'","rgb(155, 100, 75)"] ,
["String(${DESCRIP_12}) === 'Ordenaciol en filera'","rgb(155, 109, 9)"] ,
["String(${DESCRIP_12}) === 'Parcs i jardins urbans'","rgb(156, 204, 43)"] ,
["String(${DESCRIP_12}) === 'Proteccia de sistemes generals'","rgb(110, 129, 140)"] ,
["String(${DESCRIP_12}) === 'Renovacia urbana: transformacio'","rgb(188, 251, 41)"] ,
["String(${DESCRIP_12}) === 'Sistema de serveis tecnics'","rgb(15, 75, 41)"] ,
["String(${DESCRIP_12}) === 'Sistema ferroviari'","rgb(222, 75, 181)"] ,
["String(${DESCRIP_12}) === 'Sistema portuari'","rgb(15, 75, 181)"] ,
["String(${DESCRIP_12}) === 'Sistema portuari - Zona maritimo-terrestre'","rgb(1, 216, 255)"] ,
["String(${DESCRIP_12}) === 'Sistema viari basic'","rgb(189, 216, 255)"] ,
["true", 'color("white")']
]
}
/*color : {
conditions : [
["Number(${MUNICIPIO}) = 245", "rgb(250,0,0)"]
]
}*/
});
var heightOffset = 50;
tileset.readyPromise.then(function(tileset) {
var boundingSphere = tileset.boundingSphere;
//viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0, -2.0, 0));
//viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
// Position tileset
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, heightOffset);
var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
console.log(tileset.modelMatrix);
});
</script>
</body>
</html>