"use script"; //开发环境建议开启严格模式 (function (window, mars3d) { //创建widget类,需要继承BaseWidget class MyWidget extends mars3d.widget.BaseWidget { //初始化[仅执行1次] create() {} //打开激活 activate() { this._last_basemap = this.map.basemap?.uuid; this.map.basemap = 2017; //切换底图到深色底图 this.map.setCameraView({ lat: 31.314644, lng: 121.515959, alt: 7866, heading: 200, pitch: -43 }); //显示上海建筑物 this.layerJzw = this.map.getLayer(204012, "id"); if (this.layerJzw && !this.layerJzw.isAdded) { this.layerJzw.marsJzwStyle = true; this.layerJzw.style = { color: { conditions: [["true", "rgb(3, 104, 255)"]], }, }; this.map.addLayer(this.layerJzw, true); this._hasRemoveLayer = true; } //创建Graphic图层 var graphicLayer = new mars3d.layer.GraphicLayer({ name: this.config.name, pid: 99, //图层管理 中使用,父节点id }); this.map.addLayer(graphicLayer); this.graphicLayer = graphicLayer; //加一些演示数据 addGraphic_a1(graphicLayer); addGraphic_a2(graphicLayer); addGraphic_a3(graphicLayer); addGraphic_a4(graphicLayer); addGraphic_a5(graphicLayer); } //关闭释放 disable() { if (this._last_basemap) { this.map.basemap = this._last_basemap; //还原底图 this._last_basemap = null; } if (this.graphicLayer) { this.map.removeLayer(this.graphicLayer, true); this.graphicLayer = null; } if (this._hasRemoveLayer && this.layerJzw) { this.map.removeLayer(this.layerJzw); this._hasRemoveLayer = false; } } } //注册到widget管理器中。 mars3d.widget.bindClass(MyWidget); function addGraphic_a1(graphicLayer) { //立体围墙扩散效果,面状 var diffuseWallGlow = new mars3d.graphic.DiffuseWall({ positions: [ [121.475616, 31.255374, 5.87], [121.482578, 31.248681, 10.85], [121.479447, 31.240235, 14.25], [121.470002, 31.240496, 12.92], [121.46538, 31.249206, 9.53], [121.475616, 31.255374, 5.87], ], style: { diffHeight: 2000, //高度 speed: 10, //速度 }, }); graphicLayer.addGraphic(diffuseWallGlow); } function addGraphic_a2(graphicLayer) { //立体围墙扩散效果,圆状 var circleDiffuseWallGlow = new mars3d.graphic.DiffuseWall({ position: new mars3d.LatLngPoint(121.481165, 31.278668, 44.3), //圆中心点 style: { radius: 600, //半径 color: "#ff0000", diffHeight: 2000, //高度 speed: 10, //速度 }, }); graphicLayer.addGraphic(circleDiffuseWallGlow); } function addGraphic_a3(graphicLayer) { var primitive = new mars3d.graphic.CirclePrimitive({ position: [121.522454, 31.267553, 61.9], style: { radius: 2000, material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ScanLine, { color: new Cesium.Color(1.0, 1.0, 0.0, 1.0), speed: 10, }), clampToGround: true, //是否贴地 }, }); graphicLayer.addGraphic(primitive); } function addGraphic_a4(graphicLayer) { var _rotation = Math.random(); var graphic = new mars3d.graphic.CircleEntity({ position: Cesium.Cartesian3.fromDegrees(121.504242, 31.23805, 27.88), style: { radius: 1500.0, //扫描材质 material: new mars3d.material.CircleScanMaterialProperty({ url: "img/textures/circleScan.png", color: Cesium.Color.fromCssColorString("#00ff00"), }), stRotation: new Cesium.CallbackProperty(function (e) { _rotation -= 0.1; return _rotation; }, false), classificationType: Cesium.ClassificationType.BOTH, clampToGround: true, //是否贴地 }, }); graphicLayer.addGraphic(graphic); } function addGraphic_a5(graphicLayer) { var _rotation = Math.random(); var graphic = new mars3d.graphic.CircleEntity({ position: new mars3d.LatLngPoint(121.526215, 31.245237, 123.5), style: { radius: 700.0, material: new mars3d.material.CircleScanMaterialProperty({ //扫描材质 url: "img/textures/circle_bg.png", color: Cesium.Color.fromCssColorString("#5fc4ee"), }), stRotation: new Cesium.CallbackProperty(function (e) { _rotation -= 0.1; return _rotation; }, false), classificationType: Cesium.ClassificationType.BOTH, clampToGround: true, //是否贴地 }, }); graphicLayer.addGraphic(graphic); } //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。 })(window, mars3d);