HTMl代码
<div id="container" class="container"></div> <script src="//webapi.amap.com/maps?v=1.4.15&key=您申请的key值&"></script> <script src="//webapi.amap.com/loca?v=1.3.0&key=您申请的key值"></script> <script src="//a.amap.com/Loca/static/dist/jquery.min.js"></script>
javascript代码
var map = new AMap.Map('container', { mapStyle: 'amap://styles/1de318cbb8d12c02303a22c550b9ccc9', center: [119.557371,28.970325], pitch: 50, features: ['bg', 'road'], zoom: 5, viewMode: '3D' }); //初始化动画效果; setTimeout(function(){ map.panTo([116.409788,39.880782]); map.setZoom(9); //设置地图层级 },10000); var colors = ['#ffffcc', '#a1dab4', '#41b6c4', '#225ea8']; $.get('https://a.amap.com/Loca/static/mock/bj_district_wkt.json', function (data) { var layer = new Loca.PolygonLayer({ map: map, fitView: true }); layer.setData(data, { lnglat: 'coordinates' }); var idx = 0; layer.setOptions({ style: { height: function () { return Math.random() * 200000; }, opacity: 0.8, color: function () { return colors[idx++ % colors.length]; } } }); layer.render(); });
Done!