cesium点击面高亮事件[转]

cesium点击面高亮事件

主要功能:比如你加载了json、geojson或者topojson的数据。加载出来后,分为很多个面,现在要实现点击一个面,这个面变颜色;再点击另一个面,另一个面高亮,之前的面复原。(有不懂得,请加相关学习群:854184700)

下面上代码:

 1     function hightlightLine() {
 2         var temp = new Array();
 3         function linehHghtlight(nameId) {
 4             var exists = temp.indexOf(nameId);
 5             if (exists <= -1) {
 6                 temp.push(nameId);
 7             } else {
 8                 temp.splice(exists, 1);  //删除对应的nameID
 9             }
10         }
11         viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
12             var pickedFeature = viewer.scene.pick(movement.position);
13 
14             //判断之前是否有高亮面存在
15             if (highlightFace) {
16                 highlightFace.material = highlightFace.material0;
17             }
18             pickedFeature.id.polygon.material0 = pickedFeature.id.polygon.material;
19             pickedFeature.id.polygon.material = Cesium.Color.WHITE;
20             highlightFace = pickedFeature.id.polygon;
21             showDivPositionOld = pickedFeature.id.properties;
22 
23             if (typeof (pickedFeature) != "undefined")  //鼠标是否点到面上
24                 var id = pickedFeature.id;
25             linehHghtlight(id);
26         }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
27     }
饮水思源,不忘初心。 要面包,也要有诗和远方。
原文地址:https://www.cnblogs.com/mazhenyu/p/15620111.html