使用
const popupsDom = new global.DC.mobileDivForms(state.mviewer, {
domId: "mobilePopup",
title: data.query.name || "成教楼 ",
className: "mobilePopup",
content: document.getElementById("mobile-map_content_content"),
position: [data.position],
});
构造函数主体
import DC from '@dvgis/dc-sdk/dist/dc.base.min'
import DcCore from '@dvgis/dc-sdk/dist/dc.core.min'
var $ = window.$
DC.use(DcCore)
class mobileDivForms {
constructor(viewer, popup) {
this._viewer = viewer;
this._popup = popup;
this._position = popup.position;
this._title = popup.title;
this._content = popup.content;
this.appendPopup();
this.isOpen = true;
}
get viewer() {
return this._viewer
}
get title() {
return this._title
}
get content() {
return this._content
}
get popup() {
return this._popup
}
get position() {
return this._position
}
appendPopup() {
this.createVideoWindowAll(this._popup.domId, this._popup.className, this._position[0])
}
createVideoWindowAll(id, className, position) {
let dom = document.getElementById('mobile-map_popup_content');
dom.style.display = 'block';
var childs = document.getElementById('mobile-map_popup_content').getElementsByTagName('div')
if (childs.length > 0) {
for (var i = 0; i < childs.length; i++) {
document.getElementById('mobile-map_popup_content').removeChild(childs[i])
}
}
var self = this
var el = $("<div class=''></div>")
el.append(this._content)
el.attr('id', id)
el.addClass(className || '')
$('#mobile-map_popup_content').append(el)
this._viewer.scene.postRender.addEventListener(function (e) {
if (!self.isOpen) {
return;
}
const windowCoord = DC.Namespace.Cesium.SceneTransforms.wgs84ToWindowCoordinates(
self._viewer.scene,
position
)
self.positionPopUp(windowCoord, id)
})
}
positionPopUp(windowCoord, id) {
if (!windowCoord) {
return;
}
const wx = document.getElementById('app').clientWidth;
const x = windowCoord.x - (wx / 100 * 35);
const y = windowCoord.y - document.getElementById(id).offsetHeight - 15;
document.getElementById(id).style.cssText = `
visibility:visible;
z-index:98;
transform:translate3d(${
Math.round(x)}px,${
Math.round(y)}px, 0);
`
}
closeOur() {
this.isOpen = false;
let dom = document.getElementById('mobile-map_popup_content');
dom.style.display = 'none';
}
}
export default mobileDivForms
html展示页面–可查看上一篇–便利贴9有一部分
<template>
<div
ref="mobile-mapContent