(function (window, mars3d) {
|
//创建widget类,需要继承BaseWidget
|
class MyWidget extends mars3d.widget.BaseWidget {
|
//初始化[仅执行1次]
|
create() {}
|
//打开激活
|
activate() {
|
//创建Graphic图层
|
var graphicLayer = new mars3d.layer.GraphicLayer({
|
name: this.config.name,
|
pid: 99, //图层管理 中使用,父节点id
|
});
|
this.map.addLayer(graphicLayer);
|
|
graphicLayer.bindPopup(function (event) {
|
let item = event.graphic?.attr;
|
var inhtml = "管线长度:" + item.changdu + "米<br/>管径:" + item.guanjin + "mm";
|
return inhtml;
|
});
|
|
this.graphicLayer = graphicLayer;
|
|
//添加管道示例数据
|
$.getJSON("//data.mars3d.cn/file/geojson/pipeline.json", (geojson) => {
|
//循环每个面
|
|
let arr = mars3d.Util.geoJsonToGraphics(geojson);
|
|
for (let i = 0; i < arr.length; i++) {
|
let graphicOptions = arr[i];
|
|
var radius = graphicOptions.attr.guanjin / 80;
|
if (radius < 2) {
|
radius = 2;
|
}
|
|
var primitive = new mars3d.graphic.PolylineVolumePrimitive({
|
positions: graphicOptions.positions,
|
style: {
|
shape: "pipeline",
|
radius: radius,
|
material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.Color, {
|
color: Cesium.Color.BLUE,
|
}),
|
},
|
attr: graphicOptions.attr,
|
});
|
this.graphicLayer.addGraphic(primitive);
|
}
|
|
console.log("管线加载完成,共" + arr.length + "条");
|
|
this.graphicLayer.flyTo();
|
});
|
}
|
//关闭释放
|
disable() {
|
this.map.removeLayer(this.graphicLayer, true);
|
this.graphicLayer = null;
|
}
|
}
|
|
//注册到widget管理器中。
|
mars3d.widget.bindClass(MyWidget);
|
|
//每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
|
})(window, mars3d);
|