Files
sdk4.0_new/src/Global/ExportKml/index.js
2025-09-01 16:17:11 +08:00

54 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @name: index
* @author: Administrator
* @date: 2023-09-11 16:41
* @descriptionindex
* @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