Dark19,
<script>
var centroids = [
{
object: "A",
point: [50.4404, 30.5582]
},
{
object: "B",
point: [49.3905, 27.0426]
},
{
object: "C",
point: [48.4931, 32.2721]
},
{
object: "D",
point: [49.5623, 34.5573]
}
];
var points = [
{
point: [50.2153, 29.5036]
},
{
point: [50.3561, 32.1842]
},
{
point: [48.5515, 29.5915]
},
{
point: [47.6686, 32.4040]
},
{
point: [48.6972, 35.7438]
},
{
point: [47.1016, 35.2604]
}
];
var i =0;
var j = 0;
var k = 0, pointsDistance = [];
$('#map').click(function(e) {
for(i;i<points.length;i++){
pointsDistance[i] = {length : 0}
for(j;j<centroids.length;j++){
(function(a, b) {
ymaps.route([points[a]['point'], centroids[b]['point']]).then(function (router) {
var distance = Math.round(router.getLength() / 1000);
pointsDistance[a][centroids[b]["object"]] = distance
pointsDistance[a]["length"]++;
if(pointsDistance[a]["length"] == centroids.length) k++;
if (k == points.length) {console.log(pointsDistance)} //пора вычислять
});
})(i,j)
}
j=0;
}
});
</script>