html代码
<div id="container" class="container"></div> <script src="https://webapi.amap.com/maps?v=1.4.15&plugin=Map3D&key=4d9588a3341c2828d87c"></script> <script src="https://webapi.amap.com/loca?v=1.3.1&key=4d9a765939a2b76588a33"></script> <script src="js/jquery-3.3.1.min.js"></script>
javascript代码
var map = new AMap.Map('container', { mapStyle: 'amap://styles/dark', zoom: 5, pitch: 0, center: [104.090834, 31.270677], features: ['bg', 'road'], viewMode: '3D' }); var layer = new Loca.LabelsLayer({ fitView: true, map: map, collision: true }); $.get('json/trafficjam_lnglat.csv', function (datas) { layer.setData(datas, { type: 'csv', /*lnglat: function (o) { return dist[o.value['地区']] },*/ lnglat: 'lnglat' }).setOptions({ style: { direction: 'center', offset: [0, 0], text: function (data) { return data.value['city'] + ' ' + data.value['mom']; }, fillColor: function (data) { var income = +data.value['mom'].slice(0, -1); return income < -5 ? '#0C6DB0' : income < -4 ? '#99d594' : income < -3 ? '#99d594' : income < -2 ? '#fee08b' : income < -1 ? '#fee08b' : '#fc8d59'; }, fontSize: function (data) { var income = +data.value['mom'].slice(0, -1); return income < -5 ? 12 : income < -4 ? 12 : income < -3 ? 16 : income < -2 ? 18 : income < -1 ? 26 : 30; }, strokeWidth: 0 } }).render(); layer.setzIndex(100); });
Done!