微信小程序用uni-app开发,使用的高德的key,地图上marker标点过多页面卡顿,怎么解决
3条回答 默认 最新
- technologist_30 2021-05-17 20:56关注
复制代码 <template> <div> <div id="container" class="map"></div> </div> </template> <script> import axios from "axios"; export default { name: "qqMap", data() { return { map: {}, }; }, mounted() { this.setMap(points); }, methods: { setMap(data) { var map = new AMap.Map("container", { zoom: 11, center: [116.397428, 39.90923], zoomEnable: true, //是否可滚轮缩放 dragEnable: true, //是否可拖拽 resizeEnable: true, //是否监控地图容器尺寸变化 keyboardEnable: false, //键盘控制'↑' '→' '↓' '←' doubleClickZoom: false, //地图是否可通过双击鼠标放大地图 }); /*根据健康状态展示不同的图片*/ var style = [ { //健康green01 url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3366321909,1868160535&fm=26&gp=0.jpg", anchor: new AMap.Pixel(0, 0), size: new AMap.Size(30, 30), }, { //亚健康orange01 url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3366321909,1868160535&fm=26&gp=0.jpg", anchor: new AMap.Pixel(0, 0), size: new AMap.Size(30, 30), }, { //疾病red01 url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3366321909,1868160535&fm=26&gp=0.jpg", anchor: new AMap.Pixel(0, 0), size: new AMap.Size(30, 30), }, { //正在救助nowHelper url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3366321909,1868160535&fm=26&gp=0.jpg", anchor: new AMap.Pixel(0, 0), size: new AMap.Size(30, 30), }, { //未知状态blue01 url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3366321909,1868160535&fm=26&gp=0.jpg", anchor: new AMap.Pixel(0, 0), size: new AMap.Size(30, 30), }, ]; var locationData = []; //存放经纬度的数组 var status = ""; //下表对应的样式 for (var i = 0; i < data.length; i++) { var str2 = data[i].lnglat; // str2 = str2.split(","); //把经纬度转让数组 /*判断健康状态*/ if (data[i].district == "昌平区") { //健康 status = 0; //根据下标来相对应样式 例如:健康对应style数组中的第0个样式 } else if (data[i].district == "海淀区") { //亚健康 status = 1; } else if (data[i].district == "朝阳区") { //疾病 status = 2; } else if (data[i].district == "西城区") { //正在救助nowHelper status = 3; } else { //未知状态 status = 4; } /*{lnglat: Array(2), style: 2} 所需要的数据格式 */ locationData.push({ lnglat: str2, style: status, //对应的status相对应的样式style }); } console.log(locationData) /* 大量点所对应的方法*/ var mass = new AMap.MassMarks(locationData, { opacity: 0.8, zIndex: 111, cursor: "pointer", style: style, }); var marker = new AMap.Marker({ content: " ", map: map }); mass.on("mouseover", function (e) { marker.setPosition(e.data.lnglat); //用户相对应的经纬度 marker.setLabel({ content: e.data.name }); //用户相对应的名字 }); mass.setMap(map); } } }; </script> <style scoped> .map { width: 100%; height: 900px; } </style>
换成你自己的数据
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 请问这张multisim图的原理是什么,这是一个交通灯,是课程要求,明天要进行解析,但是我们组没一个人会,所以急要,今天要
- ¥15 ansible tower 卡住
- ¥15 等间距平面螺旋天线方程式
- ¥15 通过链接访问,显示514或不是私密连接
- ¥100 系统自动弹窗,键盘一接上就会
- ¥50 股票交易系统设计(sql语言)
- ¥15 调制识别中这几个数据集的文献分别是什么?
- ¥15 请大家看看报错原因,为啥会这样
- ¥30 Cocos转UWP应用,支付调起后闪退
- ¥15 STC32G12K128芯片可以接DS1302时钟模块吗