动态引入图片require()和import()
一、require// html
// xxx.js
let imgList = [
require('../images/a.png'),
require('../images/b.jpg')
]
let imgName = 'a';
let imgAllName = 'a.png';
// example 1
let imgUrl = require('../images/a.png'); // 纯字符串
// example 2
let imgUrl = require('../images/' + imgAllName); // 目录 + 文件全名
// example 3
let imgUrl = require('../images/' + imgName + '.png'); // 目录 + 文件名 + 后缀
二、import
1.先引入
import imgUrl from "../assets/test.png"
2.在 return 中输出 imgUrl
3.
百度地图自定义图片点标记和文本内容:
import myimg from "../assets/test.png"
var lat = data.value
var map = new BMapGL.Map("containerMap"); // 创建Map实例
map.centerAndZoom(new BMapGL.Point(135.1213, 24.2563), 11); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
var myIcon = new BMapGL.Icon(myimg, new BMapGL.Size(80, 80), //视窗大小
);
var point = new BMapGL.Point(135.1025, 24.1254);
var marker = new BMapGL.Marker(point, {
icon: myIcon
});
var content = "";
content = content + "" + 客户 + " ";
content = content + "" + 693 + " ";
content += "
";
var optsion = {
point: point,
offset: new BMapGL.Size(-40, -60),//偏移量
enableMassClear: true
}
var label = new window.BMapGL.Label(content, optsion)
label.setStyle({ //文本框样式
width: '80px',
lineHeight: '15px',
textAlign: 'center',
color: '#ff0000',
fontSize: '12px',
border: '0px',
})
marker.setLabel(label) // 放到这个点上
map.addOverlay(marker)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)