首页 > 其他分享 >vue中引入高德地图Loca数据可视化

vue中引入高德地图Loca数据可视化

时间:2022-11-03 15:01:04浏览次数:70  
标签:loca price vue AMap 2.0 true 高德 Loca


 

目录

引言:

关键词:

正文:

一、如何安装或者引入:

二、如何引入:

三、如何使用:

四、完整代码:

五、效果图

 参考:


引言:

vue中引入高德地图​实例的,详情可以去参考,由于需求增加,地图要做的更加美观、数据更加符合真实的空间数据呈现,依旧选择高德地图的API,这里我们选择引入高德地图 在vue中加载 ​​数据可视化​

关键词:

        vue、高德地图、LOCA、数据可视化

正文:

        Loca 数据可视化 API 2.0(以下简称为LOCA API 2.0)是一个基于高德地图JS API 2.0的高性能地图数据可视化库。其中Loca 2.x版本的要比1.3版本的相比,性能提升了和渲染效果更好,这是因为它们不同的架构模式和渲染管线;而且,2.0版本还引入了自定义镜头动画、图层动效、光照和材质等能力。此处注意一下你的版本兼容性!

vue中引入高德地图Loca数据可视化_高德地图

编辑

一、如何安装或者引入:

方式一:

        通过npm引入:

npm i @amap/amap-jsapi-loader --save


方式二:

        通过标签CDN引入:

<script src="https://webapi.amap.com/maps?v=2.0&key=您申请的key值"></script>
<script src="https://webapi.amap.com/loca?v=2.0.0&key=您申请的key值"></script>


二、如何引入:

通过npm安装的依赖引入,如下:

import AMapLoader from '@amap/amap-jsapi-loader';


三、如何使用:

注意版本号要选择 2.0!

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
});

//....其他配置代码,参考下文全量代码

})


四、完整代码:

<template>
<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>


五、效果图

vue中引入高德地图Loca数据可视化_加载_02


 参考:

1.​​、参考手册-LOCA 数据可视化 API 2.0 | 高德地图API​

2.​​、某片区房价信息-标牌点-示例详情-Loca API 2.0 | 高德地图API​


标签:loca,price,vue,AMap,2.0,true,高德,Loca
From: https://blog.51cto.com/u_14562672/5819286

相关文章

  • 关于Vue-穿梭框
    选择一个或以上的选项后,点击对应的方向键,可以把选中的选项移动到另一栏。其中,左边一栏为source,右边一栏为target,API的设计也反映了这两个概念。<T......
  • 并发编程之ThreadLocal
    并发编程之ThreadLocal前言当多线程访问共享可变数据时,涉及到线程间同步的问题,并不是所有时候,都要用到共享数据,所以就需要线程封闭出场了。数据都被封闭在各自的线程之......
  • 导航栏下拉列表/vue/scss/html
    效果   scss样式 html 源码<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=......
  • WebSocket C#服务器端+VUE客户端
    WebSocketC#服务器端先定义一个基类注:用于和WinSocket融合。当然不用也是可以的clsSocketusingSystem;usingSystem.Collections.Generic;usingSystem.Text;na......
  • vue3新特性的使用
    1、Suspense组件:等待异步组件时渲染一些额外内容,让应用有更好的用户体验例:<template><divclass="app"><h3>我是App组件</h3><......
  • 高德地图搜索结果如何导出成excel里?
    前段时间,根据朋友的要求,开发了地图里的商家采集工具。地图商家如何导出?电话如何导出EXCEL?现在很多做销售工作的思路都开阔了,从地图上直接找商家推销。但是普遍反映一个......
  • vue常见面试题
    vue路由跳转有几种方式vue中router和routr的区别vue路由有那两种模式,这两种模式的区别vue中scoped的原理防抖节流的理解vuex的5个组成部分vue中如何生命全局变量计......
  • 微信小程序watch监听, 类似vue的watch
    Vue.js里有watch监听机制,很适合“一处改变,多处影响”的场景,在开发小程序的过程中,自然也会遇到这样的场景,下面介绍如何在小程序中实现watch监听不好用你来打我!一.新建w......
  • 学习vue3(五)(插槽slot,Teleport传送组件,keep-alive缓存组件,依赖注入Provide / Inject)
    插槽slot插槽就是子组件中的提供给父组件使用的一个占位符,用<slot></slot>表示,父组件可以在这个占位符中填充任何模板代码,如HTML、组件等,填充的内容会替换子组件的<slot......
  • Vue 警告 Write operation failed: computed value is readonly
    警告信息:浏览器控制台警告:Writeoperationfailed:computedvalueisreadonly使用环境:Vue3.2.41Chromex64v103.0.5060.66报错情景:利用Vue的响应式修改某个值时......