Cesium中爲幾何形狀設置材質有多種方法html
直接構建Cesium.Material對象,經過設置Material的屬性來進行控制,官方示例和API描述的比較清楚,編程
API說明ide
材質示例ui
今天介紹經過MaterialProperty設置:spa
Cesium 材質相關的類爲 MaterialProperty,它有一下幾個子類:code
這裏以 第五節介紹的Geometry來表現材質的變化,示例以下:htm
//方法一,構造時賦材質 var entity = viewer.entities.add({ position: Cesium.Cartesian3.fromDegrees(-103.0, 40.0), ellipse : { semiMinorAxis : 250000.0, semiMajorAxis : 400000.0, material : Cesium.Color.BLUE.withAlpha(0.5)//可設置不一樣的MaterialProperty } }); //方法二,構造後賦材質 var ellipse = entity.ellipse; ellipse.material = Cesium.Color.RED;
如下依次來介紹對象
顏色是最多見的材質,能夠將幾何形狀修改成不一樣的純色,達到區分的目的,也能夠完成好比鼠標移動到某個建築,建築變色之類;使用比較簡單,只須要賦值顏色就好了,例如: ellipse.material = Cesium.Color.BLUE.withAlpha(0.5)blog
圖片紋理功能比較豐富,主要有下面屬性:圖片
//完整的這麼寫 ellipse.material = new Cesium.ImageMaterialProperty({ image:'../images/cats.jpg', color: Cesium.Color.BLUE, repeat : new Cesium.Cartesian2(4, 4) }); //也能夠簡單的寫成 ellipse.material = '../images/cats.jpg';
注意 在http網址中調用https網址圖片,肯能會調用失敗
共有三個屬性,
ellipse.material = new Cesium.CheckerboardMaterialProperty({ evenColor : Cesium.Color.WHITE, oddColor : Cesium.Color.BLACK, repeat : new Cesium.Cartesian2(4, 4) });
屬性說明以下:
ellipse.material = new Cesium.StripeMaterialProperty({ evenColor : Cesium.Color.WHITE, oddColor : Cesium.Color.BLACK, repeat : 32, offset:20, orientation:Cesium.StripeOrientation.VERTICAL });
屬性說明以下:
ellipse.material = new Cesium.GridMaterialProperty({ color : Cesium.Color.YELLOW, cellAlpha : 0.2, lineCount : new Cesium.Cartesian2(8, 8), lineThickness : new Cesium.Cartesian2(2.0, 2.0) });
var entity = viewer.entities.add({ polyline : { positions : Cesium.Cartesian3.fromDegreesArray([-77, 35, -77.1, 35]), width : 5, material : Cesium.Color.RED }}); viewer.zoomTo(viewer.entities);
屬性說明以下:
polyline.material = new Cesium.PolylineGlowMaterialProperty({ glowPower : 0.2, color : Cesium.Color.BLUE });
屬性說明以下:
polyline.material = new Cesium.PolylineOutlineMaterialProperty({ color : Cesium.Color.ORANGE, outlineWidth : 3, outlineColor : Cesium.Color.BLACK });
我的主頁 http://cesium.xin