

vue中引入高德地图Loca数据可视化
source link: https://blog.51cto.com/u_14562672/5819286
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

目录
一、如何安装或者引入:
二、如何引入:
三、如何使用:
四、完整代码:
五、效果图
vue中引入高德地图实例的,详情可以去参考,由于需求增加,地图要做的更加美观、数据更加符合真实的空间数据呈现,依旧选择高德地图的API,这里我们选择引入高德地图 在vue中加载 数据可视化
vue、高德地图、LOCA、数据可视化
Loca 数据可视化 API 2.0(以下简称为LOCA API 2.0)是一个基于高德地图JS API 2.0的高性能地图数据可视化库。其中Loca 2.x版本的要比1.3版本的相比,性能提升了和渲染效果更好,这是因为它们不同的架构模式和渲染管线;而且,2.0版本还引入了自定义镜头动画、图层动效、光照和材质等能力。此处注意一下你的版本兼容性!

一、如何安装或者引入:
通过npm引入:
通过标签CDN引入:
<script src="https://webapi.amap.com/loca?v=2.0.0&key=您申请的key值"></script>
二、如何引入:
通过npm安装的依赖引入,如下:
三、如何使用:
注意版本号要选择 2.0!
"key": "ec5517c7d9a73dae44xxxxxxxxxxx", //申请好的Web端开发者Key,首次调用load时必填
"version": "2.0", //指定要加载的JSAPI的版本,缺省时默认为1.4.15
"plugins": ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
"Loca":{ //是否加载 Loca,缺省不加载
"version": '2.0.0' //Loca 版本,缺省1.3.2
}
}).then((AMap)=>{
this.map = new AMap.Map('container', {
zoom: 15.82,
center: [81.214768,43.836157],
pitch: 80,
rotation: 205,
showLabel: true, //不显示地名
showBuildingBlock: true, //显示建筑物
viewMode: '3D', //查看视野
});
this.loca = new Loca.Container({
map: this.map
});
//....其他配置代码,参考下文全量代码
})
四、完整代码:
<div>
<div id="container" style="width:100%;height:90vh" />
</div>
</template>
<script>
import AMapLoader from '@amap/amap-jsapi-loader';
export default {
name: "home",
data() {
return {
mapStyle: "amap://styles/normal", //地图背景模式
loca: null,
map: null,
featuresDataTest: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [81.218792, 43.841619],
},
properties: {
name: '一号灌溉区',
price: 65000,
count: 92
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [81.20927,43.836963],
},
properties: {
name: '2号灌溉区',
price: 65000,
count: 52
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [81.20927,43.836963],
},
properties: {
name: '3号灌溉区',
price: 49000,
count: 53,
},
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [81.190621,43.838342],
},
properties: {
name: '4号灌溉区',
price: 62000,
count: 639,
},
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [81.203593,43.83431],
},
properties: {
name: '5号灌溉区',
price: 48000,
count: 651,
},
},
]
}
},
methods: {
//获取当前时间看是白天还是晚上
getCurrentTime() {
let currentDate = new Date(),
hours = currentDate.getHours();
if (hours >= 19) {
this.mapStyle = "amap://styles/darkblue";
} else {
this.mapStyle = "amap://styles/normal";
}
},
//初始化地图
initMap(){
AMapLoader.load({
"key": "ec5517c7d9a73dae44xxxxxxxxxxx", //申请好的Web端开发者Key,首次调用load时必填
"version": "2.0", //指定要加载的JSAPI的版本,缺省时默认为1.4.15
"plugins": ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
"Loca":{ //是否加载 Loca,缺省不加载
"version": '2.0.0' //Loca 版本,缺省1.3.2
}
}).then((AMap)=>{
this.map = new AMap.Map('container', {
zoom: 15.82,
center: [81.214768,43.836157],
pitch: 80,
rotation: 205,
showLabel: true, //不显示地名
showBuildingBlock: true, //显示建筑物
viewMode: '3D', //查看视野
});
this.loca = new Loca.Container({
map: this.map
});
var geo = new Loca.GeoJSONSource({
data: {
"type": "FeatureCollection",
"features": this.featuresDataTest
}
});
// 文字主体图层
var zMarker = new Loca.ZMarkerLayer({
loca: this.loca,
zIndex: 120,
depth: false
});
zMarker.setSource(geo);
zMarker.setStyle({
content: (i, feat) => {
var props = feat.properties;
var leftColor = props.price < 60000 ? 'rgba(0, 28, 52, 0.6)' : 'rgba(33,33,33,0.6)';
var rightColor = props.price < 60000 ? '#038684' : 'rgba(172, 137, 51, 0.3)';
var borderColor = props.price < 60000 ? '#038684' : 'rgba(172, 137, 51, 1)';
return (
'<div style="width: 490px; height: 228px; padding: 0 0;">' +
'<p style="display: block; height:80px; line-height:80px;font-size:40px;background-image: linear-gradient(to right, '
+ leftColor + ',' + leftColor + ',' + rightColor + ',rgba(0,0,0,0.4)); border:4px solid '
+ borderColor + '; color:#fff; border-radius: 15px; text-align:center; margin:0; padding:5px;">' +
props['name'] +
': ' +
(props['price'] / 10000) + `m<sup>3</sup>` +
'</p><span style="width: 130px; height: 130px; margin: 0 auto; display: block; background: url(https://a.amap.com/Loca/static/loca-v2/demos/images/prism_'
+ (props['price'] < 60000 ? 'blue' : 'yellow') + '.png);"></span></div>'
);
},
unit: 'meter',
rotation: 0,
alwaysFront: true,
size: [490/2, 222/2],
altitude: 0
});
// 浮动三角
var triangleZMarker = new Loca.ZMarkerLayer({
loca: this.loca,
zIndex: 119,
depth: false
});
triangleZMarker.setSource(geo);
triangleZMarker.setStyle({
content: (i, feat) => {
return (
'<div style="width: 120px; height: 120px; background: url(https://a.amap.com/Loca/static/loca-v2/demos/images/triangle_'
+ (feat.properties.price < 60000 ? 'blue' : 'yellow')
+ '.png);"></div>'
);
},
unit: 'meter',
rotation: 0,
alwaysFront: true,
size: [60, 60],
altitude: 15
});
triangleZMarker.addAnimate({
key: 'altitude',
value: [0, 1],
random: true,
transform: 1000,
delay: 2000,
yoyo: true,
repeat: 999999
});
// 呼吸点 蓝色
var scatterBlue = new Loca.ScatterLayer({
loca: this.loca,
zIndex: 110,
opacity: 1,
visible: true,
zooms: [2, 26],
depth: false
});
scatterBlue.setSource(geo);
scatterBlue.setStyle({
unit: 'meter',
size: function (i, feat) {
return feat.properties.price < 60000 ? [90, 90] : [0, 0];
},
texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/scan_blue.png',
altitude: 20,
duration: 2000,
animate: true
});
// 呼吸点 金色
var scatterYellow = new Loca.ScatterLayer({
loca: this.loca,
zIndex: 110,
opacity: 1,
visible: true,
zooms: [2, 26],
depth: false
});
scatterYellow.setSource(geo);
scatterYellow.setStyle({
unit: 'meter',
size: function (i, feat) {
return feat.properties.price > 60000 ? [90, 90] : [0, 0];
},
texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/scan_yellow.png',
altitude: 20,
duration: 2000,
animate: true
});
// 启动帧
this.loca.animate.start();
})
},
},
mounted(){
if(!this.map){
this.initMap();
}
}
}
</script>
五、效果图

Recommend
-
23
-
62
1. 导读 高德既有上半身(导航服务、交通服务、步导服务、渲染服务、离线包等),为亿级用户提供基础的地图展示、搜索、导航、路况服务;又有下半身(数据采集、制作),源源不断地采集最新的数据,为用户提供最新最准的数据。...
-
5
高德地图 API Loca 动画的说明我们在使用 Loca 制作地图动画时,里面有几个对应的动画效果,有center: 平移pitch: 视角zoom: 缩放rotation: 旋转
-
42
实用工具|零代码实现高德地图 POI 数据下载上海市新能源汽车公共数据采集与监测研究中心 数据分析师
-
8
图像检索在高德地图POI数据生产中的应用发布于 11 分钟前简介: 高德通过自有海量的图像源,来保证现实世界的每一个新增的POI及时制作成数据。在较短时间间隔内(小...
-
6
Vue 高德地图最佳实践 淮城一只猫 • 2021年06月28日 • 奇淫技巧 • 阅读量 59 次 • 评论量 0 个 ...
-
9
B端设计师必看,数据可视化地图制作指南 Color可乐 2022-05-26 0 评论...
-
2
vue+element中引入百度地图_尔嵘的技术博客_51CTO博客2.然后在index.html文件中直接引用:<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=3.0&ak=密钥"></script>
-
8
[数据分析与可视化] Python绘制数据地图1-GeoPandas入门指北 ...
-
8
[数据分析与可视化] Python绘制数据地图3-GeoPandas使用要点 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK