1 回答
TA贡献1886条经验 获得超2个赞
您不必扩展 CircleMarker 类来添加更多选项。您可以按默认方式执行此操作:
var myMarker = L.circleMarker([point.lat, point.lng], {
title: 'unselected',
radius: 20,
first_market: loop_index == 0,
last_market: loop_index == points.length-1,
point_id: point.id,
prior_point_id: priorPoint ? priorPoint.id : null,
});
polylinePoints[polylinePoints.length]=如果没有必要也不要使用。采用polylinePoints.push(
你想用折线上的数据做什么?为什么不将整个点数组添加到折线?
var polyline = new L.Polyline(polylinePoints, {
customData:{
points: points
}
});
否则,您可以创建一个点 id 数组:
let polylinePoints= [] // I get all info about all Polylines
let loop_index = 0;
let pointIds = [];
points.forEach(point => {
pointIds.push(point.id);
//...
var polyline = new L.Polyline(polylinePoints, {
customData:{
points: pointIds
}
});
或者(我建议)将标记添加到折线:
let markersForPoly = [];
points.forEach(point => {
//... Loop ...
myMarker.addTo(mymap);
markersForPoly .push(myMarker);
});
//.. Code
var polyline = new L.Polyline(polylinePoints, {
customData:{
points: markersForPoly
}
});
您可以在点击侦听器中获得积分:
polyline.on('click', function (event) {
var layer = event.target;
var points = layer.options.customData.points;
console.log(points);
});
示例 https://jsfiddle.net/falkedesign/61sjx3bv/
添加回答
举报