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 view() {
|
|
|
|
|
|
return {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
type: "window",
|
|
|
|
|
|
url: "view.html",
|
2023-07-08 15:37:34 +08:00
|
|
|
|
windowOptions: {
|
|
|
|
|
|
width: 250,
|
|
|
|
|
|
height: 500,
|
|
|
|
|
|
},
|
2023-07-18 09:04:15 +08:00
|
|
|
|
};
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
create() {
|
|
|
|
|
|
var inhtml = `
|
|
|
|
|
|
<div id="centerDivEx" style="position:absolute;left:0px;top:0px;border:1px solid #ccc;bottom: 0px;width:50%;overflow: hidden;">
|
|
|
|
|
|
<div id="cesiumContainerEx" style="height:100%;width:100%;overflow: hidden;"></div>
|
2023-07-18 09:04:15 +08:00
|
|
|
|
</div>`;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
$("body").append(inhtml);
|
|
|
|
|
|
|
|
|
|
|
|
var mapOptions2 = this.map.getOptions();
|
|
|
|
|
|
//绑定的控件
|
|
|
|
|
|
mapOptions2.control = {
|
|
|
|
|
|
baseLayerPicker: true, //basemaps底图切换按钮
|
|
|
|
|
|
defaultContextMenu: true, //右键菜单
|
|
|
|
|
|
};
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
//用于双屏同图层,不同配置展示
|
2023-07-18 09:04:15 +08:00
|
|
|
|
for (let i = 0, len = mapOptions2.layers.length; i < len; i++) {
|
|
|
|
|
|
let item = mapOptions2.layers[i];
|
2023-07-08 15:37:34 +08:00
|
|
|
|
if (item.compare) {
|
|
|
|
|
|
//存在compare属性时
|
|
|
|
|
|
for (var key in item.compare) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
item[key] = item.compare[key];
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
//后置加的图层的处理
|
|
|
|
|
|
var mapLayers = this.map.getLayers({
|
|
|
|
|
|
filter: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
for (let i = mapLayers.length - 1; i >= 0; i--) {
|
|
|
|
|
|
let layer = mapLayers[i];
|
|
|
|
|
|
if (layer.noLayerManage || layer.parent) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
mapOptions2.layers.push(layer.toJSON());
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
2023-07-18 09:04:15 +08:00
|
|
|
|
console.log("分屏地图配置", mapOptions2);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.mapEx = new mars3d.Map("cesiumContainerEx", mapOptions2);
|
|
|
|
|
|
this.mapEx.basemap = "天地图电子";
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
this.map.on(mars3d.EventType.morphComplete, (event) => {
|
|
|
|
|
|
//切换场景前事件
|
|
|
|
|
|
if (this.map.scene.mode === Cesium.SceneMode.SCENE2D) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.mapEx.scene.screenSpaceCameraController.enableTilt = false;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
} else {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.mapEx.scene.screenSpaceCameraController.enableTilt = true;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
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
|
|
|
|
$("#btn_mapCompare_close").click(() => {
|
|
|
|
|
|
this.disableBase();
|
|
|
|
|
|
});
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//激活插件
|
|
|
|
|
|
activate() {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
$("#centerDiv").css({
|
|
|
|
|
|
position: "absolute",
|
|
|
|
|
|
height: "100%",
|
|
|
|
|
|
width: "50%",
|
|
|
|
|
|
top: 0,
|
|
|
|
|
|
left: "auto",
|
|
|
|
|
|
right: 0,
|
|
|
|
|
|
});
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
$("#centerDivEx").show();
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.map.on(mars3d.EventType.cameraChanged, this._map_extentChangeHandler, this);
|
|
|
|
|
|
this.map.camera.percentageChanged = 0.01;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.mapEx.on(mars3d.EventType.cameraChanged, this._mapEx_extentChangeHandler, this);
|
|
|
|
|
|
this.mapEx.camera.percentageChanged = 0.01;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this._map_extentChangeHandler();
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//释放插件
|
|
|
|
|
|
disable() {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.map.off(mars3d.EventType.cameraChanged, this._map_extentChangeHandler, this);
|
|
|
|
|
|
this.mapEx.off(mars3d.EventType.cameraChanged, this._mapEx_extentChangeHandler, this);
|
|
|
|
|
|
|
|
|
|
|
|
$("#centerDivEx").hide();
|
|
|
|
|
|
$("#centerDiv").css({
|
|
|
|
|
|
position: "",
|
|
|
|
|
|
height: "100%",
|
|
|
|
|
|
width: "100%",
|
|
|
|
|
|
left: 0,
|
|
|
|
|
|
right: "auto",
|
|
|
|
|
|
});
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
_map_extentChangeHandler(e) {
|
|
|
|
|
|
if (!this.isActivate) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
return;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
// console.log('map主地图 视角变化了')
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.mapEx.off(mars3d.EventType.cameraChanged, this._mapEx_extentChangeHandler, this);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.updateView(this.map, this.mapEx);
|
|
|
|
|
|
this.mapEx.on(mars3d.EventType.cameraChanged, this._mapEx_extentChangeHandler, this);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
_mapEx_extentChangeHandler(e) {
|
|
|
|
|
|
if (!this.isActivate) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
return;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
// console.log('mapEx对比地图 视角变化了')
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.map.off(mars3d.EventType.cameraChanged, this._map_extentChangeHandler, this);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.updateView(this.mapEx, this.map);
|
|
|
|
|
|
this.map.on(mars3d.EventType.cameraChanged, this._map_extentChangeHandler, this);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
//“变化屏”mapChange变化,将“被更新屏”mapUpdate同步更新
|
|
|
|
|
|
updateView(mapChange, mapUpdate) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
var cameraView = mapChange.getCameraView();
|
|
|
|
|
|
mapUpdate.setCameraView(cameraView, { duration: 0 });
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//图层树相关
|
|
|
|
|
|
getLayers() {
|
|
|
|
|
|
return this.mapEx.getLayers({
|
|
|
|
|
|
basemaps: true, //是否取config.json中的basempas
|
|
|
|
|
|
layers: true, //是否取config.json中的layers
|
2023-07-18 09:04:15 +08:00
|
|
|
|
});
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//更新图层:显示隐藏状态
|
|
|
|
|
|
updateLayerShow(layer, show) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
layer.show = show;
|
2023-07-08 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
|
if (show) {
|
|
|
|
|
|
if (!layer.isAdded) {
|
2023-07-18 09:04:15 +08:00
|
|
|
|
this.mapEx.addLayer(layer);
|
2023-07-08 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// if (layer.isAdded) {
|
|
|
|
|
|
// this.mapEx.removeLayer(layer)
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//注册到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);
|