-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove more picking code in favor of derived commands. Add dev Sandca…
…stle example for picking.
- Loading branch information
Showing
10 changed files
with
292 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> | ||
<meta name="description" content="Picking."> | ||
<meta name="cesium-sandcastle-labels" content="Development"> | ||
<title>Cesium Demo</title> | ||
<script type="text/javascript" src="../Sandcastle-header.js"></script> | ||
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script> | ||
<script type="text/javascript"> | ||
require.config({ | ||
baseUrl : '../../../Source', | ||
waitSeconds : 60 | ||
}); | ||
</script> | ||
</head> | ||
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> | ||
<style> | ||
@import url(../templates/bucket.css); | ||
</style> | ||
<div id="cesiumContainer" class="fullSize"></div> | ||
<div id="loadingOverlay"><h1>Loading...</h1></div> | ||
<div id="toolbar"></div> | ||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
'use strict'; | ||
//Sandcastle_Begin | ||
var viewer = new Cesium.Viewer('cesiumContainer', { | ||
selectionIndicator : false, | ||
infoBox : false | ||
}); | ||
|
||
var scene = viewer.scene; | ||
var handler; | ||
|
||
Sandcastle.addToolbarButton('Pick billboard', function() { | ||
var entity = viewer.entities.add({ | ||
position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883), | ||
billboard : { | ||
image : '../images/Cesium_Logo_overlay.png' | ||
} | ||
}); | ||
|
||
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); | ||
handler.setInputAction(function(movement) { | ||
var pickedObject = scene.pick(movement.endPosition); | ||
if (Cesium.defined(pickedObject) && (pickedObject.id === entity)) { | ||
entity.billboard.color = Cesium.Color.YELLOW; | ||
} else { | ||
entity.billboard.color = Cesium.Color.WHITE; | ||
} | ||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
}); | ||
|
||
Sandcastle.addToolbarButton('Pick label', function() { | ||
var entity = viewer.entities.add({ | ||
position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883), | ||
label : { | ||
text : 'Label' | ||
} | ||
}); | ||
|
||
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); | ||
handler.setInputAction(function(movement) { | ||
var pickedObject = scene.pick(movement.endPosition); | ||
if (Cesium.defined(pickedObject) && (pickedObject.id === entity)) { | ||
entity.label.fillColor = Cesium.Color.YELLOW; | ||
} else { | ||
entity.label.fillColor = Cesium.Color.WHITE; | ||
} | ||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
}); | ||
|
||
Sandcastle.addToolbarButton('Pick point', function() { | ||
var entity = viewer.entities.add({ | ||
position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883), | ||
point : { | ||
color : Cesium.Color.WHITE, | ||
pixelSize : 15.0 | ||
} | ||
}); | ||
|
||
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); | ||
handler.setInputAction(function(movement) { | ||
var pickedObject = scene.pick(movement.endPosition); | ||
if (Cesium.defined(pickedObject) && (pickedObject.id === entity)) { | ||
entity.point.color = Cesium.Color.YELLOW; | ||
} else { | ||
entity.point.color = Cesium.Color.WHITE; | ||
} | ||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
}); | ||
|
||
Sandcastle.addToolbarButton('Pick polyline collection', function() { | ||
var polylines = scene.primitives.add(new Cesium.PolylineCollection()); | ||
var id = 'line'; | ||
var line = polylines.add({ | ||
positions : Cesium.Cartesian3.fromDegreesArrayHeights([ | ||
-84.0, 50.0, 0.0, | ||
-100.0, 30.0, 0.0 | ||
]), | ||
width : 5.0, | ||
id : id | ||
}); | ||
|
||
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); | ||
handler.setInputAction(function(movement) { | ||
var pickedObject = scene.pick(movement.endPosition); | ||
if (Cesium.defined(pickedObject) && (pickedObject.id === id)) { | ||
line.material.uniforms.color = Cesium.Color.YELLOW; | ||
} else { | ||
line.material.uniforms.color = Cesium.Color.WHITE; | ||
} | ||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
}); | ||
|
||
Sandcastle.addToolbarButton('Pick polyline geometry', function() { | ||
var id = 'line'; | ||
var primitive = scene.primitives.add(new Cesium.Primitive({ | ||
geometryInstances : new Cesium.GeometryInstance({ | ||
geometry : new Cesium.PolylineGeometry({ | ||
positions : Cesium.Cartesian3.fromDegreesArrayHeights([ | ||
-84.0, 50.0, 0.0, | ||
-100.0, 30.0, 0.0 | ||
]), | ||
width : 5.0, | ||
vertexFormat : Cesium.PolylineColorAppearance.VERTEX_FORMAT | ||
}), | ||
attributes: { | ||
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.WHITE) | ||
}, | ||
id : id | ||
}), | ||
appearance : new Cesium.PolylineColorAppearance(), | ||
asynchronous : false | ||
})); | ||
|
||
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); | ||
handler.setInputAction(function(movement) { | ||
var pickedObject = scene.pick(movement.endPosition); | ||
if (Cesium.defined(pickedObject) && (pickedObject.id === id)) { | ||
primitive.getGeometryInstanceAttributes(id).color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.YELLOW); | ||
} else { | ||
primitive.getGeometryInstanceAttributes(id).color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.WHITE); | ||
} | ||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
}); | ||
|
||
Sandcastle.addToolbarButton('Pick model', function() { | ||
var position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883); | ||
var hpr = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(135), 0, 0); | ||
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); | ||
|
||
var entity = viewer.entities.add({ | ||
position : position, | ||
orientation : orientation, | ||
model : { | ||
uri : '../../SampleData/models/CesiumAir/Cesium_Air.glb', | ||
minimumPixelSize : 256 | ||
} | ||
}); | ||
|
||
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); | ||
handler.setInputAction(function(movement) { | ||
var pickedObject = scene.pick(movement.endPosition); | ||
if (Cesium.defined(pickedObject) && (pickedObject.id === entity)) { | ||
entity.model.color = Cesium.Color.YELLOW; | ||
} else { | ||
entity.model.color = Cesium.Color.WHITE; | ||
} | ||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
}); | ||
|
||
Sandcastle.reset = function() { | ||
viewer.entities.removeAll(); | ||
handler = handler && handler.destroy(); | ||
}; | ||
//Sandcastle_End | ||
Sandcastle.finishedLoading(); | ||
} | ||
if (typeof Cesium !== "undefined") { | ||
startup(Cesium); | ||
} else if (typeof require === "function") { | ||
require(["Cesium"], startup); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.