import * as mars3d from "mars3d" export let map // mars3d.Map三维地图对象 // 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并) export const mapOptions = { scene: { center: { lat: 31.771475, lng: 117.219579, alt: 8642, heading: 0, pitch: -57 } } } /** * 初始化地图业务,生命周期钩子函数(必须) * 框架在地图初始化完成后自动调用该函数 * @param {mars3d.Map} mapInstance 地图对象 * @returns {void} 无 */ export function onMounted(mapInstance) { map = mapInstance // 记录首次创建的map } /** * 释放当前地图业务的生命周期函数 * @returns {void} 无 */ export function onUnmounted() { map = null } // 叠加的图层 let tileLayer export function addLayer() { removeLayer() // 方式2:在创建地球后调用addLayer添加图层(直接new对应type类型的图层类) tileLayer = new mars3d.layer.ArcGisLayer({ url: "//server.mars3d.cn/arcgis/rest/services/crs/ssjzw4326/MapServer", highlight: { clampToGround: true, fill: true, color: "#2deaf7", opacity: 0.6, outline: true, outlineWidth: 3, outlineColor: "#e000d9", outlineOpacity: 1.0 }, popup: "all", flyTo: true }) map.addLayer(tileLayer) } export function removeLayer() { if (tileLayer) { map.removeLayer(tileLayer, true) tileLayer = null } }