"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({
y: 31.231319,
x: 118.810112,
z: 103265.46,
heading: 360,
pitch: -50.2,
roll: 0,
});
//显示高校点
$.getJSON("//data.mars3d.cn/file/apidemo/gaoxiao.json", (result) => {
this.addFeature(result);
});
}
//关闭释放
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;
}
}
addFeature(arr) {
//创建DIV数据图层
var graphicLayer = new mars3d.layer.DivLayer({
name: this.config.name,
pid: 99, //图层管理 中使用,父节点id
});
this.map.addLayer(graphicLayer);
this.graphicLayer = graphicLayer;
//在layer上绑定监听事件
graphicLayer.on(mars3d.EventType.click, function (event) {
console.log("监听layer,单击了矢量对象", event);
// haoutil.msg('单击了:' + item['高校名称'])
});
graphicLayer.bindPopup(function (event) {
let item = event.graphic?.attr;
var html =
"高校名称:" +
item["高校名称"] +
"
所属地区:" +
item["地区"] +
"
主管部门:" +
item["主管部门"] +
"
办学层次:" +
item["办学层次"] +
"
王牌专业:" +
item["王牌专业"];
return html;
});
var pointColorArr = ["#f33349", "#f79a2c", "#f2fa19", "#95e40c", "#1ffee6"];
for (var i = 0, len = arr.length; i < len; i++) {
var item = arr[i];
var jwd = item["经纬度"].split(",");
if (jwd.length !== 2) {
continue;
}
var jd = Number(jwd[0]);
var wd = Number(jwd[1]);
var clr = pointColorArr[i % pointColorArr.length];
var graphic = new mars3d.graphic.DivGraphic({
position: Cesium.Cartesian3.fromDegrees(jd, wd),
style: {
html: '