cesium多边形描边_Cesium实现文字、点、多段线、多边形的实时绘制

该博客介绍了如何在 Cesium 中实现多边形的描边、文字、点和多段线的实时绘制。通过监听屏幕事件,创建ScreenSpaceEventHandler,当用户点击时添加点到多边形路径,并在鼠标移动时更新点位置。双击时清除当前形状。文章提供了createPolygon函数用于生成带描边的红色多边形,并设置了黄色的边框。
摘要由CSDN通过智能技术生成

functiondrawPolygon() {varfloatingPoint;varactivePolygon;var handler = newCesium.ScreenSpaceEventHandler(viewer.canvas);

handler.setInputAction(function(click) {var position =viewer.scene.pickPosition(click.position);if(Cesium.defined(location.cartesian)){var cartesian =location.cartesian;if(activeShapePoints.length === 0){

floatingPoint=creatPoint(cartesian);

activeShapePoints.push(cartesian);var dynamicPositions = new Cesium.CallbackProperty(function() {returnactiveShapePoints;

},false);

activePolygon=createPolygon(dynamicPositions);

}

activeShapePoints.push(cartesian);

creatPoint(cartesian);

}

},Cesium.ScreenSpaceEventType.LEFT_CLICK);

handler.setInputAction(function(movement) {if(Cesium.defined(floatingPoint)){if(Cesium.defined(location.endPosition)){

floatingPoint.position.setValue(location.endPosition);

activeShapePoints.pop();

activeShapePoints.push(location.endPosition);

}

}

},Cesium.ScreenSpaceEventType.MOUSE_MOVE);

handler.setInputAction(function(movement) {

handler.destroy();for(var i=0;i

viewer.entities.remove(Points[i]);

}

Points=[];

},Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);functioncreatePolygon(positionData) {varpolygon;

polygon=viewer.entities.add({

name:'polygon',

positions : positionData,

polygon:{

hierarchy : positionData,

perPositionHeight:true,

material: Cesium.Color.RED.withAlpha(0.7),

outline:true,

outlineColor: Cesium.Color.YELLOW.withAlpha(1)

}

});returnpolygon;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值