Thank you for clarifying. We currently don’t have a method for specifying which entities can be picked. We have an issue written up about that here: https://github.com/AnalyticalGraphicsInc/cesium/issues/1592
It is one of the more frequently requested features so hopefully someone will be able to take a look at that soon.
You would also have to write custom code to resize a rectangle. We don’t have any drawing capabilities built in at this time. A common solution we see is to use a point as a drag handle.
Here’s an example of using a point to drag the west side of a rectangle using entites:
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var west = -110;
var south = 20;
var east = -100;
var north = 25;
var redRectangle = viewer.entities.add({
rectangle : {
coordinates : new Cesium.CallbackProperty(function() {
return Cesium.Rectangle.fromDegrees(west, south, east, north);
}, false),
material : Cesium.Color.RED.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.RED
}
});
var point = viewer.entities.add({
position : new Cesium.CallbackProperty(function() {
return Cesium.Cartesian3.fromDegrees(west, (north + south) / 2);
}, false),
point : {
pixelSize : 10,
color : Cesium.Color.YELLOW
}
});
var dragging;
var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
handler.setInputAction(function(click) {
var pickedObject = viewer.scene.pick(click.position);
if (Cesium.defined(pickedObject) && pickedObject.id === point) {
dragging = pickedObject;
viewer.scene.screenSpaceCameraController.enableRotate = false;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
handler.setInputAction(function() {
if (Cesium.defined(dragging)) {
dragging = undefined;
viewer.scene.screenSpaceCameraController.enableRotate = true;
}
}, Cesium.ScreenSpaceEventType.LEFT_UP);
handler.setInputAction(function(movement) {
var position = viewer.camera.pickEllipsoid(movement.endPosition);
if (!Cesium.defined(position) || !dragging) {
return;
}
var positionCartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
west = Cesium.Math.toDegrees(positionCartographic.longitude);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
viewer.zoomTo(viewer.entities);
``
Using a CallbackProperty for the positions tells Cesium to draw those shapes synchronously, which prevents lag when dragging around the point. You could easily use a billboard to drag instead of using a point.
Best,
Hannah