loca 数据可视化 API 2.0是一个基于高德地图JS API 2.0的高性能地图数据可视化库,采用了和1.3版本中不同的架构模式和渲染管线,极大的提升了性能和渲染效果。数据源进行了标准化,仅支持标准的GeoJSON格式数据。
注意:新版Loca API 2.0和Loca 1.3.x版本不兼容,它们是针对不同的JS API版本进行的封装。 因此如果您需要使用JS API 1.4.x,那么只能使用Loca API 1.3.x;如果您需要使用JS API 2.0,那么只能使用Loca API 2.0。
var map = new AMap.Map('map', {zoom: 15.8,//center: [123.0155, 41.11805],center: [116.33081, 39.995731],showIndoorMap: false,pitch: 45, // 地图俯仰角度,有效范围 0 度- 83 度viewMode: '3D', // 地图模式mapStyle: 'amap://styles/a88f4b4a2db1276936aefa8d21ee95a1'});
由于是海量点的引入,不建议在实际生产环境使用3D视图,容易卡顿,或造成浏览器的崩溃。
添加 3D 罗盘控制,显示倾斜和旋转按钮。
//3D控制罗盘AMap.plugin(['AMap.ControlBar',], function () {// 添加 3D 罗盘控制map.addControl(new AMap.ControlBar({position: {right: '20px',top: '20px'},showControlButton: true, // 是否显示倾斜、旋转按钮。默认为 true}));});
var loca = new Loca.Container({map,});var labelsLayer = (window.labelsLayer = new Loca.LabelsLayer({zooms: [10, 20],}));var geo = new Loca.GeoJSONSource({url: 'data2.json',});labelsLayer.setSource(geo);
labelsLayer.setStyle({icon: {type: 'image',image: (index, feat) => {//console.log(feat.properties.level)return './images/icon' + feat.properties.types + '.png'},size: [48, 75],anchor: 'center',},text: {// 每项配置都可使用回调函数来动态配置content: (index, feat) => {return feat.properties.name;},style: {fontSize: 12,fontWeight: 'normal',fillColor: '#5CDE8E',strokeColor: '#000',strokeWidth: 2,},direction: 'bottom',},extData: (index, feat) => {return feat.properties;},});loca.add(labelsLayer);
在labelsLayer的icon配置项中,对image新增回调函数,读取geojson中对应的项目类型,进行自动加载图标。
image: (index, feat) => {//console.log(feat.properties.level)return './images/icon' + feat.properties.types + '.png'},
labelsLayer.on('complete', () => {var normalMarker = new AMap.Marker({offset: [70, -15],});var labelMarkers = labelsLayer.getLabelsLayer().getAllOverlays();for (let marker of labelMarkers) {marker.on('mouseover', (e) => {var position = e.data.data && e.data.data.position;if (position) {normalMarker.setContent('地址:' + marker.getExtData().name + '',);normalMarker.setPosition(position);map.add(normalMarker);}});marker.on('mouseout', () => {map.remove(normalMarker);});}});
在鼠标移动到对应的数据层时,会出现信息提示。
normalMarker.setContent('地址:' + marker.getExtData().name + '', );
@漏刻有时
上一篇:八、STM32串口通信