關于Mars3d的入門
- 一. 創建地球,加載瓦片圖層
- 二 矢量圖層
- 2.1 常用矢量圖層
- 2.1.1 GraphicLayer
- 2.1.2 GeoJsonLayer
- 2.2 矢量圖層的點擊事件
- 三 矢量數據
- 四 事件機制
一. 創建地球,加載瓦片圖層
// 1. 創建地球let map = new mars3d.Map("mars3dContainer", mapOptions);// 2. 加載瓦片layers: [{name: "test",type: "image",url: "//data.mars3d.cn/test.png",rectangle: { xmin: 127.259691, xmax: 137.267778, ymin: 34.834432, ymax: 36.84387 },show: true}]
加載瓦片的方式有兩種:
二 矢量圖層
矢量圖層與矢量數據的用法
- 定義矢量數據
- 把矢量數據放到矢量圖層
- 把矢量圖層放到地圖上
2.1 常用矢量圖層
2.1.1 GraphicLayer
//創建矢量數據圖層
let graphicLayer = new mars3d.layer.GraphicLayer()
map.addLayer(graphicLayer)//加載數據到矢量圖層
let graphic = new mars3d.graphic.LabelEntity({position: new mars3d.LngLatPoint(116.1, 31.0, 1000),style: {text: 'Mars3D三維可視化平臺',font_size: 25,color: '#003da6',},
})
graphicLayer.addGraphic(graphic)
2.1.2 GeoJsonLayer
通過json的格式創建圖層,高效方便
let geoJsonLayer = new mars3d.layer.GeoJsonLayer({name: '省界線',url: 'http://data.mars3d.cn/file/geojson/sheng-line.json',symbol: {//可以通過配置symbol參數來指定渲染的矢量數據類型和樣式。type:"polyline",styleOptions: {color: '#ffffff',opacity: 0.8,width: 2},},
})
map.addLayer(geoJsonLayer)
2.2 矢量圖層的點擊事件
graphicEllipseLayer.on(mars3d.EventType.click, function (event) {console.log("監聽layer,單擊了矢量對象", event)})// 綁定layer標繪相關事件監聽(可以自行加相關代碼實現業務需求,此處主要做示例)graphicEllipseLayer.on(mars3d.EventType.drawStart, function (e) {console.log("開始繪制", e)})graphicEllipseLayer.on(mars3d.EventType.drawAddPoint, function (e) {console.log("繪制過程中增加了點", e)})graphicEllipseLayer.on(mars3d.EventType.drawRemovePoint, function (e) {console.log("繪制過程中刪除了點", e)})graphicEllipseLayer.on(mars3d.EventType.drawCreated, function (e) {console.log("創建完成", e)// graphicLayer.stopDraw()// graphicLayer.startDraw(mars3d.Util.clone(e.graphic.options)) // 連續標繪時,可以代替isContinued})graphicEllipseLayer.on(mars3d.EventType.editStart, function (e) {console.log("開始編輯", e)})graphicEllipseLayer.on(mars3d.EventType.editMovePoint, (e)=> {console.log("編輯修改了點", e.graphic.editing._graphic.options.style.radius)this.$emit("mixinsRadiusChangeMth",e.graphic.editing._graphic.options.style.radius)this.mapScan(e.graphic);})graphicEllipseLayer.on(mars3d.EventType.editAddPoint, function (e) {console.log("編輯新增了點", e)})graphicEllipseLayer.on(mars3d.EventType.editRemovePoint, function (e) {console.log("編輯刪除了點", e)})graphicEllipseLayer.on(mars3d.EventType.editStop, function (e) {console.log("停止編輯", e)})graphicEllipseLayer.on(mars3d.EventType.removeGraphic, function (e) {console.log("刪除了對象", e)})
三 矢量數據
剩余的矢量對象
ParticleSystem粒子對象 —》 粒子效果
漫游路線對象 —》 展示對象按照一定軌跡移動
視頻融合對象 —》投射視頻物體表面
四 事件機制
常用的方法
// 獲取圖層 在清除圖層
const layer = map.getLayerById(2021)// 移除圖層
map.removeLayer(layer )// 隱藏圖層
layer.show = false// 顯示圖層
layer.show = true//通過id獲取圖層
const layer = map.getLayerById(2021)
const layer = map.getLayer("id",2021) //獲取所有的圖層
const layers =map.getLayers({basemaps:false // 不包含basemps中配置的所有圖層layers:false // 不包含layers中配置的所有圖層})//判斷圖層是否添加過
const isHaveLayer = map.hasLayer(2021) // 返回boolean