代码
var map = new BMap.Map('map');
map.centerAndZoom(new BMap.Point(116.416, 39.9087), 18);
map.enableScrollWheelZoom();
var polylines = DONGJIAOMINXIANG_POINTS.map(function (c) {
return new BMap.Point(c[0], c[1]);
});
var polyline = new BMap.Polyline(polylines, {
strokeColor: '#1890ff',
strokeWeight: 4,
strokeOpacity: 0.9,
});
map.addOverlay(polyline);
map.setViewport([polyline]);
var isDashed = false;
document.getElementById('colorInput').addEventListener('input', function () {
polyline.setStrokeColor(this.value);
});
document.getElementById('weightInput').addEventListener('change', function () {
var w = parseInt(this.value);
if (w > 0) polyline.setStrokeWeight(w);
});
function toggleDash() {
isDashed = !isDashed;
polyline.setStrokeStyle(isDashed ? 'dashed' : 'solid');
}
通过 BMap.Polyline 绘制折线
预览