Toggle navigation
调用mapbox api 实现地图飞行定位 flyto
By
baixiaozhe
2017-12-29 07:24:01
脚本
16
21
作品使用的第三方脚本
https://api.mapbox.com/mapbox-gl-js/v0.38.0/mapbox-gl.js,http://echarts.baidu.com/resource/echarts-gl-latest/dist/echarts-gl.min.js,http://echarts.baidu.com/resource/echarts-gl-latest/mapboxgl-token.js
数据管理
上传数据
支持小于 5M 任意格式(csv, xlsx, json, xml, ...)的数据文件
上传后可以通过生成的文件链接异步获取托管的数据。
历史数据
0 条
无历史数据
代码修改记录
信息提示
保存作品
对当前截图不满意?你还可以
上传本地截图
重新截图
作品名称
作品描述
标签
geo
grid
legend
markLine
markPoint
bar
effectScatter
line
lines
map
timeline
title
toolbox
tooltip
visualMap
作品默认版本
最新
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
20:11:45
图表已生成
整理代码
刷新
代码
var uploadedDataURL1 = "/asset/get/s/data-1514531213518-SJL5tvmmG.hdr"; var uploadedDataURL2 = "/asset/get/s/data-1514531203136-rysKFPQ7M.json"; mapboxgl.accessToken = mapboxglToken; $.getJSON(uploadedDataURL2, function(data) { data = data.filter(function(dataItem) { return dataItem[2] > 0; }).map(function(dataItem) { return [dataItem[0], dataItem[1], dataItem[2]]; }); myChart.setOption({ title: { text: '空格键启动飞行', left: 'center' }, visualMap: { show: false, max: 1000, calculable: true, realtime: false, inRange: { color: ['#23074d', '#cc5333'] }, outOfRange: { colorAlpha: 0 } }, mapbox: { center: [104.114129, 37.550339], zoom: 3, pitch: 50, bearing: -10, style: 'mapbox://styles/mapbox/light-v9', boxHeight: 20, // altitudeScale: 3e2, postEffect: { enable: false, SSAO: { enable: true, radius: 2 } }, light: { main: { intensity: 2, shadow: true, shadowQuality: 'high' }, ambient: { intensity: 1.0 }, ambientCubemap: { texture: uploadedDataURL1, exposure: 2, diffuseIntensity: 0.5 } } }, series: [{ type: 'bar3D', coordinateSystem: 'mapbox', shading: 'lambert', minHeight: 0.1, barSize: 0.3, data: data, silent: true }] }); var isPerspective = true; //飞行目的地 可以点击地图获取,坐标会输出到控制台 var locations = [{ "camera": { center: [112.53778846748253, 41.60655252782351], zoom: 8, pitch: 30 } }, { "camera": { center: [107.79175922308059, 30.00052304525201], zoom: 8, pitch: 40 } }, { "camera": { center: [118.94102201550334, 28.165606490352943], zoom: 8, pitch: 50 } }, { "camera": { center: [123.95740624281103, 37.27393230192344], zoom: 8, pitch: 60 } }]; //获取mapbox地图对象 var map = myChart.getModel().getComponent('mapbox').getMapbox(); //监听点击地图事件 获取地图坐标 加入飞行目的地数组 map.on('click', function(e) { console.log('center: [' + e.lngLat.lng + ', ' + e.lngLat.lat + ']'); }); function playback(index) { //其他飞行参数参考:https://www.mapbox.com/mapbox-gl-js/api#map#flyto map.flyTo(locations[index].camera); map.once('moveend', function() { // Duration the slide is on screen after interaction window.setTimeout(function() { index = index + 1; if (index + 1 <= locations.length) { playback(index); } // Increment index // index = (index + 1 === locations.length) ? 0 : index + 1; }, 3000); // After callback, show the location for 3 seconds. }); } //空格键启动飞行 window.addEventListener('keydown', function(e) { playback(0); }); });