import * as mars3d from "mars3d"export let map // mars3d.Map三维地图对象
export let graphicLayer // 矢量数据图层
export const mapOptions = {scene: {center:{"lat":30.577085,"lng":116.885511,"alt":45203.5,"heading":360,"pitch":-45}}
}
/*** 初始化地图业务,生命周期钩子函数(必须)* 框架在地图初始化完成后自动调用该函数* @param {mars3d.Map} mapInstance 地图对象* @returns {void} 无*/
export function onMounted(mapInstance) {map = mapInstancegraphicLayer = new mars3d.layer.GraphicLayer()map.addLayer(graphicLayer)addDemoGraphic3(graphicLayer)
}/*** 释放当前地图业务的生命周期函数* @returns {void} 无*/
export function onUnmounted() {map = null
}function addDemoGraphic3(graphicLayer) {var graphic = new mars3d.graphic.ModelEntity({name: "警车",position: [116.5, 30.9, 1000],style: {url: "//data.mars3d.cn/gltf/mars/jingche/jingche.gltf",scale: 1,minimumPixelSize: 50},popup: "{remark} {name} {text}",attr: { remark: "示例2" }})for (let i = 1; i < 10; i++) {const geojson = graphic.toGeoJSON()console.log("这是一条华丽的分割线--------------------------------------")console.log(geojson,"+++++++++geojson++++++++")const graphicCopy = mars3d.Util.geoJsonToGraphics(geojson)[0]console.log("这是一条华丽的分割线--------------------------------------")console.log(graphicCopy, "++++++++++graphicCopy++++++++++")delete graphicCopy.attrgraphicCopy['attr'] = { remark: "循环示例" + i ,name: "我是追加的" + i,text: "原始循环示例" + i}graphicCopy.position = [116.5 + i * 0.1, 30.9, 1000]graphicCopy.style.label = graphicCopy.style.label || {}graphicCopy.style.label.text = "原始循环示例" + igraphicLayer.addGraphic(graphicCopy)}}
链接:
功能示例(Vue版) | Mars3D三维可视化平台 | 火星科技