2023-07-18 09:04:15 +08:00
|
|
|
|
(function (window, mars3d) {
|
2023-07-08 15:37:34 +08:00
|
|
|
|
//创建widget类,需要继承BaseWidget
|
|
|
|
|
|
class MyWidget extends mars3d.widget.BaseWidget {
|
|
|
|
|
|
//外部资源配置
|
|
|
|
|
|
get resources() {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
return ["view.css"];
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//弹窗配置
|
|
|
|
|
|
get view() {
|
|
|
|
|
|
return {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
type: "divwindow",
|
|
|
|
|
|
url: "view.html",
|
2023-07-08 15:37:34 +08:00
|
|
|
|
windowOptions: {
|
|
|
|
|
|
width: 210,
|
|
|
|
|
|
height: 210,
|
|
|
|
|
|
},
|
2023-07-18 09:04:15 +08:00
|
|
|
|
};
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//每个窗口创建完成后调用
|
|
|
|
|
|
winCreateOK(opt, result) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
var point = this.map.getCenter();
|
|
|
|
|
|
this.showInputView(point);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
$("#btnCenterXY").click(() => {
|
|
|
|
|
|
var jd = $("#point_jd").val();
|
|
|
|
|
|
var wd = $("#point_wd").val();
|
|
|
|
|
|
var height = $("#point_height").val();
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
let point = new mars3d.LngLatPoint(Number(jd), Number(wd), Number(height));
|
|
|
|
|
|
this.updateMarker(point, true);
|
|
|
|
|
|
});
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//激活插件
|
|
|
|
|
|
activate() {
|
|
|
|
|
|
//单击地图事件
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.map.on(mars3d.EventType.click, this.onMapClick, this);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//释放插件
|
|
|
|
|
|
disable() {
|
|
|
|
|
|
//释放单击地图事件
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.map.off(mars3d.EventType.click, this.onMapClick, this);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
if (this.graphic) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.map.graphicLayer.removeGraphic(this.graphic, true);
|
|
|
|
|
|
this.graphic = null;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
onMapClick(event) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
var cartesian = event.cartesian;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
if (cartesian) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
var point = mars3d.LatLngPoint.fromCartesian(cartesian);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.updateMarker(point);
|
|
|
|
|
|
this.showInputView(point);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
updateMarker(position, iscenter) {
|
|
|
|
|
|
if (this.graphic) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.graphic.position = position;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.graphic = new mars3d.graphic.BillboardEntity({
|
|
|
|
|
|
position: position,
|
|
|
|
|
|
style: {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
image: this.path + "img/marker.png",
|
2023-07-08 15:37:34 +08:00
|
|
|
|
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
|
|
|
|
|
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // default: CENTER
|
|
|
|
|
|
scale: 0.6,
|
|
|
|
|
|
},
|
2023-07-18 09:04:15 +08:00
|
|
|
|
});
|
|
|
|
|
|
this.map.graphicLayer.addGraphic(this.graphic);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (iscenter) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.map.flyToGraphic(this.graphic, { radius: 2000 });
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
showInputView(xy) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
$("#point_jd").val(xy.lng.toFixed(6));
|
|
|
|
|
|
$("#point_wd").val(xy.lat.toFixed(6));
|
|
|
|
|
|
$("#point_height").val(xy.alt.toFixed(1));
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//注册到widget管理器中。
|
2023-07-18 09:04:15 +08:00
|
|
|
|
mars3d.widget.bindClass(MyWidget);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
//每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
|
2023-07-18 09:04:15 +08:00
|
|
|
|
})(window, mars3d);
|