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 }
有疑惑,請加相關學習群:854184700