//添加polyline
function addPolyLine(){
//初始化
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
var positions = [];
var poly = undefined;
//封装polyline对象
var PolyLinePrimitive = (function(){
function _(positions){
this.options = {
polyline : {
show : true,
positions : [],
material : Cesium.Color.CORNFLOWERBLUE,
width : 5
}
};
this.positions = positions;
this._init();
}
_.prototype._init = function(){
var _self = this;
var _update = function(){
return _self.positions;
};
//实时更新polyline.positions
this.options.polyline.positions = new Cesium.CallbackProperty(_update,false);
viewer.entities.add(this.options);
};
return _;
})();
handler.setInputAction(function(movement){
var cartesian = scene.camera.pickEllipsoid(movement.position,scene.globe.ellipsoid);
if(positions.length == 0) {
positions.push(cartesian.clone());
}
positions.push(cartesian);
},Cesium.ScreenSpaceEventType.LEFT_CLICK);
handler.setInputAction(function(movement){
var cartesian = scene.camera.pickEllipsoid(movement.endPosition,scene.globe.ellipsoid);
if(positions.length >= 2){
if (!Cesium.defined(poly)) {
poly = new PolyLinePrimitive(positions);
}else{
positions.pop();
cartesian.y += (1 + Math.random());
positions.push(cartesian);
}
}
},Cesium.ScreenSpaceEventType.MOUSE_MOVE);
handler.setInputAction(function(movement){
handler.destroy();
},Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
}
cesium 添加ployline方法
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...