Lin_Ye_Fang_Huo/public/widgets/streetscape/widget.js

112 lines
3.5 KiB
JavaScript
Raw Normal View History

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: "append",
url: "view.html",
parent: "body",
};
2023-07-08 15:37:34 +08:00
}
//每个窗口创建完成后调用
winCreateOK(opt, result) {
2023-07-18 09:04:15 +08:00
var that = this;
$("#btn_streetscapeBar_close").click(function () {
that.disableBase();
});
2023-07-08 15:37:34 +08:00
}
//激活插件
activate() {
2023-07-18 09:04:15 +08:00
var point = this.config.point || { lat: 31.833789, lng: 117.183995 };
this.updateMarker(point);
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
var pointBd = this.getBaiduPoint(point);
2023-07-08 15:37:34 +08:00
var inhtml = `<div id="streetscapeView" style="position:absolute;right:0px;top:0px;border:1px solid #ccc;top: 0px;bottom: 0px;width:50%;overflow: hidden;">
<iframe id="streetscape" name="streetscape" style="width:100%;height:100%;overflow:hidden;margin:0;"
scrolling="no" frameborder="0" src="${this.path}streetscape.html?lng=${pointBd.lng}&lat=${pointBd.lat}"></iframe>
2023-07-18 09:04:15 +08:00
</div>`;
$("body").append(inhtml);
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
$("#centerDiv").css({
position: "",
height: "100%",
width: "50%",
});
$(".no-print-view").hide();
2023-07-08 15:37:34 +08:00
//单击地图事件
2023-07-18 09:04:15 +08:00
this.map.on(mars3d.EventType.click, this.onMapClick, this);
$(".cesium-viewer").css("cursor", "crosshair");
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);
$(".cesium-viewer").css("cursor", "");
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
}
2023-07-18 09:04:15 +08:00
$("#streetscapeView").remove();
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
$("#centerDiv").css({
position: "",
height: "100%",
width: "100%",
});
$(".no-print-view").show();
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);
2023-07-08 15:37:34 +08:00
//点击地图的事件,触发街景改变
2023-07-18 09:04:15 +08:00
var pointBd = this.getBaiduPoint(point);
var streetscapeFrame = document.getElementById("streetscape");
2023-07-08 15:37:34 +08:00
if (streetscapeFrame && streetscapeFrame.contentWindow.setPosition) {
2023-07-18 09:04:15 +08:00
streetscapeFrame.contentWindow.setPosition(pointBd); //根据经纬度坐标展示全景图
2023-07-08 15:37:34 +08:00
}
}
}
getBaiduPoint(point) {
2023-07-18 09:04:15 +08:00
let pointbd = mars3d.PointTrans.wgs2bd([point.lng, point.lat]);
return { lng: pointbd[0], lat: pointbd[1] };
2023-07-08 15:37:34 +08:00
}
updateMarker(position) {
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/streetimg.png",
2023-07-08 15:37:34 +08:00
scale: 1,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
clampToGround: true,
},
2023-07-18 09:04:15 +08:00
});
this.map.graphicLayer.addGraphic(this.graphic);
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
this.map.flyToGraphic(this.graphic, { radius: 800 });
2023-07-08 15:37:34 +08:00
}
}
//注册到widget管理器中。
2023-07-18 09:04:15 +08:00
window.streetscapeWidget = 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);