54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
/**
|
||
* @name: index
|
||
* @author: Administrator
|
||
* @date: 2023-09-11 16:41
|
||
* @description:index
|
||
* @update: 2023-09-11 16:41
|
||
*/
|
||
import BillboardObject from "../../Obj/Base/BillboardObject";
|
||
import PolygonObject from "../../Obj/Base/PolygonObject";
|
||
import PolylineObject from "../../Obj/Base/PolylineObject";
|
||
import Circle from "../../Obj/Base/CircleDiffuse";
|
||
|
||
function exportKml(list = []) {
|
||
|
||
let entities = new Cesium.EntityCollection();
|
||
list.forEach(entity => {
|
||
if (
|
||
entity instanceof BillboardObject ||
|
||
entity instanceof PolygonObject ||
|
||
entity instanceof Circle ||
|
||
entity instanceof PolylineObject
|
||
) {
|
||
entities.add(entity.entity)
|
||
}
|
||
})
|
||
if (entities.values.length) {
|
||
let promise = Cesium.exportKml({entities})
|
||
promise.then(e => {
|
||
// Cesium.exportKml(e.kml,)
|
||
funDownload(e.kml, new Date().getTime() + ".kml")
|
||
})
|
||
} else {
|
||
console.error("允许导出为kml的对象为空")
|
||
}
|
||
}
|
||
|
||
function funDownload(content, filename) {
|
||
let eleLink = document.createElement("a");
|
||
eleLink.download = filename;
|
||
eleLink.style.display = "none";
|
||
// 字符内容转变成blob地址
|
||
let blob = new Blob([content]);
|
||
eleLink.href = URL.createObjectURL(blob);
|
||
// 触发点击
|
||
document.body.appendChild(eleLink);
|
||
eleLink.click();
|
||
// 然后移除
|
||
document.body.removeChild(eleLink);
|
||
}
|
||
|
||
|
||
export default exportKml
|
||
|