|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
| 6 | + <meta |
| 7 | + name="viewport" |
| 8 | + content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" |
| 9 | + /> |
| 10 | + <meta |
| 11 | + name="description" |
| 12 | + content="Use Viewer to start building new applications or easily embed Cesium into existing applications." |
| 13 | + /> |
| 14 | + <meta name="cesium-sandcastle-labels" content="Beginner, Showcases" /> |
| 15 | + <title>iTwin Feature Service</title> |
| 16 | + <script type="text/javascript" src="../Sandcastle-header.js"></script> |
| 17 | + <script type="module" src="../load-cesium-es6.js"></script> |
| 18 | + </head> |
| 19 | + <body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> |
| 20 | + <style> |
| 21 | + @import url(../templates/bucket.css); |
| 22 | + </style> |
| 23 | + <div id="cesiumContainer" class="fullSize"></div> |
| 24 | + <div id="loadingOverlay"><h1>Loading...</h1></div> |
| 25 | + <div id="toolbar"> |
| 26 | + <div id="layers"></div> |
| 27 | + </div> |
| 28 | + <script id="cesium_sandcastle_script"> |
| 29 | + window.startup = async function (Cesium) { |
| 30 | + "use strict"; |
| 31 | + //Sandcastle_Begin |
| 32 | + const serviceResponse = await fetch("https://api.cesium.com/itwin/token"); |
| 33 | + const { access_token: token } = await serviceResponse.json(); |
| 34 | + |
| 35 | + Cesium.ITwinPlatform.defaultAccessToken = token; |
| 36 | + |
| 37 | + const iTwinId = "04ba725f-f3c0-4f30-8014-a4488cbd612d"; |
| 38 | + |
| 39 | + const viewer = new Cesium.Viewer("cesiumContainer", { |
| 40 | + geocoder: false, |
| 41 | + sceneModePicker: false, |
| 42 | + homeButton: false, |
| 43 | + timeline: false, |
| 44 | + animation: false, |
| 45 | + }); |
| 46 | + viewer.baseLayerPicker.viewModel.selectedImagery = |
| 47 | + viewer.baseLayerPicker.viewModel.imageryProviderViewModels[2]; |
| 48 | + |
| 49 | + const birdsEyeView = { |
| 50 | + destination: new Cesium.Cartesian3( |
| 51 | + -1525359.4318772827, |
| 52 | + 6191643.528984093, |
| 53 | + 148851.5321709012, |
| 54 | + ), |
| 55 | + orientation: new Cesium.HeadingPitchRoll( |
| 56 | + 0.16657338935967037, |
| 57 | + -0.7943050121851765, |
| 58 | + 6.283180723449992, |
| 59 | + ), |
| 60 | + duration: 0, |
| 61 | + easingFunction: Cesium.EasingFunction.LINEAR_NONE, |
| 62 | + }; |
| 63 | + viewer.scene.camera.flyTo(birdsEyeView); |
| 64 | + |
| 65 | + // Load feature service geojson files |
| 66 | + const points = await Cesium.ITwinData.createDataSourceForRealityDataId( |
| 67 | + iTwinId, |
| 68 | + "57b975f6-fd92-42ba-8014-79911ed606d1", |
| 69 | + ); |
| 70 | + const lines = await Cesium.ITwinData.createDataSourceForRealityDataId( |
| 71 | + iTwinId, |
| 72 | + "1099c53f-c568-48a3-a57c-0230a6f37229", |
| 73 | + ); |
| 74 | + const areas = await Cesium.ITwinData.createDataSourceForRealityDataId( |
| 75 | + iTwinId, |
| 76 | + "21eaf0d0-ab90-400f-97cf-adc455b29a78", |
| 77 | + ); |
| 78 | + |
| 79 | + // Add some styling to the lines and points to differentiate types |
| 80 | + const pinBuilder = new Cesium.PinBuilder(); |
| 81 | + points.entities.values.forEach(async (entity) => { |
| 82 | + const styleByType = { |
| 83 | + Tree: { color: Cesium.Color.GREEN, icon: "park2" }, |
| 84 | + Lamp_post: { color: Cesium.Color.WHITE, icon: "lighthouse" }, |
| 85 | + Traffic_light: { color: Cesium.Color.CRIMSON, icon: "circle-stroked" }, |
| 86 | + Arrow_Marking: { color: Cesium.Color.YELLOW, icon: "car" }, |
| 87 | + Road_Sign: { color: Cesium.Color.ORANGE, icon: "triangle" }, |
| 88 | + }; |
| 89 | + const type = entity.properties.Type?.getValue(); |
| 90 | + if (Cesium.defined(type) && Cesium.defined(styleByType[type])) { |
| 91 | + const { color, icon } = styleByType[type]; |
| 92 | + const canvas = await pinBuilder.fromMakiIconId(icon, color, 48); |
| 93 | + entity.billboard.image = canvas.toDataURL(); |
| 94 | + entity.billboard.verticalOrigin = Cesium.VerticalOrigin.BOTTOM; |
| 95 | + } |
| 96 | + }); |
| 97 | + lines.entities.values.forEach((entity) => { |
| 98 | + const lineColorsByType = { |
| 99 | + Contours: Cesium.Color.CRIMSON, |
| 100 | + Lane_Marking: Cesium.Color.CYAN, |
| 101 | + Kerb: Cesium.Color.BLUEVIOLET, |
| 102 | + Chevron_marking: Cesium.Color.DARKORANGE, |
| 103 | + Turning_pocket: Cesium.Color.DEEPPINK, |
| 104 | + Yellow_Box: Cesium.Color.GOLD, |
| 105 | + }; |
| 106 | + const type = entity.properties.Type?.getValue(); |
| 107 | + if (Cesium.defined(type) && Cesium.defined(lineColorsByType[type])) { |
| 108 | + entity.polyline.material = lineColorsByType[type]; |
| 109 | + } |
| 110 | + }); |
| 111 | + |
| 112 | + // add the geojsons to the viewer |
| 113 | + viewer.dataSources.add(points); |
| 114 | + viewer.dataSources.add(lines); |
| 115 | + viewer.dataSources.add(areas); |
| 116 | + |
| 117 | + // Create tileset of the reality data mesh and pointcloud |
| 118 | + const realityMeshId = "62e4432d-621d-489a-87ff-1fc56a2b5369"; |
| 119 | + const realityMesh = await Cesium.ITwinData.createTilesetForRealityDataId( |
| 120 | + iTwinId, |
| 121 | + realityMeshId, |
| 122 | + ); |
| 123 | + viewer.scene.primitives.add(realityMesh); |
| 124 | + const pointcloudId = "ebf2ee74-f0de-4cd6-a311-19a169c55fdc"; |
| 125 | + const pointcloud = await Cesium.ITwinData.createTilesetForRealityDataId( |
| 126 | + iTwinId, |
| 127 | + pointcloudId, |
| 128 | + ); |
| 129 | + // increase the size of the pointcloud points and turn on attenuation to |
| 130 | + // make them more visible in the viewer |
| 131 | + pointcloud.maximumScreenSpaceError = 1; |
| 132 | + pointcloud.pointCloudShading.attenuation = true; |
| 133 | + pointcloud.style = new Cesium.Cesium3DTileStyle({ |
| 134 | + pointSize: 5.0, |
| 135 | + }); |
| 136 | + pointcloud.show = false; |
| 137 | + viewer.scene.primitives.add(pointcloud); |
| 138 | + |
| 139 | + Sandcastle.addToolbarButton( |
| 140 | + "Toggle Points", |
| 141 | + () => (points.show = !points.show), |
| 142 | + "layers", |
| 143 | + ); |
| 144 | + Sandcastle.addToolbarButton( |
| 145 | + "Toggle Lines", |
| 146 | + () => (lines.show = !lines.show), |
| 147 | + "layers", |
| 148 | + ); |
| 149 | + Sandcastle.addToolbarButton( |
| 150 | + "Toggle Areas", |
| 151 | + () => (areas.show = !areas.show), |
| 152 | + "layers", |
| 153 | + ); |
| 154 | + Sandcastle.addToolbarButton( |
| 155 | + "Toggle Reality Mesh", |
| 156 | + () => (realityMesh.show = !realityMesh.show), |
| 157 | + "layers", |
| 158 | + ); |
| 159 | + Sandcastle.addToolbarButton( |
| 160 | + "Toggle Pointcloud", |
| 161 | + () => (pointcloud.show = !pointcloud.show), |
| 162 | + "layers", |
| 163 | + ); |
| 164 | + |
| 165 | + Sandcastle.addToolbarButton("Birdseye View", () => { |
| 166 | + viewer.scene.camera.flyTo(birdsEyeView); |
| 167 | + }); |
| 168 | + Sandcastle.addToolbarButton("Zoom to Pointcloud", () => { |
| 169 | + pointcloud.show = true; |
| 170 | + viewer.zoomTo(pointcloud); |
| 171 | + }); |
| 172 | + //Sandcastle_End |
| 173 | + Sandcastle.finishedLoading(); |
| 174 | + }; |
| 175 | + if (typeof Cesium !== "undefined") { |
| 176 | + window.startupCalled = true; |
| 177 | + window.startup(Cesium).catch((error) => { |
| 178 | + "use strict"; |
| 179 | + console.error(error); |
| 180 | + }); |
| 181 | + } |
| 182 | + </script> |
| 183 | + </body> |
| 184 | +</html> |
0 commit comments